|
6 | 6 | pull_request: |
7 | 7 | branches: [main] |
8 | 8 | workflow_dispatch: |
| 9 | + inputs: |
| 10 | + release: |
| 11 | + description: "Cut a release from main (forces a patch bump when there is nothing new to release)" |
| 12 | + type: boolean |
| 13 | + default: false |
9 | 14 |
|
10 | 15 | concurrency: |
11 | 16 | group: ${{ github.workflow }}-${{ github.ref }} |
@@ -866,7 +871,12 @@ jobs: |
866 | 871 | release: |
867 | 872 | name: Release |
868 | 873 | needs: [check, test] |
869 | | - if: github.ref == 'refs/heads/main' && github.event_name == 'push' |
| 874 | + # Auto on push to main, or on demand via `workflow_dispatch` with the |
| 875 | + # `release` input ticked (a dispatch without it just runs CI). |
| 876 | + if: > |
| 877 | + github.ref == 'refs/heads/main' && |
| 878 | + (github.event_name == 'push' || |
| 879 | + (github.event_name == 'workflow_dispatch' && inputs.release)) |
870 | 880 | # release-plz bumps Cargo.lock on every release, which invalidates |
871 | 881 | # rust-cache's target/ wholesale, and the sccache Save steps only run on a |
872 | 882 | # main push — so the first release after a cold/evicted cache rebuilds the |
@@ -920,21 +930,34 @@ jobs: |
920 | 930 | git config user.email "github-actions[bot]@users.noreply.github.com" |
921 | 931 | git add -A |
922 | 932 | if git diff --cached --quiet; then |
923 | | - echo 'No version bump to commit' |
924 | | - echo "bumped=false" >> "$GITHUB_OUTPUT" |
925 | | - else |
926 | | - VERSION=$(grep '^version =' Cargo.toml | head -1 | sed 's/version = "\(.*\)"/\1/') |
927 | | - # [skip ci] keeps this bot bump from spawning a second, redundant CI |
928 | | - # run: the release and its asset builds already ran as downstream |
929 | | - # jobs of the push that triggered this one, so re-running the full |
930 | | - # matrix here only burns minutes and cancels the original run's |
931 | | - # trailing jobs via the cancel-in-progress concurrency group. |
932 | | - git commit -m "chore: release v${VERSION} [skip ci]" |
933 | | - git push |
934 | | - echo "bumped=true" >> "$GITHUB_OUTPUT" |
935 | | - echo "version=${VERSION}" >> "$GITHUB_OUTPUT" |
936 | | - echo "Bumped to v${VERSION}" |
| 933 | + # release-plz found nothing to release. On a manual dispatch the |
| 934 | + # operator explicitly asked for a release, so force a patch bump |
| 935 | + # rather than no-op; on a push, leave it as a clean no-release. |
| 936 | + if [ "${{ github.event_name }}" != "workflow_dispatch" ]; then |
| 937 | + echo 'No version bump to commit' |
| 938 | + echo "bumped=false" >> "$GITHUB_OUTPUT" |
| 939 | + exit 0 |
| 940 | + fi |
| 941 | + CUR=$(grep '^version = ' Cargo.toml | head -1 | sed -E 's/version = "(.*)"/\1/') |
| 942 | + NEW=$(echo "$CUR" | awk -F. '{printf "%d.%d.%d", $1, $2, $3 + 1}') |
| 943 | + awk -v new="$NEW" '!done && /^version = "[^"]*"/ {sub(/"[^"]*"/, "\"" new "\""); done=1} {print}' Cargo.toml > Cargo.toml.tmp |
| 944 | + mv Cargo.toml.tmp Cargo.toml |
| 945 | + # Sync the workspace crates' versions in Cargo.lock (not their deps). |
| 946 | + cargo update --workspace |
| 947 | + git add -A |
| 948 | + echo "Forced patch bump v${CUR} -> v${NEW} (manual release, no new releasable commits)" |
937 | 949 | fi |
| 950 | + VERSION=$(grep '^version = ' Cargo.toml | head -1 | sed -E 's/version = "(.*)"/\1/') |
| 951 | + # [skip ci] keeps this bot bump from spawning a second, redundant CI |
| 952 | + # run: the release and its asset builds already ran as downstream |
| 953 | + # jobs of the push that triggered this one, so re-running the full |
| 954 | + # matrix here only burns minutes and cancels the original run's |
| 955 | + # trailing jobs via the cancel-in-progress concurrency group. |
| 956 | + git commit -m "chore: release v${VERSION} [skip ci]" |
| 957 | + git push |
| 958 | + echo "bumped=true" >> "$GITHUB_OUTPUT" |
| 959 | + echo "version=${VERSION}" >> "$GITHUB_OUTPUT" |
| 960 | + echo "Released v${VERSION}" |
938 | 961 | - name: Create releases |
939 | 962 | id: release |
940 | 963 | if: steps.bump.outputs.bumped == 'true' |
|
0 commit comments