Skip to content

Commit 041e079

Browse files
make draft release work with version bump PR (#45)
* make draft release work with version bump PR * update * add cleanup
1 parent 0eb24ab commit 041e079

1 file changed

Lines changed: 82 additions & 1 deletion

File tree

.github/workflows/draft-release.yml

Lines changed: 82 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
name: Draft Release
2+
run-name: "Draft Release (${{ inputs.bump }} bump)"
23

34
on:
45
workflow_dispatch:
@@ -14,6 +15,7 @@ on:
1415

1516
permissions:
1617
contents: write
18+
pull-requests: write
1719

1820
jobs:
1921
draft-release:
@@ -59,11 +61,90 @@ jobs:
5961
echo "rc=$RC_NUM" >> $GITHUB_OUTPUT
6062
echo "Next version: v${NEXT}-rc.${RC_NUM}"
6163
62-
- name: Create tag
64+
- name: Install Rust
65+
run: rustup toolchain install stable
66+
67+
- name: Bump version in Cargo.toml and open PR
68+
id: pr
69+
env:
70+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6371
run: |
72+
NEXT="${{ steps.version.outputs.next }}"
73+
RC="${{ steps.version.outputs.rc }}"
74+
FULL_VERSION="${NEXT}-rc.${RC}"
75+
BRANCH="release/bump-${FULL_VERSION}"
76+
77+
git config user.name "github-actions[bot]"
78+
git config user.email "github-actions[bot]@users.noreply.github.com"
79+
80+
# Clean up any leftover remote branch from a previous run
81+
git push origin --delete "$BRANCH" 2>/dev/null || true
82+
83+
git checkout -b "$BRANCH"
84+
85+
# Replace the version line in the workspace Cargo.toml
86+
sed -i "s/^version = \".*\"/version = \"${FULL_VERSION}\"/" Cargo.toml
87+
cargo update -p skardi --precise "${FULL_VERSION}"
88+
89+
git add Cargo.toml Cargo.lock
90+
git commit -m "chore: bump version to ${FULL_VERSION}"
91+
git push --force origin "$BRANCH"
92+
93+
PR_URL=$(gh pr create \
94+
--title "chore: bump version to ${FULL_VERSION}" \
95+
--body "Automated version bump to \`${FULL_VERSION}\` ahead of the \`v${FULL_VERSION}\` release." \
96+
--base main \
97+
--head "$BRANCH")
98+
99+
echo "pr_url=$PR_URL" >> $GITHUB_OUTPUT
100+
echo "branch=$BRANCH" >> $GITHUB_OUTPUT
101+
echo "PR created: $PR_URL"
102+
103+
- name: Wait for PR to be merged (1 hour timeout)
104+
id: wait
105+
env:
106+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
107+
run: |
108+
PR_URL="${{ steps.pr.outputs.pr_url }}"
109+
TIMEOUT=3600 # 1 hour in seconds
110+
INTERVAL=30 # poll every 30 seconds
111+
ELAPSED=0
112+
113+
echo "Waiting for PR to be merged: $PR_URL"
114+
115+
while [ $ELAPSED -lt $TIMEOUT ]; do
116+
STATE=$(gh pr view "$PR_URL" --json state,mergeStateStatus --jq '.state')
117+
118+
if [ "$STATE" = "MERGED" ]; then
119+
echo "PR merged successfully."
120+
break
121+
elif [ "$STATE" = "CLOSED" ]; then
122+
echo "Error: PR was closed without merging."
123+
exit 1
124+
fi
125+
126+
echo "PR state: $STATE — waiting ${INTERVAL}s (elapsed: ${ELAPSED}s / ${TIMEOUT}s)"
127+
sleep $INTERVAL
128+
ELAPSED=$((ELAPSED + INTERVAL))
129+
done
130+
131+
if [ $ELAPSED -ge $TIMEOUT ]; then
132+
echo "Error: Timed out after ${TIMEOUT}s waiting for PR to be merged."
133+
exit 1
134+
fi
135+
136+
- name: Fetch merged main and create RC tag
137+
env:
138+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
139+
run: |
140+
git fetch origin main
141+
git checkout main
142+
git pull origin main
143+
64144
VERSION="v${{ steps.version.outputs.next }}-rc.${{ steps.version.outputs.rc }}"
65145
git tag "$VERSION"
66146
git push origin "$VERSION"
147+
echo "Tagged: $VERSION"
67148
68149
- name: Create draft release
69150
env:

0 commit comments

Comments
 (0)