From d1932dd12b3cffabd659ae03b710df2fb28423fb Mon Sep 17 00:00:00 2001 From: chris3ware <36608309+chris3ware@users.noreply.github.com> Date: Fri, 27 Nov 2026 13:54:52 +0000 Subject: [PATCH] update gh-actions-lock installation logic to check for pinned version --- .github/README.md | 3 ++- .github/gh-actions-lock.version | 2 +- scripts/actions-lock-verify.sh | 13 +++++++++---- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/.github/README.md b/.github/README.md index 2e2cf86..5c2e651 100644 --- a/.github/README.md +++ b/.github/README.md @@ -59,7 +59,8 @@ same name to a repository to override it. - Trunk CLI `>=1.25.0`. The [Trunk VS Code extension](https://marketplace.visualstudio.com/items?itemName=Trunk.io), recommended in `.vscode/extensions.json`, installs the CLI. - `gh` authenticated (`gh auth login`). The `actions-lock-verify` hook - installs the `github/gh-actions-lock` extension on first use. + installs the `github/gh-actions-lock` extension on first use, and + reinstalls it when the installed version differs from the pinned version. - A `.github/gh-actions-lock.version` file in the consuming repository containing the `gh-actions-lock` version to pin, for example `v0.4.0`. Without it the pre-commit hook fails whenever workflows or actions change. diff --git a/.github/gh-actions-lock.version b/.github/gh-actions-lock.version index fb7a04c..992ac75 100644 --- a/.github/gh-actions-lock.version +++ b/.github/gh-actions-lock.version @@ -1 +1 @@ -v0.4.0 +v0.5.1 diff --git a/scripts/actions-lock-verify.sh b/scripts/actions-lock-verify.sh index 7330712..6e2421b 100755 --- a/scripts/actions-lock-verify.sh +++ b/scripts/actions-lock-verify.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash # Check for any GitHub Action workflow changes. If none, exit early. -# Otherwise, install the GitHub CLI gh-actions-lock extension (if not already installed) +# Otherwise, install the GitHub CLI gh-actions-lock extension (if missing or not the pinned version) # and verify the actions lock file. set -euo pipefail @@ -10,9 +10,14 @@ if git diff --cached --quiet -- .github/workflows/ ':(glob)**/action.yml' ':(glo exit 0 fi -extensions=$(gh extension list) -if ! grep -q 'github/gh-actions-lock' <<<"${extensions}"; then - read -r version <.github/gh-actions-lock.version +read -r version <.github/gh-actions-lock.version +installed=$(gh extension list | awk -F'\t' '$2 == "github/gh-actions-lock" {print $3}') + +if [[ ${installed} != "${version}" ]]; then + if [[ -n ${installed} ]]; then + gh extension remove actions-lock + fi + # --upgrade would upgrade to latest and ignore --pin, so remove and reinstall instead gh extension install github/gh-actions-lock --pin "${version}" fi