Skip to content

Commit cd8f008

Browse files
committed
feat: enhance release workflow to create version bump PR and enable auto-merge
1 parent 945da58 commit cd8f008

File tree

1 file changed

+102
-7
lines changed

1 file changed

+102
-7
lines changed

.github/workflows/release.yml

Lines changed: 102 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ jobs:
221221
needs: [preflight, test, lint, build]
222222
permissions:
223223
contents: write
224+
pull-requests: write
224225

225226
steps:
226227
- name: Checkout
@@ -268,10 +269,23 @@ jobs:
268269
echo "next=$NEXT" >> $GITHUB_OUTPUT
269270
echo "Bumping from $CURRENT to $NEXT"
270271
271-
- name: Update version files
272+
- name: Update version files and create PR
273+
id: version_pr
272274
working-directory: cli
275+
env:
276+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
273277
run: |
274278
VERSION="${{ steps.version.outputs.next }}"
279+
BRANCH="release/v${VERSION}"
280+
281+
# Delete branch if it already exists (from previous failed runs)
282+
git push origin --delete "$BRANCH" 2>/dev/null || true
283+
git branch -D "$BRANCH" 2>/dev/null || true
284+
285+
# Create and switch to release branch
286+
git config user.name "github-actions[bot]"
287+
git config user.email "github-actions[bot]@users.noreply.github.com"
288+
git checkout -b "$BRANCH"
275289
276290
# Update extension.yaml
277291
sed -i "s/^version: .*/version: $VERSION/" extension.yaml
@@ -306,15 +320,96 @@ jobs:
306320
} > CHANGELOG.new.md
307321
mv CHANGELOG.new.md CHANGELOG.md
308322
309-
# Commit version bump
323+
# Commit and push to branch
324+
git add extension.yaml CHANGELOG.md
325+
git commit -m "chore: bump version to $VERSION"
326+
git push origin "$BRANCH"
327+
328+
# Create PR
310329
cd ..
330+
PR_URL=$(gh pr create \
331+
--title "chore: Release v${VERSION}" \
332+
--body "Automated version bump to ${VERSION} for release." \
333+
--base main \
334+
--head "$BRANCH")
335+
336+
echo "pr_url=$PR_URL" >> $GITHUB_OUTPUT
337+
echo "branch=$BRANCH" >> $GITHUB_OUTPUT
338+
339+
# Extract PR number
340+
PR_NUMBER=$(echo "$PR_URL" | grep -oP '\d+$')
341+
echo "pr_number=$PR_NUMBER" >> $GITHUB_OUTPUT
342+
343+
- name: Enable auto-merge and wait for merge
344+
env:
345+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
346+
run: |
347+
PR_NUMBER="${{ steps.version_pr.outputs.pr_number }}"
348+
349+
echo "Enabling auto-merge for PR #${PR_NUMBER}..."
350+
gh pr merge "$PR_NUMBER" --auto --squash
351+
352+
echo "Waiting for PR to be merged..."
353+
354+
# Wait for PR to merge (with timeout)
355+
TIMEOUT=600 # 10 minutes
356+
ELAPSED=0
357+
INTERVAL=15
358+
359+
while [ $ELAPSED -lt $TIMEOUT ]; do
360+
# Check PR state and status checks
361+
PR_DATA=$(gh pr view "$PR_NUMBER" --json state,mergeable,statusCheckRollup)
362+
STATE=$(echo "$PR_DATA" | jq -r '.state')
363+
MERGEABLE=$(echo "$PR_DATA" | jq -r '.mergeable')
364+
365+
echo "PR state: $STATE, Mergeable: $MERGEABLE"
366+
367+
if [ "$STATE" = "MERGED" ]; then
368+
echo "PR merged successfully!"
369+
break
370+
fi
371+
372+
# Check if all checks are complete
373+
PENDING_CHECKS=$(echo "$PR_DATA" | jq '[.statusCheckRollup[] | select(.status == "IN_PROGRESS" or .status == "QUEUED" or .status == "PENDING")] | length')
374+
TOTAL_CHECKS=$(echo "$PR_DATA" | jq '.statusCheckRollup | length')
375+
376+
echo "Checks: $((TOTAL_CHECKS - PENDING_CHECKS))/$TOTAL_CHECKS complete"
377+
378+
if [ "$PENDING_CHECKS" -eq 0 ] && [ "$TOTAL_CHECKS" -gt 0 ]; then
379+
# All checks done, check for failures
380+
FAILED_CHECKS=$(echo "$PR_DATA" | jq -r '.statusCheckRollup[] | select(.conclusion == "FAILURE" or .conclusion == "CANCELLED") | .name')
381+
if [ -n "$FAILED_CHECKS" ]; then
382+
echo "ERROR: Some checks failed:"
383+
echo "$FAILED_CHECKS"
384+
exit 1
385+
fi
386+
387+
if [ "$MERGEABLE" = "MERGEABLE" ]; then
388+
echo "All checks passed and PR is mergeable. GitHub should auto-merge shortly..."
389+
fi
390+
fi
391+
392+
sleep $INTERVAL
393+
ELAPSED=$((ELAPSED + INTERVAL))
394+
done
395+
396+
if [ "$STATE" != "MERGED" ]; then
397+
echo "ERROR: PR did not merge within timeout"
398+
echo "Final state: $STATE, Mergeable: $MERGEABLE"
399+
exit 1
400+
fi
401+
402+
- name: Checkout main and create tag
403+
run: |
404+
VERSION="${{ steps.version.outputs.next }}"
405+
406+
# Switch to main and pull latest
407+
git checkout main
408+
git pull origin main
409+
410+
# Create and push version tag
311411
git config user.name "github-actions[bot]"
312412
git config user.email "github-actions[bot]@users.noreply.github.com"
313-
git add cli/extension.yaml cli/CHANGELOG.md
314-
git commit -m "chore: bump version to $VERSION"
315-
git push
316-
317-
# Create and push version tag for future releases
318413
git tag -a "v${VERSION}" -m "Release version ${VERSION}"
319414
git push origin "v${VERSION}"
320415

0 commit comments

Comments
 (0)