diff --git a/src/github-cli/devcontainer-feature.json b/src/github-cli/devcontainer-feature.json index 9b7f51e89..ae531da55 100644 --- a/src/github-cli/devcontainer-feature.json +++ b/src/github-cli/devcontainer-feature.json @@ -21,7 +21,7 @@ "extensions": { "type": "string", "default": "", - "description": "Comma-separated list of GitHub CLI extensions to install (e.g. 'dlvhdr/gh-dash,github/gh-copilot')." + "description": "Comma-separated list of GitHub CLI extensions to install (e.g. 'dlvhdr/gh-dash,github/gh-copilot'). Append ':' to pin a version (e.g. 'github/gh-stack:v1.0.0')." } }, "customizations": { diff --git a/src/github-cli/scripts/install-extensions.sh b/src/github-cli/scripts/install-extensions.sh index 05285aa7b..26062c93b 100644 --- a/src/github-cli/scripts/install-extensions.sh +++ b/src/github-cli/scripts/install-extensions.sh @@ -19,18 +19,32 @@ trim() { install_extension() { local extension="$1" local extensions_root + local repo + local tag local repo_name + local install_args=() + local clone_args=() + + repo="${extension%%:*}" + if [ "${repo}" != "${extension}" ]; then + tag="${extension#*:}" + fi extensions_root="${XDG_DATA_HOME:-"${HOME}/.local/share"}/gh/extensions" - repo_name="${extension##*/}" + repo_name="${repo##*/}" + + if [ -n "${tag}" ]; then + install_args=(--pin "${tag}") + clone_args=(--branch "${tag}") + fi mkdir -p "${extensions_root}" if [ ! -d "${extensions_root}/${repo_name}" ]; then - if ! gh extension install "${extension}"; then + if ! gh extension install "${repo}" "${install_args[@]}"; then git \ -c credential.helper= \ -c credential.helper='!gh auth git-credential' \ - clone --depth 1 "https://github.com/${extension}.git" "${extensions_root}/${repo_name}" + clone --depth 1 "${clone_args[@]}" "https://github.com/${repo}.git" "${extensions_root}/${repo_name}" fi fi } diff --git a/test/github-cli/install_extensions.sh b/test/github-cli/install_extensions.sh index 1538ff3f2..38324ca9e 100644 --- a/test/github-cli/install_extensions.sh +++ b/test/github-cli/install_extensions.sh @@ -11,6 +11,8 @@ check "gh-extension-installed" gh extension list | grep -q 'dlvhdr/gh-dash' check "gh-extension-installed-2" gh extension list | grep -q 'github/gh-copilot' check "gh-extension-installed-3" gh extension list | grep -q 'github/gh-aw' check "gh-aw-runs" gh aw version +check "gh-extension-pinned-tag" grep -q 'tag: v0.88.8' "${XDG_DATA_HOME:-"${HOME}/.local/share"}/gh/extensions/gh-aw/manifest.yml" +check "gh-extension-pinned-flag" grep -q 'ispinned: true' "${XDG_DATA_HOME:-"${HOME}/.local/share"}/gh/extensions/gh-aw/manifest.yml" # Report result reportResults diff --git a/test/github-cli/scenarios.json b/test/github-cli/scenarios.json index c6dc2350e..1f49131fb 100644 --- a/test/github-cli/scenarios.json +++ b/test/github-cli/scenarios.json @@ -31,7 +31,7 @@ "features": { "github-cli": { "version": "latest", - "extensions": "dlvhdr/gh-dash,github/gh-copilot,github/gh-aw" + "extensions": "dlvhdr/gh-dash,github/gh-copilot,github/gh-aw:v0.88.8" } } }