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