Skip to content

Commit 6b200c5

Browse files
committed
ci: allow cutting a release via workflow_dispatch
Add a `release` boolean input to workflow_dispatch and let the release job run when it is ticked (a plain dispatch still just runs CI). On that manual path, if release-plz finds nothing new to release, force a patch bump so the trigger reliably produces a release. Pushes to main still auto-release as before; this only adds an on-demand path.
1 parent 2f1ceed commit 6b200c5

1 file changed

Lines changed: 38 additions & 15 deletions

File tree

.github/workflows/ci.yml

Lines changed: 38 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ on:
66
pull_request:
77
branches: [main]
88
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
914

1015
concurrency:
1116
group: ${{ github.workflow }}-${{ github.ref }}
@@ -866,7 +871,12 @@ jobs:
866871
release:
867872
name: Release
868873
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))
870880
# release-plz bumps Cargo.lock on every release, which invalidates
871881
# rust-cache's target/ wholesale, and the sccache Save steps only run on a
872882
# main push — so the first release after a cold/evicted cache rebuilds the
@@ -920,21 +930,34 @@ jobs:
920930
git config user.email "github-actions[bot]@users.noreply.github.com"
921931
git add -A
922932
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)"
937949
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}"
938961
- name: Create releases
939962
id: release
940963
if: steps.bump.outputs.bumped == 'true'

0 commit comments

Comments
 (0)