Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions .github/workflows/tag-action.yml
Original file line number Diff line number Diff line change
@@ -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"
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,17 @@ jobs:
with:
persist-credentials: false

- uses: planetscale/nix-devshell/.github/actions/setup-nix@<sha> # v0.1.0
- uses: planetscale/nix-devshell/.github/actions/setup-nix@<sha> # 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.<n>`, when a commit changes
`.github/actions/`. Commits elsewhere in the repository get no tag, because
consumers only ever reference the action.

### Inputs

Expand Down
Loading