-
Notifications
You must be signed in to change notification settings - Fork 11
129 lines (105 loc) · 3.85 KB
/
Copy pathpromote-release.yml
File metadata and controls
129 lines (105 loc) · 3.85 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
name: Promote Release
run-name: "Promote ${{ inputs.rc_tag }}"
on:
workflow_dispatch:
inputs:
rc_tag:
description: "RC tag to promote (e.g. v0.2.0-rc.1)"
required: true
type: string
permissions:
contents: write
pull-requests: write
jobs:
promote-release:
name: "Promote ${{ inputs.rc_tag }}"
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: main
fetch-depth: 0
- name: Validate and extract version
id: version
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
RC_TAG="${{ inputs.rc_tag }}"
if [[ ! "$RC_TAG" =~ ^v[0-9]+\.[0-9]+\.[0-9]+-rc\.[0-9]+$ ]]; then
echo "Error: Tag must be in format v0.0.0-rc.N"
exit 1
fi
# Verify the rc release exists
if ! gh release view "$RC_TAG" &>/dev/null; then
echo "Error: Release $RC_TAG not found"
exit 1
fi
# Strip the -rc.N suffix
OFFICIAL="${RC_TAG%-rc.*}"
echo "official=$OFFICIAL" >> $GITHUB_OUTPUT
echo "Promoting $RC_TAG -> $OFFICIAL"
- name: Install Rust
# Version comes from rust-toolchain.toml.
run: rustup toolchain install
- name: Bump version in Cargo.toml and open PR
id: pr
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
OFFICIAL="${{ steps.version.outputs.official }}"
VERSION="${OFFICIAL#v}"
BRANCH="release/bump-${OFFICIAL}"
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
# Clean up any leftover remote branch from a previous run
git push origin --delete "$BRANCH" 2>/dev/null || true
git checkout -b "$BRANCH"
# Replace the version line in the workspace Cargo.toml
sed -i "s/^version = \".*\"/version = \"${VERSION}\"/" Cargo.toml
cargo update -p skardi --precise "${VERSION}"
git add Cargo.toml Cargo.lock
git commit -m "chore: bump version to ${VERSION}"
git push --force origin "$BRANCH"
PR_URL=$(gh pr create \
--title "chore: bump version to ${VERSION}" \
--body "Automated version bump to \`${VERSION}\` promoting \`${{ inputs.rc_tag }}\` to \`${OFFICIAL}\`." \
--base main \
--head "$BRANCH")
echo "pr_url=$PR_URL" >> $GITHUB_OUTPUT
echo "PR created: $PR_URL"
- name: Wait for PR to be merged (1 hour timeout)
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
PR_URL="${{ steps.pr.outputs.pr_url }}"
TIMEOUT=3600
INTERVAL=30
ELAPSED=0
echo "Waiting for PR to be merged: $PR_URL"
while [ $ELAPSED -lt $TIMEOUT ]; do
STATE=$(gh pr view "$PR_URL" --json state --jq '.state')
if [ "$STATE" = "MERGED" ]; then
echo "PR merged successfully."
break
elif [ "$STATE" = "CLOSED" ]; then
echo "Error: PR was closed without merging."
exit 1
fi
echo "PR state: $STATE — waiting ${INTERVAL}s (elapsed: ${ELAPSED}s / ${TIMEOUT}s)"
sleep $INTERVAL
ELAPSED=$((ELAPSED + INTERVAL))
done
if [ $ELAPSED -ge $TIMEOUT ]; then
echo "Error: Timed out after ${TIMEOUT}s waiting for PR to be merged."
exit 1
fi
- name: Fetch merged main and create tag
run: |
git fetch origin main
git checkout main
git pull origin main
OFFICIAL="${{ steps.version.outputs.official }}"
git tag "$OFFICIAL"
git push origin "$OFFICIAL"
echo "Tagged: $OFFICIAL"