|
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 (GitHub Release + automatic R2 publish). workflow_dispatch can open a |
| 6 | +# bump PR or tag the current VERSION_CLI. This workflow never pushes commits to main. |
6 | 7 | on: |
7 | 8 | push: |
8 | 9 | branches: [main] |
| 10 | + paths: |
| 11 | + - VERSION_CLI |
| 12 | + - src/cortex-cli/VERSION |
9 | 13 | workflow_dispatch: |
10 | 14 | inputs: |
11 | | - bump_type: |
12 | | - description: "Version bump type" |
| 15 | + action: |
| 16 | + description: "Action to perform" |
13 | 17 | required: true |
14 | 18 | type: choice |
| 19 | + options: |
| 20 | + - tag-current-version |
| 21 | + - open-bump-pr |
| 22 | + bump_type: |
| 23 | + description: "Bump type (only used with open-bump-pr)" |
| 24 | + required: false |
| 25 | + type: choice |
15 | 26 | options: |
16 | 27 | - patch |
17 | 28 | - minor |
18 | 29 | - major |
19 | | - create_release: |
20 | | - description: "Create release after bump" |
21 | | - required: false |
22 | | - type: boolean |
23 | | - default: true |
| 30 | + default: patch |
24 | 31 |
|
25 | 32 | permissions: |
26 | 33 | contents: write |
| 34 | + pull-requests: write |
27 | 35 |
|
28 | 36 | jobs: |
29 | | - bump-version: |
30 | | - name: Bump Version |
| 37 | + # Always-green job so skipped tag/PR jobs do not fail the workflow. |
| 38 | + gate: |
| 39 | + name: Workflow started |
| 40 | + runs-on: ubuntu-latest |
| 41 | + steps: |
| 42 | + - name: Note |
| 43 | + env: |
| 44 | + EVENT_NAME: ${{ github.event_name }} |
| 45 | + GIT_REF: ${{ github.ref }} |
| 46 | + run: | |
| 47 | + echo "event=${EVENT_NAME}" |
| 48 | + echo "ref=${GIT_REF}" |
| 49 | + echo "Tagging runs only for 'chore: bump version to …' merges or workflow_dispatch." |
| 50 | +
|
| 51 | + tag-on-version-bump-merge: |
| 52 | + name: Tag release on version-bump merge |
31 | 53 | runs-on: ubuntu-latest |
32 | 54 | if: | |
33 | | - github.event_name == 'workflow_dispatch' || |
34 | | - ( |
35 | | - github.event_name == 'push' && |
36 | | - !contains(github.event.head_commit.message, 'chore: bump version') |
37 | | - ) |
| 55 | + github.event_name == 'push' && |
| 56 | + contains(github.event.head_commit.message, 'chore: bump version to') |
38 | 57 | outputs: |
39 | | - new_version: ${{ steps.bump.outputs.new_version }} |
40 | | - old_version: ${{ steps.bump.outputs.old_version }} |
| 58 | + version: ${{ steps.version.outputs.version }} |
| 59 | + tagged: ${{ steps.tag.outputs.tagged }} |
41 | 60 | steps: |
42 | 61 | - uses: actions/checkout@v4 |
43 | 62 | with: |
44 | 63 | fetch-depth: 0 |
45 | | - token: ${{ secrets.GITHUB_TOKEN }} |
46 | 64 |
|
47 | | - - name: Configure Git |
| 65 | + - name: Read VERSION_CLI |
| 66 | + id: version |
| 67 | + run: | |
| 68 | + VERSION=$(tr -d '[:space:]' < VERSION_CLI) |
| 69 | + if [[ ! "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+([.-][A-Za-z0-9.]+)?$ ]]; then |
| 70 | + echo "::error::VERSION_CLI is missing or not a valid version" |
| 71 | + exit 1 |
| 72 | + fi |
| 73 | + echo "version=$VERSION" >> "$GITHUB_OUTPUT" |
| 74 | + echo "Release version from VERSION_CLI: $VERSION" |
| 75 | +
|
| 76 | + - name: Verify bump commit message |
| 77 | + env: |
| 78 | + VERSION: ${{ steps.version.outputs.version }} |
48 | 79 | run: | |
| 80 | + expected="chore: bump version to ${VERSION}" |
| 81 | + MSG=$(git log -1 --pretty=%B) |
| 82 | + if ! printf '%s\n' "$MSG" | grep -F -q "$expected"; then |
| 83 | + echo "::error::Head commit must contain '${expected}'" |
| 84 | + exit 1 |
| 85 | + fi |
| 86 | + ./scripts/check-cli-version.sh |
| 87 | +
|
| 88 | + - name: Create and push tag |
| 89 | + id: tag |
| 90 | + env: |
| 91 | + VERSION: ${{ steps.version.outputs.version }} |
| 92 | + run: | |
| 93 | + TAG="v${VERSION}" |
| 94 | + if git rev-parse "$TAG" >/dev/null 2>&1; then |
| 95 | + echo "Tag $TAG already exists; skipping" |
| 96 | + echo "tagged=false" >> "$GITHUB_OUTPUT" |
| 97 | + exit 0 |
| 98 | + fi |
49 | 99 | git config user.name "github-actions[bot]" |
50 | 100 | git config user.email "github-actions[bot]@users.noreply.github.com" |
| 101 | + git tag -a "$TAG" -m "Release $TAG" |
| 102 | + git push origin "$TAG" |
| 103 | + echo "tagged=true" >> "$GITHUB_OUTPUT" |
| 104 | + echo "Created and pushed $TAG" |
| 105 | +
|
| 106 | + open-bump-pr: |
| 107 | + name: Open version-bump PR |
| 108 | + runs-on: ubuntu-latest |
| 109 | + if: github.event_name == 'workflow_dispatch' && inputs.action == 'open-bump-pr' |
| 110 | + steps: |
| 111 | + - uses: actions/checkout@v4 |
| 112 | + with: |
| 113 | + ref: main |
| 114 | + fetch-depth: 0 |
51 | 115 |
|
52 | 116 | - name: Bump version |
53 | 117 | id: bump |
| 118 | + env: |
| 119 | + BUMP_TYPE: ${{ inputs.bump_type }} |
54 | 120 | run: | |
| 121 | + case "$BUMP_TYPE" in |
| 122 | + patch|minor|major) ;; |
| 123 | + *) |
| 124 | + echo "::error::bump_type must be patch, minor, or major" |
| 125 | + exit 1 |
| 126 | + ;; |
| 127 | + esac |
55 | 128 | OLD_VERSION=$(tr -d '[:space:]' < VERSION_CLI) |
56 | 129 | echo "old_version=$OLD_VERSION" >> "$GITHUB_OUTPUT" |
57 | | -
|
58 | | - Bump="${{ github.event_name == 'workflow_dispatch' && inputs.bump_type || 'patch' }}" |
59 | 130 | chmod +x ./scripts/bump-version.sh |
60 | | - ./scripts/bump-version.sh "$Bump" |
61 | | -
|
| 131 | + ./scripts/bump-version.sh "$BUMP_TYPE" |
62 | 132 | NEW_VERSION=$(tr -d '[:space:]' < VERSION_CLI) |
63 | 133 | echo "new_version=$NEW_VERSION" >> "$GITHUB_OUTPUT" |
64 | | - echo "Version bumped from $OLD_VERSION to $NEW_VERSION" |
65 | 134 |
|
66 | | - - name: Commit version bump |
| 135 | + - name: Create pull request |
| 136 | + env: |
| 137 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 138 | + NEW_VERSION: ${{ steps.bump.outputs.new_version }} |
| 139 | + OLD_VERSION: ${{ steps.bump.outputs.old_version }} |
67 | 140 | run: | |
| 141 | + BRANCH="chore/bump-version-${NEW_VERSION}" |
| 142 | + git config user.name "github-actions[bot]" |
| 143 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 144 | + git checkout -b "$BRANCH" |
68 | 145 | 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 |
| 146 | + git commit -m "chore: bump version to ${NEW_VERSION}" |
| 147 | + git push -u origin "$BRANCH" |
| 148 | + BODY="Automated version bump from ${OLD_VERSION} to ${NEW_VERSION}. Merge this PR (do not push to main). version-bump.yml then tags v${NEW_VERSION}; release.yml builds artifacts and publish-r2.yml publishes to software.cortex.foundation." |
| 149 | + gh pr create \ |
| 150 | + --base main \ |
| 151 | + --head "$BRANCH" \ |
| 152 | + --title "chore: bump version to ${NEW_VERSION}" \ |
| 153 | + --body "$BODY" |
| 154 | +
|
| 155 | + tag-current-version: |
| 156 | + name: Tag current VERSION_CLI |
| 157 | + runs-on: ubuntu-latest |
| 158 | + if: github.event_name == 'workflow_dispatch' && inputs.action == 'tag-current-version' |
| 159 | + steps: |
| 160 | + - uses: actions/checkout@v4 |
| 161 | + with: |
| 162 | + fetch-depth: 0 |
| 163 | + |
| 164 | + - name: Read VERSION_CLI |
| 165 | + id: version |
| 166 | + run: | |
| 167 | + VERSION=$(tr -d '[:space:]' < VERSION_CLI) |
| 168 | + if [[ ! "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+([.-][A-Za-z0-9.]+)?$ ]]; then |
| 169 | + echo "::error::VERSION_CLI is missing or not a valid version" |
| 170 | + exit 1 |
| 171 | + fi |
| 172 | + echo "version=$VERSION" >> "$GITHUB_OUTPUT" |
| 173 | + ./scripts/check-cli-version.sh |
71 | 174 |
|
72 | 175 | - name: Create and push tag |
73 | | - if: github.event_name == 'push' || inputs.create_release |
| 176 | + env: |
| 177 | + VERSION: ${{ steps.version.outputs.version }} |
74 | 178 | run: | |
75 | | - git tag "v${{ steps.bump.outputs.new_version }}" |
76 | | - git push origin "v${{ steps.bump.outputs.new_version }}" |
| 179 | + TAG="v${VERSION}" |
| 180 | + if git rev-parse "$TAG" >/dev/null 2>&1; then |
| 181 | + echo "::error::Tag $TAG already exists" |
| 182 | + exit 1 |
| 183 | + fi |
| 184 | + git config user.name "github-actions[bot]" |
| 185 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 186 | + git tag -a "$TAG" -m "Release $TAG" |
| 187 | + git push origin "$TAG" |
| 188 | + echo "Created and pushed $TAG (triggers release.yml)" |
77 | 189 |
|
78 | | - notify: |
| 190 | + summary: |
79 | 191 | name: Summary |
80 | 192 | runs-on: ubuntu-latest |
81 | | - needs: bump-version |
| 193 | + needs: [tag-on-version-bump-merge] |
| 194 | + if: always() && needs.tag-on-version-bump-merge.result != 'skipped' |
82 | 195 | steps: |
83 | 196 | - name: Summary |
| 197 | + env: |
| 198 | + VERSION: ${{ needs.tag-on-version-bump-merge.outputs.version }} |
| 199 | + TAGGED: ${{ needs.tag-on-version-bump-merge.outputs.tagged }} |
84 | 200 | run: | |
85 | | - echo "## Version bump" >> "$GITHUB_STEP_SUMMARY" |
86 | | - echo "" >> "$GITHUB_STEP_SUMMARY" |
87 | | - echo "| | |" >> "$GITHUB_STEP_SUMMARY" |
88 | | - 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" |
| 201 | + { |
| 202 | + echo "## Version tag" |
| 203 | + echo "" |
| 204 | + echo "| | |" |
| 205 | + echo "|---|---|" |
| 206 | + echo "| **Version** | ${VERSION} |" |
| 207 | + echo "| **Tagged** | ${TAGGED} |" |
| 208 | + } >> "$GITHUB_STEP_SUMMARY" |
0 commit comments