Repository navigation
70 lines (58 loc) · 2.09 KB
/
Copy pathrelease.yaml
File metadata and controls
70 lines (58 loc) · 2.09 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
66
67
68
69
70
name: release
on:
push:
tags:
- "v[0-9]+.[0-9]+.[0-9]+"
jobs:
update-tags:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@fbc6f3992d24b796d5a048ff273f7fcc4a7b6c09 # v5.1.0
with:
fetch-depth: 1 # only the tagged commit is needed
- name: Validate tag format
run: |
TAG="${GITHUB_REF_NAME}"
if [[ ! "$TAG" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "::error::Unexpected tag format: '$TAG'. Expected vMAJOR.MINOR.PATCH." >&2
exit 1
fi
- name: Update floating tags
run: |
TAG="${GITHUB_REF_NAME}"
MINOR="${TAG%.*}"
MAJOR="${MINOR%.*}"
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
for FLOATING in "$MAJOR" "$MINOR"; do
git tag -fa "$FLOATING" -m "Update $FLOATING -> $TAG"
git push origin "$FLOATING" --force
done
- name: Create GitHub Release
env:
GH_TOKEN: ${{ github.token }}
run: |
TAG="${GITHUB_REF_NAME}"
if gh release view "$TAG" &>/dev/null; then
echo "Release $TAG already exists, skipping creation"
exit 0
fi
# Determine whether this tag is the latest release across all versions.
# Fetch all release tags, sort by semver, and check if TAG comes out on top.
LATEST_TAG=$(gh release list --json tagName --jq '.[].tagName' \
| grep -E '^v[0-9]+\.[0-9]+\.[0-9]+$' \
| sort -V \
| tail -n1)
# Compare versions using sort -V: if TAG is greater than LATEST_TAG, mark as latest.
if [ -z "$LATEST_TAG" ] || [ "$(printf '%s\n' "$LATEST_TAG" "$TAG" | sort -V | tail -n1)" = "$TAG" ]; then
IS_LATEST=true
else
IS_LATEST=false
fi
gh release create "$TAG" \
--title "$TAG" \
--generate-notes \
--latest="$IS_LATEST"