Skip to content

Commit 1e68faf

Browse files
committed
Add feature for copilot-cli
1 parent 31f99a0 commit 1e68faf

File tree

5 files changed

+148
-0
lines changed

5 files changed

+148
-0
lines changed

src/copilot-cli/NOTES.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
3+
## OS Support
4+
5+
This Feature should work on recent versions of Debian/Ubuntu-based distributions.
6+
7+
`bash` is required to execute the `install.sh` script.

src/copilot-cli/README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
# GitHub Copilot CLI (copilot-cli)
3+
4+
Installs the GitHub Copilot CLI. Auto-detects latest version and installs needed dependencies.
5+
6+
## Example Usage
7+
8+
```json
9+
"features": {
10+
"ghcr.io/devcontainers/features/copilot-cli:1": {}
11+
}
12+
```
13+
14+
## Options
15+
16+
| Options Id | Description | Type | Default Value |
17+
|-----|-----|-----|-----|
18+
| version | Select version of the GitHub Copilot CLI, if not latest. | string | latest |
19+
20+
21+
22+
## OS Support
23+
24+
This Feature should work on recent versions of Debian/Ubuntu-based distributions.
25+
26+
`bash` is required to execute the `install.sh` script.
27+
28+
29+
---
30+
31+
_Note: This file was auto-generated from the [devcontainer-feature.json](https://github.com/devcontainers/features/blob/main/src/copilot-cli/devcontainer-feature.json). Add additional notes to a `NOTES.md`._
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"id": "copilot-cli",
3+
"version": "1.0.0",
4+
"name": "GitHub Copilot CLI",
5+
"documentationURL": "https://github.com/devcontainers/features/tree/main/src/copilot-cli",
6+
"description": "Installs the GitHub Copilot CLI.",
7+
"options": {
8+
"version": {
9+
"type": "string",
10+
"proposals": [
11+
"latest",
12+
"prerelease",
13+
"none"
14+
],
15+
"default": "latest",
16+
"description": "Select version of the GitHub Copilot CLI, if not latest."
17+
}
18+
},
19+
"customizations": {
20+
"vscode": {
21+
"settings": {
22+
"github.copilot.chat.codeGeneration.instructions": [
23+
{
24+
"text": "This dev container includes the GitHub Copilot CLI (`copilot`), which is pre-installed and available on the `PATH`."
25+
}
26+
]
27+
}
28+
}
29+
},
30+
"installsAfter": [
31+
"ghcr.io/devcontainers/features/common-utils"
32+
]
33+
}
34+

src/copilot-cli/install.sh

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#!/usr/bin/env bash
2+
#-------------------------------------------------------------------------------------------------------------
3+
# Copyright (c) Microsoft Corporation. All rights reserved.
4+
# Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information.
5+
#-------------------------------------------------------------------------------------------------------------
6+
#
7+
# Docs: https://github.com/devcontainers/features/blob/main/src/copilot-cli/README.md
8+
# Maintainer: The VS Code and Codespaces Teams
9+
10+
CLI_VERSION=${VERSION:-"latest"}
11+
12+
set -e
13+
14+
if [ "$(id -u)" -ne 0 ]; then
15+
echo -e 'Script must be run as root. Use sudo, su, or add "USER root" to your Dockerfile before running this script.'
16+
exit 1
17+
fi
18+
19+
apt_get_update() {
20+
if [ "$(find /var/lib/apt/lists/* | wc -l)" = "0" ]; then
21+
echo "Running apt-get update..."
22+
apt-get update -y
23+
fi
24+
}
25+
26+
# Checks if packages are installed and installs them if not
27+
check_packages() {
28+
if ! dpkg -s "$@" > /dev/null 2>&1; then
29+
apt_get_update
30+
apt-get -y install --no-install-recommends "$@"
31+
fi
32+
}
33+
34+
download_from_github() {
35+
local release_url=$1
36+
echo "Downloading GitHub Copilot CLI from ${release_url}..."
37+
38+
mkdir -p /tmp/copilotcli
39+
pushd /tmp/copilotcli
40+
wget --show-progress --progress=dot:giga ${release_url}
41+
# curl -fL# -O ${release_url}
42+
tar -xzf /tmp/copilotcli/${cli_filename}
43+
mv copilot /usr/local/bin/copilot
44+
popd
45+
rm -rf /tmp/copilotcli
46+
}
47+
48+
install_using_github() {
49+
check_packages wget tar ca-certificates git
50+
echo "Finished setting up dependencies"
51+
arch=$(dpkg --print-architecture)
52+
cli_filename="copilot-linux-${arch}.tar.gz"
53+
echo "Installing GitHub Copilot CLI for ${arch} architecture: ${cli_filename}"
54+
55+
# Install latest
56+
if [ "${CLI_VERSION}" = "latest" ]; then
57+
download_from_github "https://github.com/github/copilot-cli/releases/latest/download/${cli_filename}"
58+
elif [ "${CLI_VERSION}" = "prerelease" ]; then
59+
prerelease_version="$(git ls-remote --tags https://github.com/github/copilot-cli | tail -1 | awk -F/ '{print $NF}')"
60+
download_from_github "https://github.com/github/copilot-cli/releases/download/${prerelease_version}/${cli_filename}"
61+
else
62+
echo "Unsupported version value: ${CLI_VERSION}, falling back to latest" >&2
63+
download_from_github "https://github.com/github/copilot-cli/releases/latest/download/${cli_filename}"
64+
fi
65+
}
66+
67+
# Install the GitHub Copilot CLI
68+
echo "Downloading GitHub Copilot CLI..."
69+
70+
install_using_github
71+

test/copilot-cli/test.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env bash
2+
3+
echo "Checking if GitHub Copilot is installed..."
4+
which copilot
5+
copilot -v

0 commit comments

Comments
 (0)