diff --git a/.github/workflows/test-all.yaml b/.github/workflows/test-all.yaml index 7e4c343bd..ea4fe8728 100644 --- a/.github/workflows/test-all.yaml +++ b/.github/workflows/test-all.yaml @@ -17,6 +17,7 @@ jobs: "azure-cli", "common-utils", "conda", + "copilot-cli", "desktop-lite", "docker-outside-of-docker", "docker-in-docker", @@ -70,6 +71,7 @@ jobs: "azure-cli", "common-utils", "conda", + "copilot-cli", "desktop-lite", "docker-outside-of-docker", "docker-in-docker", diff --git a/.github/workflows/test-pr.yaml b/.github/workflows/test-pr.yaml index c5930d97e..645d38109 100644 --- a/.github/workflows/test-pr.yaml +++ b/.github/workflows/test-pr.yaml @@ -17,6 +17,7 @@ jobs: azure-cli: ./**/azure-cli/** common-utils: ./**/common-utils/** conda: ./**/conda/** + copilot-cli: ./**/copilot-cli/** desktop-lite: ./**/desktop-lite/** docker-outside-of-docker: ./**/docker-outside-of-docker/** docker-in-docker: ./**/docker-in-docker/** diff --git a/src/copilot-cli/NOTES.md b/src/copilot-cli/NOTES.md new file mode 100644 index 000000000..c5393ab5a --- /dev/null +++ b/src/copilot-cli/NOTES.md @@ -0,0 +1,7 @@ + + +## OS Support + +This Feature should work on recent versions of Debian/Ubuntu-based distributions. + +`bash` is required to execute the `install.sh` script. diff --git a/src/copilot-cli/README.md b/src/copilot-cli/README.md new file mode 100644 index 000000000..3b7fc3be5 --- /dev/null +++ b/src/copilot-cli/README.md @@ -0,0 +1,31 @@ + +# GitHub Copilot CLI (copilot-cli) + +Installs the GitHub Copilot CLI. Auto-detects latest version and installs needed dependencies. + +## Example Usage + +```json +"features": { + "ghcr.io/devcontainers/features/copilot-cli:1": {} +} +``` + +## Options + +| Options Id | Description | Type | Default Value | +|-----|-----|-----|-----| +| version | Select version of the GitHub Copilot CLI, if not latest. | string | latest | + + + +## OS Support + +This Feature should work on recent versions of Debian/Ubuntu-based distributions. + +`bash` is required to execute the `install.sh` script. + + +--- + +_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`._ \ No newline at end of file diff --git a/src/copilot-cli/devcontainer-feature.json b/src/copilot-cli/devcontainer-feature.json new file mode 100644 index 000000000..ab433e2ae --- /dev/null +++ b/src/copilot-cli/devcontainer-feature.json @@ -0,0 +1,33 @@ +{ + "id": "copilot-cli", + "version": "1.0.0", + "name": "GitHub Copilot CLI", + "documentationURL": "https://github.com/devcontainers/features/tree/main/src/copilot-cli", + "description": "Installs the GitHub Copilot CLI.", + "options": { + "version": { + "type": "string", + "proposals": [ + "latest", + "prerelease" + ], + "default": "latest", + "description": "Select version of the GitHub Copilot CLI, if not latest." + } + }, + "customizations": { + "vscode": { + "settings": { + "github.copilot.chat.codeGeneration.instructions": [ + { + "text": "This dev container includes the GitHub Copilot CLI (`copilot`), which is pre-installed and available on the `PATH`." + } + ] + } + } + }, + "installsAfter": [ + "ghcr.io/devcontainers/features/common-utils" + ] +} + diff --git a/src/copilot-cli/install.sh b/src/copilot-cli/install.sh new file mode 100755 index 000000000..7250fa642 --- /dev/null +++ b/src/copilot-cli/install.sh @@ -0,0 +1,82 @@ +#!/usr/bin/env bash +#------------------------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information. +#------------------------------------------------------------------------------------------------------------- +# +# Docs: https://github.com/devcontainers/features/blob/main/src/copilot-cli/README.md +# Maintainer: The VS Code and Codespaces Teams + +CLI_VERSION=${VERSION:-"latest"} + +set -e + +if [ "$(id -u)" -ne 0 ]; then + echo -e 'Script must be run as root. Use sudo, su, or add "USER root" to your Dockerfile before running this script.' + exit 1 +fi + +apt_get_update() { + if [ "$(find /var/lib/apt/lists/* | wc -l)" = "0" ]; then + echo "Running apt-get update..." + apt-get update -y + fi +} + +# Checks if packages are installed and installs them if not +check_packages() { + if ! dpkg -s "$@" > /dev/null 2>&1; then + apt_get_update + apt-get -y install --no-install-recommends "$@" + fi +} + +download_from_github() { + local release_url=$1 + echo "Downloading GitHub Copilot CLI from ${release_url}..." + + mkdir -p /tmp/copilotcli + pushd /tmp/copilotcli + wget --show-progress --progress=dot:giga ${release_url} + # curl -fL# -O ${release_url} + tar -xzf /tmp/copilotcli/${cli_filename} + mv copilot /usr/local/bin/copilot + popd + rm -rf /tmp/copilotcli +} + +install_using_github() { + check_packages wget tar ca-certificates git + echo "Finished setting up dependencies" + arch=$(dpkg --print-architecture) + if [ "${arch}" = "amd64" ]; then + arch="x64" + fi + if [ "${arch}" != "x64" ] && [ "${arch}" != "arm64" ]; then + echo "Unsupported architecture: ${arch}" >&2 + exit 1 + fi + cli_filename="copilot-linux-${arch}.tar.gz" + echo "Installing GitHub Copilot CLI for ${arch} architecture: ${cli_filename}" + + # Install latest + if [ "${CLI_VERSION}" = "latest" ]; then + download_from_github "https://github.com/github/copilot-cli/releases/latest/download/${cli_filename}" + elif [ "${CLI_VERSION}" = "prerelease" ]; then + prerelease_version="$(git ls-remote --tags https://github.com/github/copilot-cli | tail -1 | awk -F/ '{print $NF}')" + download_from_github "https://github.com/github/copilot-cli/releases/download/${prerelease_version}/${cli_filename}" + else + # Install specific version + # Add leading v to version if it doesn't start with v + if [[ ! "${CLI_VERSION}" =~ ^v[0-9] ]]; then + CLI_VERSION="v${CLI_VERSION}" + fi + download_from_github "https://github.com/github/copilot-cli/releases/download/${CLI_VERSION}/${cli_filename}" + fi +} + +# Install the GitHub Copilot CLI +echo "Downloading GitHub Copilot CLI..." + +install_using_github + diff --git a/test/copilot-cli/test.sh b/test/copilot-cli/test.sh new file mode 100644 index 000000000..d1d624cda --- /dev/null +++ b/test/copilot-cli/test.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env bash + +echo "Checking if GitHub Copilot is installed..." +which copilot +copilot -v \ No newline at end of file