Skip to content

Commit 241aae9

Browse files
feat: auto-move floating v2 tag on release (#31)
Co-authored-by: Shubhank <72601061+Sagsgit@users.noreply.github.com>
1 parent 2434ece commit 241aae9

1 file changed

Lines changed: 65 additions & 0 deletions

File tree

.github/workflows/release-tag.yml

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
name: Move Floating Version Tag
2+
3+
on:
4+
release:
5+
types: [published]
6+
push:
7+
branches: [master, main]
8+
9+
jobs:
10+
move-tag:
11+
runs-on: ubuntu-latest
12+
name: Move floating version tag
13+
permissions:
14+
contents: write
15+
steps:
16+
- name: Checkout
17+
uses: actions/checkout@v4
18+
with:
19+
fetch-depth: 0
20+
21+
- name: Move floating major tag
22+
run: |
23+
git config user.name "github-actions[bot]"
24+
git config user.email "github-actions[bot]@users.noreply.github.com"
25+
26+
if [ "${{ github.event_name }}" = "release" ]; then
27+
# Triggered by a release — move the tag for that release version
28+
VERSION="${{ github.event.release.tag_name }}"
29+
MAJOR=$(echo "$VERSION" | sed 's/^v//' | cut -d. -f1)
30+
FLOATING_TAG="v${MAJOR}"
31+
TARGET_SHA="${{ github.sha }}"
32+
33+
echo "Release: $VERSION"
34+
echo "Moving $FLOATING_TAG → $VERSION ($TARGET_SHA)"
35+
36+
git tag -d "$FLOATING_TAG" 2>/dev/null || true
37+
git push origin ":refs/tags/$FLOATING_TAG" 2>/dev/null || true
38+
git tag "$FLOATING_TAG" "$TARGET_SHA"
39+
git push origin "$FLOATING_TAG"
40+
41+
echo "✅ $FLOATING_TAG now points to $VERSION"
42+
43+
else
44+
# Triggered by a push to master — bootstrap any missing floating tags
45+
# Find the latest release tag and create vN if it doesn't exist yet
46+
LATEST_TAG=$(git tag --sort=-version:refname | grep -E '^[0-9]+\.[0-9]+\.[0-9]+$' | head -1)
47+
48+
if [ -z "$LATEST_TAG" ]; then
49+
echo "No release tags found, skipping"
50+
exit 0
51+
fi
52+
53+
MAJOR=$(echo "$LATEST_TAG" | cut -d. -f1)
54+
FLOATING_TAG="v${MAJOR}"
55+
56+
if git ls-remote --tags origin "$FLOATING_TAG" | grep -q "$FLOATING_TAG"; then
57+
echo "✅ $FLOATING_TAG already exists, nothing to do"
58+
else
59+
TAG_SHA=$(git rev-list -n 1 "$LATEST_TAG")
60+
echo "Bootstrapping $FLOATING_TAG → $LATEST_TAG ($TAG_SHA)"
61+
git tag "$FLOATING_TAG" "$TAG_SHA"
62+
git push origin "$FLOATING_TAG"
63+
echo "✅ $FLOATING_TAG created pointing at $LATEST_TAG"
64+
fi
65+
fi

0 commit comments

Comments
 (0)