-
Notifications
You must be signed in to change notification settings - Fork 71
96 lines (79 loc) · 2.95 KB
/
release-gate.yml
File metadata and controls
96 lines (79 loc) · 2.95 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
name: Release Gate
on:
pull_request:
types: [closed]
branches: [main]
jobs:
release-gate:
name: Tag and update release branches
runs-on: ubuntu-latest
# Only run when a release/ branch is merged (not just closed)
if: |
github.event.pull_request.merged == true &&
startsWith(github.event.pull_request.head.ref, 'release/v')
permissions:
contents: write
steps:
- uses: actions/create-github-app-token@v1
id: app-token
with:
app-id: ${{ secrets.APP_ID }}
private-key: ${{ secrets.APP_PRIVATE_KEY }}
- uses: actions/checkout@v4
with:
# Full history required for version comparison against existing tags
# and for the fast-forward push to stable/beta.
fetch-depth: 0
token: ${{ steps.app-token.outputs.token }}
- name: Extract and validate version
id: version
env:
BRANCH_REF: ${{ github.event.pull_request.head.ref }}
run: |
BRANCH="$BRANCH_REF"
NEW_VERSION="${BRANCH#release/}"
echo "new=${NEW_VERSION}" >> $GITHUB_OUTPUT
# Determine if this is an RC
if echo "$NEW_VERSION" | grep -qE '\-rc[0-9]+$'; then
echo "is_rc=true" >> $GITHUB_OUTPUT
else
echo "is_rc=false" >> $GITHUB_OUTPUT
fi
- name: Validate version is strictly increasing
env:
NEW_VERSION: ${{ steps.version.outputs.new }}
run: |
# Get the latest tag; if none exist yet, skip the comparison
LATEST_TAG=$(git tag --list 'v*' --sort=-version:refname | head -n1)
if [ -z "$LATEST_TAG" ]; then
echo "No existing tags found — skipping version comparison"
exit 0
fi
LATEST_VERSION="${LATEST_TAG#v}"
python3 - <<EOF
import sys
from packaging.version import Version
def normalize(v):
# Convert vX.Y.Z-rcQ → X.Y.ZrcQ (PEP 440)
return v.replace("-rc", "rc")
new = Version(normalize("$NEW_VERSION"))
latest = Version(normalize("$LATEST_VERSION"))
print(f"Latest tag : {latest}")
print(f"New version: {new}")
if new <= latest:
print(f"\n❌ {new} is not strictly greater than current {latest}")
sys.exit(1)
print(f"\n✅ Version order is valid")
EOF
- name: Configure git
run: |
git config user.name "commit-boost-release-bot[bot]"
git config user.email "commit-boost-release-bot[bot]@users.noreply.github.com"
- name: Create and push tag
env:
VERSION: ${{ steps.version.outputs.new }}
run: |
git tag "$VERSION" HEAD
git push origin "$VERSION"
# Branch fast-forwarding happens in release.yml after all artifacts
# are successfully built. stable/beta are never touched if the build fails.