aboutsummaryrefslogtreecommitdiff
path: root/src/github-cli
diff options
context:
space:
mode:
Diffstat (limited to 'src/github-cli')
-rw-r--r--src/github-cli/devcontainer-feature.json7
-rwxr-xr-xsrc/github-cli/install.sh73
2 files changed, 71 insertions, 9 deletions
diff --git a/src/github-cli/devcontainer-feature.json b/src/github-cli/devcontainer-feature.json
index fd69096..b3c736c 100644
--- a/src/github-cli/devcontainer-feature.json
+++ b/src/github-cli/devcontainer-feature.json
@@ -1,6 +1,6 @@
{
"id": "github-cli",
- "version": "1.0.2",
+ "version": "1.0.3",
"name": "GitHub CLI",
"documentationURL": "https://github.com/devcontainers/features/tree/main/src/github-cli",
"description": "Installs the GitHub CLI. Auto-detects latest version and installs needed dependencies.",
@@ -13,6 +13,11 @@
],
"default": "latest",
"description": "Select version of the GitHub CLI, if not latest."
+ },
+ "installDirectlyFromGitHubRelease": {
+ "type": "boolean",
+ "default": true
}
}
}
+
diff --git a/src/github-cli/install.sh b/src/github-cli/install.sh
index 689a816..70b48ec 100755
--- a/src/github-cli/install.sh
+++ b/src/github-cli/install.sh
@@ -8,6 +8,7 @@
# Maintainer: The VS Code and Codespaces Teams
CLI_VERSION=${VERSION:-"latest"}
+INSTALL_DIRECTLY_FROM_GITHUB_RELEASE=${INSTALLDIRECTLYFROMGITHUBRELEASE:-"true"}
GITHUB_CLI_ARCHIVE_GPG_KEY=C99B11DEB97541F0
GPG_KEY_SERVERS="keyserver hkp://keyserver.ubuntu.com:80
@@ -152,6 +153,57 @@ check_packages() {
fi
}
+find_version_from_git_tags() {
+ local variable_name=$1
+ local requested_version=${!variable_name}
+ if [ "${requested_version}" = "none" ]; then return; fi
+ local repository=$2
+ local prefix=${3:-"tags/v"}
+ local separator=${4:-"."}
+ local last_part_optional=${5:-"false"}
+ if [ "$(echo "${requested_version}" | grep -o "." | wc -l)" != "2" ]; then
+ local escaped_separator=${separator//./\\.}
+ local last_part
+ if [ "${last_part_optional}" = "true" ]; then
+ last_part="(${escaped_separator}[0-9]+)?"
+ else
+ last_part="${escaped_separator}[0-9]+"
+ fi
+ local regex="${prefix}\\K[0-9]+${escaped_separator}[0-9]+${last_part}$"
+ local version_list="$(git ls-remote --tags ${repository} | grep -oP "${regex}" | tr -d ' ' | tr "${separator}" "." | sort -rV)"
+ if [ "${requested_version}" = "latest" ] || [ "${requested_version}" = "current" ] || [ "${requested_version}" = "lts" ]; then
+ declare -g ${variable_name}="$(echo "${version_list}" | head -n 1)"
+ else
+ set +e
+ declare -g ${variable_name}="$(echo "${version_list}" | grep -E -m 1 "^${requested_version//./\\.}([\\.\\s]|$)")"
+ set -e
+ fi
+ fi
+ if [ -z "${!variable_name}" ] || ! echo "${version_list}" | grep "^${!variable_name//./\\.}$" > /dev/null 2>&1; then
+ echo -e "Invalid ${variable_name} value: ${requested_version}\nValid values:\n${version_list}" >&2
+ exit 1
+ fi
+ echo "${variable_name}=${!variable_name}"
+}
+
+
+# Fall back on direct download if no apt package exists
+# Fetches .deb file to be installed with dpkg
+install_deb_using_github() {
+ check_packages wget
+ arch=$(dpkg --print-architecture)
+
+ find_version_from_git_tags CLI_VERSION https://github.com/cli/cli
+ cli_filename="gh_${CLI_VERSION}_linux_${arch}.deb"
+
+ mkdir -p /tmp/ghcli
+ pushd /tmp/ghcli
+ wget https://github.com/cli/cli/releases/download/v${CLI_VERSION}/${cli_filename}
+ dpkg -i /tmp/ghcli/${cli_filename}
+ popd
+ rm -rf /tmp/ghcli
+}
+
export DEBIAN_FRONTEND=noninteractive
# Install curl, apt-transport-https, curl, gpg, or dirmngr, git if missing
@@ -171,11 +223,16 @@ fi
# Install the GitHub CLI
echo "Downloading github CLI..."
-# Import key safely (new method rather than deprecated apt-key approach) and install
-. /etc/os-release
-receive_gpg_keys GITHUB_CLI_ARCHIVE_GPG_KEY /usr/share/keyrings/githubcli-archive-keyring.gpg
-echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" > /etc/apt/sources.list.d/github-cli.list
-apt-get update
-apt-get -y install "gh${version_suffix}"
-rm -rf "/tmp/gh/gnupg"
-echo "Done!"
+
+if [ "${INSTALL_DIRECTLY_FROM_GITHUB_RELEASE}" = "true" ]; then
+ install_deb_using_github
+else
+ # Import key safely (new method rather than deprecated apt-key approach) and install
+ . /etc/os-release
+ receive_gpg_keys GITHUB_CLI_ARCHIVE_GPG_KEY /usr/share/keyrings/githubcli-archive-keyring.gpg
+ echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" > /etc/apt/sources.list.d/github-cli.list
+ apt-get update
+ apt-get -y install "gh${version_suffix}"
+ rm -rf "/tmp/gh/gnupg"
+ echo "Done!"
+fi \ No newline at end of file