Draft Release (patch bump) #8
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Draft Release | |
| run-name: "Draft Release (${{ inputs.bump }} bump)" | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| bump: | |
| description: "Version bump type" | |
| required: true | |
| type: choice | |
| options: | |
| - patch | |
| - minor | |
| - major | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| jobs: | |
| draft-release: | |
| name: Create Draft Release | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: main | |
| fetch-depth: 0 | |
| - name: Calculate next version and rc number | |
| id: version | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| # Find the latest official (non-rc) release | |
| LATEST=$(gh release list --json tagName,isPrerelease --jq '[.[] | select(.isPrerelease == false)] | .[0].tagName // empty' 2>/dev/null || true) | |
| if [ -z "$LATEST" ]; then | |
| MAJOR=0; MINOR=0; PATCH=0 | |
| else | |
| VERSION="${LATEST#v}" | |
| MAJOR=$(echo "$VERSION" | cut -d. -f1) | |
| MINOR=$(echo "$VERSION" | cut -d. -f2) | |
| PATCH=$(echo "$VERSION" | cut -d. -f3) | |
| fi | |
| case "${{ inputs.bump }}" in | |
| major) MAJOR=$((MAJOR + 1)); MINOR=0; PATCH=0 ;; | |
| minor) MINOR=$((MINOR + 1)); PATCH=0 ;; | |
| patch) PATCH=$((PATCH + 1)) ;; | |
| esac | |
| NEXT="${MAJOR}.${MINOR}.${PATCH}" | |
| # Count existing rc tags for this version to determine next rc number | |
| RC_COUNT=$(gh release list --json tagName --jq "[.[] | select(.tagName | startswith(\"v${NEXT}-rc.\"))] | length" 2>/dev/null || echo "0") | |
| RC_NUM=$((RC_COUNT + 1)) | |
| echo "next=$NEXT" >> $GITHUB_OUTPUT | |
| echo "rc=$RC_NUM" >> $GITHUB_OUTPUT | |
| echo "Next version: v${NEXT}-rc.${RC_NUM}" | |
| - name: Install Rust | |
| run: rustup toolchain install stable | |
| - name: Bump version in Cargo.toml and open PR | |
| id: pr | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| NEXT="${{ steps.version.outputs.next }}" | |
| RC="${{ steps.version.outputs.rc }}" | |
| FULL_VERSION="${NEXT}-rc.${RC}" | |
| BRANCH="release/bump-${FULL_VERSION}" | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git checkout -b "$BRANCH" | |
| # Replace the version line in the workspace Cargo.toml | |
| sed -i "s/^version = \".*\"/version = \"${FULL_VERSION}\"/" Cargo.toml | |
| cargo update -p skardi --precise "${FULL_VERSION}" | |
| git add Cargo.toml Cargo.lock | |
| git commit -m "chore: bump version to ${FULL_VERSION}" | |
| git push origin "$BRANCH" | |
| PR_URL=$(gh pr create \ | |
| --title "chore: bump version to ${FULL_VERSION}" \ | |
| --body "Automated version bump to \`${FULL_VERSION}\` ahead of the \`v${FULL_VERSION}\` release." \ | |
| --base main \ | |
| --head "$BRANCH") | |
| echo "pr_url=$PR_URL" >> $GITHUB_OUTPUT | |
| echo "branch=$BRANCH" >> $GITHUB_OUTPUT | |
| echo "PR created: $PR_URL" | |
| - name: Wait for PR to be merged (1 hour timeout) | |
| id: wait | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| PR_URL="${{ steps.pr.outputs.pr_url }}" | |
| TIMEOUT=3600 # 1 hour in seconds | |
| INTERVAL=30 # poll every 30 seconds | |
| ELAPSED=0 | |
| echo "Waiting for PR to be merged: $PR_URL" | |
| while [ $ELAPSED -lt $TIMEOUT ]; do | |
| STATE=$(gh pr view "$PR_URL" --json state,mergeStateStatus --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 RC tag | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| git fetch origin main | |
| git checkout main | |
| git pull origin main | |
| VERSION="v${{ steps.version.outputs.next }}-rc.${{ steps.version.outputs.rc }}" | |
| git tag "$VERSION" | |
| git push origin "$VERSION" | |
| echo "Tagged: $VERSION" | |
| - name: Create draft release | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| VERSION="v${{ steps.version.outputs.next }}-rc.${{ steps.version.outputs.rc }}" | |
| gh release create "$VERSION" \ | |
| --draft \ | |
| --prerelease \ | |
| --title "$VERSION" \ | |
| --generate-notes |