From 7b1432bc66b274aa62bf063975eba97d005b7327 Mon Sep 17 00:00:00 2001 From: Matt Robenolt Date: Mon, 9 Nov 2026 15:53:44 -0800 Subject: [PATCH] Tag the action automatically when it changes Consumers pin the action by SHA with the version in a comment, and pinact verifies the two agree. Without a tag there is nothing to verify against, and neither pinact nor Renovate can move the pin. Cut the next v0.1. on every push to main that touches .github/actions/. Other commits get no tag, since consumers never reference anything else. --- .github/workflows/tag-action.yml | 50 ++++++++++++++++++++++++++++++++ README.md | 10 +++++-- 2 files changed, 57 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/tag-action.yml diff --git a/.github/workflows/tag-action.yml b/.github/workflows/tag-action.yml new file mode 100644 index 0000000..bc01252 --- /dev/null +++ b/.github/workflows/tag-action.yml @@ -0,0 +1,50 @@ +name: Tag the action + +on: + push: + branches: + - main + paths: + - .github/actions/** + +permissions: {} + +jobs: + tag: + runs-on: ubuntu-latest + timeout-minutes: 5 + permissions: + contents: write + steps: + # A tag is only useful to consumers, who pin the action by SHA with the + # version in a comment. Nothing else needs one, so this runs only when + # the action itself changes. + - name: Tag the next patch version + env: + GH_TOKEN: ${{ github.token }} + REPO: ${{ github.repository }} + SHA: ${{ github.sha }} + run: | + set -euo pipefail + + # A push that rewrites or re-runs the same commit must not stack + # tags on it. + if gh api "repos/$REPO/git/matching-refs/tags/v0.1." \ + --jq '.[].object.sha' | grep -qx "$SHA"; then + echo "$SHA is already tagged, nothing to do" + exit 0 + fi + + latest=$(gh api "repos/$REPO/git/matching-refs/tags/v0.1." \ + --jq '.[].ref | ltrimstr("refs/tags/")' | sort -V | tail -1) + if [[ -z "$latest" ]]; then + next=v0.1.0 + else + IFS=. read -r major minor patch <<< "${latest#v}" + next="v${major}.${minor}.$((patch + 1))" + fi + + echo "Tagging $next at $SHA" + gh api --method POST "repos/$REPO/git/refs" \ + --field ref="refs/tags/$next" \ + --field sha="$SHA" diff --git a/README.md b/README.md index 6ce71bc..dcab653 100644 --- a/README.md +++ b/README.md @@ -93,13 +93,17 @@ jobs: with: persist-credentials: false - - uses: planetscale/nix-devshell/.github/actions/setup-nix@ # v0.1.0 + - uses: planetscale/nix-devshell/.github/actions/setup-nix@ # v0.1.1 - run: nix develop .#dev --command just test ``` -Pin the action by SHA and keep the version in a comment. Renovate and pinact -update both. A job that uses the action needs no other Nix setup. +Pin the action by SHA and keep the version in a comment; pinact verifies that +the two agree. A job that uses the action needs no other Nix setup. + +Tags are cut automatically, as `v0.1.`, when a commit changes +`.github/actions/`. Commits elsewhere in the repository get no tag, because +consumers only ever reference the action. ### Inputs