Skip to content

Commit 216fdb1

Browse files
authored
ci: auto-update floating major/minor tags on release (#29)
Users pinning `tox-dev/action-pre-commit-uv@v1`, as the README recommends, were running stale code. 🏷️ The `v1` tag on the remote points to `v1.0.0` while `v1.0.4` is the current release, because nothing re-points the floating tag once a new version ships. Issue #28 reported this drift. The chosen direction keeps the `v1` and `v1.0` floating tags so existing consumers stay unaffected, and instead automates their maintenance. A new `Update floating tags` workflow runs whenever a stable release is published, deriving `vX` and `vX.Y` from the released `vX.Y.Z` and re-pointing them through the GitHub REST API. ✨ Working through the API means no checkout and no persisted credentials, which keeps the workflow clean under the repo's `zizmor` audit; `contents: write` is scoped to the single job while the top level stays read-only. Prereleases are skipped, and a `workflow_dispatch` input allows pointing the tags at an explicit version on demand. To repair the current drift after merge, run the workflow once with `tag = v1.0.4`; this moves `v1` forward and creates the missing `v1.0`. A malformed `1.0.3` tag (missing the `v` prefix, off `main`) also exists and can be deleted separately, but is left untouched here. Closes #28.
1 parent 41a04ab commit 216fdb1

1 file changed

Lines changed: 43 additions & 0 deletions

File tree

.github/workflows/release.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Update floating tags
2+
3+
on:
4+
release:
5+
types: [published]
6+
workflow_dispatch:
7+
inputs:
8+
tag:
9+
description: Full version tag to point the floating tags at (e.g. v1.0.4)
10+
required: true
11+
12+
permissions:
13+
contents: read
14+
15+
jobs:
16+
update-floating-tags:
17+
runs-on: ubuntu-latest
18+
if: ${{ github.event_name == 'workflow_dispatch' || !github.event.release.prerelease }}
19+
permissions:
20+
contents: write
21+
steps:
22+
- name: Move major and minor tags to the released version
23+
env:
24+
GH_TOKEN: ${{ github.token }}
25+
REPO: ${{ github.repository }}
26+
TAG: ${{ github.event.release.tag_name || inputs.tag }}
27+
run: |
28+
set -euo pipefail
29+
if [[ ! "${TAG}" =~ ^v([0-9]+)\.([0-9]+)\.([0-9]+)$ ]]; then
30+
echo "::error::Unexpected tag format: ${TAG} (expected vMAJOR.MINOR.PATCH)" >&2
31+
exit 1
32+
fi
33+
major="v${BASH_REMATCH[1]}"
34+
minor="v${BASH_REMATCH[1]}.${BASH_REMATCH[2]}"
35+
sha="$(gh api "repos/${REPO}/commits/${TAG}" --jq '.sha')"
36+
for ref in "${major}" "${minor}"; do
37+
if gh api "repos/${REPO}/git/refs/tags/${ref}" >/dev/null 2>&1; then
38+
gh api -X PATCH "repos/${REPO}/git/refs/tags/${ref}" -f "sha=${sha}" -F force=true >/dev/null
39+
else
40+
gh api -X POST "repos/${REPO}/git/refs" -f "ref=refs/tags/${ref}" -f "sha=${sha}" >/dev/null
41+
fi
42+
echo "Pointed ${ref} -> ${TAG} (${sha})"
43+
done

0 commit comments

Comments
 (0)