|
1 | 1 | name: Draft Release |
| 2 | +run-name: "Draft Release (${{ inputs.bump }} bump)" |
2 | 3 |
|
3 | 4 | on: |
4 | 5 | workflow_dispatch: |
|
14 | 15 |
|
15 | 16 | permissions: |
16 | 17 | contents: write |
| 18 | + pull-requests: write |
17 | 19 |
|
18 | 20 | jobs: |
19 | 21 | draft-release: |
@@ -59,11 +61,90 @@ jobs: |
59 | 61 | echo "rc=$RC_NUM" >> $GITHUB_OUTPUT |
60 | 62 | echo "Next version: v${NEXT}-rc.${RC_NUM}" |
61 | 63 |
|
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 }} |
63 | 71 | 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 | +
|
64 | 144 | VERSION="v${{ steps.version.outputs.next }}-rc.${{ steps.version.outputs.rc }}" |
65 | 145 | git tag "$VERSION" |
66 | 146 | git push origin "$VERSION" |
| 147 | + echo "Tagged: $VERSION" |
67 | 148 |
|
68 | 149 | - name: Create draft release |
69 | 150 | env: |
|
0 commit comments