-
Notifications
You must be signed in to change notification settings - Fork 1
44 lines (37 loc) · 1.46 KB
/
release.yml
File metadata and controls
44 lines (37 loc) · 1.46 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
name: Release
on:
release:
types: [published]
jobs:
tag-aliases:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Move major and minor version tags
if: ${{ !github.event.release.prerelease }}
env:
GH_TOKEN: ${{ github.token }}
run: |
VERSION="${{ github.event.release.tag_name }}"
# Only move tags if this is the latest release for the repo
LATEST=$(gh release view --repo "${{ github.repository }}" --json tagName -q .tagName)
if [ "$LATEST" != "$VERSION" ]; then
echo "Skipping: $VERSION is not the latest release (latest is $LATEST)"
exit 0
fi
STRIPPED="$(echo "$VERSION" | sed 's/^v//')"
PARTS="$(echo "$STRIPPED" | tr '.' '\n' | wc -l)"
MAJOR="v$(echo "$STRIPPED" | cut -d. -f1)"
# Always move the major tag (e.g. v3)
echo "Updating major tag: $MAJOR"
git tag -f "$MAJOR"
git push origin "refs/tags/$MAJOR" --force
# Move the minor tag only if version has 3+ parts (e.g. v3.1.0 → v3.1)
if [ "$PARTS" -ge 3 ]; then
MINOR="v$(echo "$STRIPPED" | cut -d. -f1).$(echo "$STRIPPED" | cut -d. -f2)"
echo "Updating minor tag: $MINOR"
git tag -f "$MINOR"
git push origin "refs/tags/$MINOR" --force
fi