|
1 | 1 | name: Version Bump |
2 | 2 |
|
3 | | -# Patch-bump and tag on every merge to main. workflow_dispatch keeps |
4 | | -# explicit patch/minor/major control. Skip commits that are already bumps |
5 | | -# so the bot cannot loop. |
| 3 | +# Version bumps land on main through normal PRs (protected branch / ruleset safe). |
| 4 | +# After a version-bump PR merges, this workflow tags v{VERSION_CLI}, which triggers |
| 5 | +# release.yml. workflow_dispatch can open a bump PR or tag the current VERSION_CLI. |
6 | 6 | on: |
7 | 7 | push: |
8 | 8 | branches: [main] |
9 | 9 | workflow_dispatch: |
10 | 10 | inputs: |
11 | | - bump_type: |
12 | | - description: "Version bump type" |
| 11 | + action: |
| 12 | + description: "Action to perform" |
13 | 13 | required: true |
14 | 14 | type: choice |
| 15 | + options: |
| 16 | + - tag-current-version |
| 17 | + - open-bump-pr |
| 18 | + bump_type: |
| 19 | + description: "Bump type (only used with open-bump-pr)" |
| 20 | + required: false |
| 21 | + type: choice |
15 | 22 | options: |
16 | 23 | - patch |
17 | 24 | - minor |
18 | 25 | - major |
19 | | - create_release: |
20 | | - description: "Create release after bump" |
21 | | - required: false |
22 | | - type: boolean |
23 | | - default: true |
| 26 | + default: patch |
24 | 27 |
|
25 | 28 | permissions: |
26 | 29 | contents: write |
| 30 | + pull-requests: write |
27 | 31 |
|
28 | 32 | jobs: |
29 | | - bump-version: |
30 | | - name: Bump Version |
| 33 | + tag-on-version-bump-merge: |
| 34 | + name: Tag release on version-bump merge |
31 | 35 | runs-on: ubuntu-latest |
32 | 36 | if: | |
33 | | - github.event_name == 'workflow_dispatch' || |
34 | | - ( |
35 | | - github.event_name == 'push' && |
36 | | - !contains(github.event.head_commit.message, 'chore: bump version') |
37 | | - ) |
| 37 | + github.event_name == 'push' && |
| 38 | + contains(github.event.head_commit.message, 'chore: bump version to') |
38 | 39 | outputs: |
39 | | - new_version: ${{ steps.bump.outputs.new_version }} |
40 | | - old_version: ${{ steps.bump.outputs.old_version }} |
| 40 | + version: ${{ steps.version.outputs.version }} |
| 41 | + tagged: ${{ steps.tag.outputs.tagged }} |
41 | 42 | steps: |
42 | 43 | - uses: actions/checkout@v4 |
43 | 44 | with: |
44 | 45 | fetch-depth: 0 |
45 | | - token: ${{ secrets.GITHUB_TOKEN }} |
46 | 46 |
|
47 | | - - name: Configure Git |
| 47 | + - name: Read VERSION_CLI |
| 48 | + id: version |
| 49 | + run: | |
| 50 | + VERSION=$(tr -d '[:space:]' < VERSION_CLI) |
| 51 | + if [ -z "$VERSION" ]; then |
| 52 | + echo "::error::VERSION_CLI is empty" |
| 53 | + exit 1 |
| 54 | + fi |
| 55 | + echo "version=$VERSION" >> "$GITHUB_OUTPUT" |
| 56 | + echo "Release version from VERSION_CLI: $VERSION" |
| 57 | +
|
| 58 | + - name: Verify bump commit message |
48 | 59 | run: | |
| 60 | + VERSION="${{ steps.version.outputs.version }}" |
| 61 | + MSG="${{ github.event.head_commit.message }}" |
| 62 | + if ! echo "$MSG" | grep -q "chore: bump version to ${VERSION}"; then |
| 63 | + echo "::error::Head commit must be 'chore: bump version to ${VERSION}' (got: ${MSG})" |
| 64 | + exit 1 |
| 65 | + fi |
| 66 | + ./scripts/check-cli-version.sh |
| 67 | +
|
| 68 | + - name: Create and push tag |
| 69 | + id: tag |
| 70 | + env: |
| 71 | + VERSION: ${{ steps.version.outputs.version }} |
| 72 | + run: | |
| 73 | + TAG="v${VERSION}" |
| 74 | + if git rev-parse "$TAG" >/dev/null 2>&1; then |
| 75 | + echo "Tag $TAG already exists; skipping" |
| 76 | + echo "tagged=false" >> "$GITHUB_OUTPUT" |
| 77 | + exit 0 |
| 78 | + fi |
49 | 79 | git config user.name "github-actions[bot]" |
50 | 80 | git config user.email "github-actions[bot]@users.noreply.github.com" |
| 81 | + git tag -a "$TAG" -m "Release $TAG" |
| 82 | + git push origin "$TAG" |
| 83 | + echo "tagged=true" >> "$GITHUB_OUTPUT" |
| 84 | + echo "Created and pushed $TAG" |
| 85 | +
|
| 86 | + open-bump-pr: |
| 87 | + name: Open version-bump PR |
| 88 | + runs-on: ubuntu-latest |
| 89 | + if: github.event_name == 'workflow_dispatch' && inputs.action == 'open-bump-pr' |
| 90 | + steps: |
| 91 | + - uses: actions/checkout@v4 |
| 92 | + with: |
| 93 | + ref: main |
| 94 | + fetch-depth: 0 |
51 | 95 |
|
52 | 96 | - name: Bump version |
53 | 97 | id: bump |
54 | 98 | run: | |
55 | 99 | OLD_VERSION=$(tr -d '[:space:]' < VERSION_CLI) |
56 | 100 | echo "old_version=$OLD_VERSION" >> "$GITHUB_OUTPUT" |
57 | | -
|
58 | | - Bump="${{ github.event_name == 'workflow_dispatch' && inputs.bump_type || 'patch' }}" |
59 | 101 | chmod +x ./scripts/bump-version.sh |
60 | | - ./scripts/bump-version.sh "$Bump" |
61 | | -
|
| 102 | + ./scripts/bump-version.sh "${{ inputs.bump_type }}" |
62 | 103 | NEW_VERSION=$(tr -d '[:space:]' < VERSION_CLI) |
63 | 104 | echo "new_version=$NEW_VERSION" >> "$GITHUB_OUTPUT" |
64 | | - echo "Version bumped from $OLD_VERSION to $NEW_VERSION" |
65 | 105 |
|
66 | | - - name: Commit version bump |
| 106 | + - name: Create pull request |
| 107 | + env: |
| 108 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
67 | 109 | run: | |
| 110 | + NEW_VERSION="${{ steps.bump.outputs.new_version }}" |
| 111 | + BRANCH="chore/bump-version-${NEW_VERSION}" |
| 112 | + git config user.name "github-actions[bot]" |
| 113 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 114 | + git checkout -b "$BRANCH" |
68 | 115 | git add VERSION_CLI src/cortex-cli/VERSION Cargo.toml Cargo.lock |
69 | | - git commit -m "chore: bump version to ${{ steps.bump.outputs.new_version }}" |
70 | | - git push origin HEAD |
| 116 | + git commit -m "chore: bump version to ${NEW_VERSION}" |
| 117 | + git push -u origin "$BRANCH" |
| 118 | + gh pr create \ |
| 119 | + --base main \ |
| 120 | + --head "$BRANCH" \ |
| 121 | + --title "chore: bump version to ${NEW_VERSION}" \ |
| 122 | + --body "$(cat <<EOF |
| 123 | +## Summary |
| 124 | + |
| 125 | +Automated version bump from ${{ steps.bump.outputs.old_version }} to ${NEW_VERSION}. |
| 126 | + |
| 127 | +## Release path |
| 128 | + |
| 129 | +1. Merge this PR (no direct pushes to \`main\`). |
| 130 | +2. \`version-bump.yml\` tags \`v${NEW_VERSION}\` on merge. |
| 131 | +3. The tag triggers \`release.yml\` to build artifacts and create the GitHub Release. |
| 132 | +4. Publish to R2 manually via \`publish-r2.yml\` workflow_dispatch when ready. |
| 133 | +EOF |
| 134 | +)" |
| 135 | + |
| 136 | + tag-current-version: |
| 137 | + name: Tag current VERSION_CLI |
| 138 | + runs-on: ubuntu-latest |
| 139 | + if: github.event_name == 'workflow_dispatch' && inputs.action == 'tag-current-version' |
| 140 | + steps: |
| 141 | + - uses: actions/checkout@v4 |
| 142 | + with: |
| 143 | + fetch-depth: 0 |
| 144 | + |
| 145 | + - name: Read VERSION_CLI |
| 146 | + id: version |
| 147 | + run: | |
| 148 | + VERSION=$(tr -d '[:space:]' < VERSION_CLI) |
| 149 | + echo "version=$VERSION" >> "$GITHUB_OUTPUT" |
| 150 | + ./scripts/check-cli-version.sh |
71 | 151 |
|
72 | 152 | - name: Create and push tag |
73 | | - if: github.event_name == 'push' || inputs.create_release |
| 153 | + env: |
| 154 | + VERSION: ${{ steps.version.outputs.version }} |
74 | 155 | run: | |
75 | | - git tag "v${{ steps.bump.outputs.new_version }}" |
76 | | - git push origin "v${{ steps.bump.outputs.new_version }}" |
| 156 | + TAG="v${VERSION}" |
| 157 | + if git rev-parse "$TAG" >/dev/null 2>&1; then |
| 158 | + echo "::error::Tag $TAG already exists" |
| 159 | + exit 1 |
| 160 | + fi |
| 161 | + git config user.name "github-actions[bot]" |
| 162 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 163 | + git tag -a "$TAG" -m "Release $TAG" |
| 164 | + git push origin "$TAG" |
| 165 | + echo "Created and pushed $TAG (triggers release.yml)" |
77 | 166 |
|
78 | | - notify: |
| 167 | + summary: |
79 | 168 | name: Summary |
80 | 169 | runs-on: ubuntu-latest |
81 | | - needs: bump-version |
| 170 | + needs: [tag-on-version-bump-merge] |
| 171 | + if: always() && needs.tag-on-version-bump-merge.result != 'skipped' |
82 | 172 | steps: |
83 | 173 | - name: Summary |
84 | 174 | run: | |
85 | | - echo "## Version bump" >> "$GITHUB_STEP_SUMMARY" |
| 175 | + echo "## Version tag" >> "$GITHUB_STEP_SUMMARY" |
86 | 176 | echo "" >> "$GITHUB_STEP_SUMMARY" |
87 | 177 | echo "| | |" >> "$GITHUB_STEP_SUMMARY" |
88 | 178 | echo "|---|---|" >> "$GITHUB_STEP_SUMMARY" |
89 | | - echo "| **Previous** | ${{ needs.bump-version.outputs.old_version }} |" >> "$GITHUB_STEP_SUMMARY" |
90 | | - echo "| **New** | ${{ needs.bump-version.outputs.new_version }} |" >> "$GITHUB_STEP_SUMMARY" |
| 179 | + echo "| **Version** | ${{ needs.tag-on-version-bump-merge.outputs.version }} |" >> "$GITHUB_STEP_SUMMARY" |
| 180 | + echo "| **Tagged** | ${{ needs.tag-on-version-bump-merge.outputs.tagged }} |" >> "$GITHUB_STEP_SUMMARY" |
0 commit comments