Skip to content

Commit 3b74c6c

Browse files
authored
chore: add manual release workflow dispatch (#177)
* chore: add manual release workflow dispatch * Fix GitHub Actions shell injection warnings
1 parent db2cdbd commit 3b74c6c

2 files changed

Lines changed: 37 additions & 12 deletions

File tree

.github/workflows/release.yml

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@ on:
44
pull_request:
55
types: [closed]
66
branches: [main]
7+
workflow_dispatch:
8+
inputs:
9+
bump_type:
10+
description: Version bump to apply
11+
required: true
12+
type: choice
13+
options:
14+
- patch
15+
- minor
16+
- major
717

818
permissions:
919
contents: read
@@ -16,23 +26,35 @@ jobs:
1626
check-release-label:
1727
name: Check for release label
1828
if: |
19-
github.event.pull_request.merged == true
20-
&& contains(github.event.pull_request.labels.*.name, 'release')
29+
github.event_name == 'workflow_dispatch' ||
30+
(github.event_name == 'pull_request' &&
31+
github.event.pull_request.merged == true &&
32+
contains(github.event.pull_request.labels.*.name, 'release'))
2133
runs-on: ubuntu-latest
2234
outputs:
2335
should-release: ${{ steps.check.outputs.should-release }}
2436
bump-type: ${{ steps.check.outputs.bump-type }}
2537
steps:
2638
- name: Check release conditions
2739
id: check
40+
env:
41+
EVENT_NAME: ${{ github.event_name }}
42+
BUMP_TYPE: ${{ inputs.bump_type }}
43+
HAS_BUMP_MAJOR: ${{ contains(github.event.pull_request.labels.*.name, 'bump-major') }}
44+
HAS_BUMP_MINOR: ${{ contains(github.event.pull_request.labels.*.name, 'bump-minor') }}
45+
HAS_BUMP_PATCH: ${{ contains(github.event.pull_request.labels.*.name, 'bump-patch') }}
2846
run: |
29-
if ${{ contains(github.event.pull_request.labels.*.name, 'bump-major') }}; then
47+
if [ "$EVENT_NAME" = "workflow_dispatch" ]; then
48+
echo "bump-type=$BUMP_TYPE" >> "$GITHUB_OUTPUT"
49+
echo "should-release=true" >> "$GITHUB_OUTPUT"
50+
echo "Manual release requested with bump type '$BUMP_TYPE'"
51+
elif [ "$HAS_BUMP_MAJOR" = "true" ]; then
3052
echo "bump-type=major" >> "$GITHUB_OUTPUT"
3153
echo "should-release=true" >> "$GITHUB_OUTPUT"
32-
elif ${{ contains(github.event.pull_request.labels.*.name, 'bump-minor') }}; then
54+
elif [ "$HAS_BUMP_MINOR" = "true" ]; then
3355
echo "bump-type=minor" >> "$GITHUB_OUTPUT"
3456
echo "should-release=true" >> "$GITHUB_OUTPUT"
35-
elif ${{ contains(github.event.pull_request.labels.*.name, 'bump-patch') }}; then
57+
elif [ "$HAS_BUMP_PATCH" = "true" ]; then
3658
echo "bump-type=patch" >> "$GITHUB_OUTPUT"
3759
echo "should-release=true" >> "$GITHUB_OUTPUT"
3860
else
@@ -191,8 +213,10 @@ jobs:
191213
id: check-rejection
192214
env:
193215
GH_TOKEN: ${{ github.token }}
216+
GITHUB_REPOSITORY_NAME: ${{ github.repository }}
217+
GITHUB_RUN_ID_VALUE: ${{ github.run_id }}
194218
run: |
195-
RESPONSE=$(gh api /repos/${{ github.repository }}/actions/runs/${{ github.run_id }}/approvals)
219+
RESPONSE=$(gh api "/repos/$GITHUB_REPOSITORY_NAME/actions/runs/$GITHUB_RUN_ID_VALUE/approvals")
196220
REJECTED=$(echo "$RESPONSE" | jq '[.[] | select(.state == "rejected")] | length')
197221
if [ "$REJECTED" -gt 0 ]; then
198222
echo "was_rejected=true" >> "$GITHUB_OUTPUT"

RELEASING.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
# Releasing
22

3-
Releases are driven by PR labels. When a PR with the right labels is merged to `main`, a GitHub Actions workflow handles version bumping, tagging, creating a GitHub Release (with auto-generated notes), and publishing to NuGet.
3+
Releases are usually driven by PR labels. When a PR with the right labels is merged to `main`, a GitHub Actions workflow handles version bumping, tagging, creating a GitHub Release (with auto-generated notes), and publishing to NuGet. You can also trigger the `Release` workflow manually from GitHub Actions and choose the bump type.
44

55
## Release Process
66

7-
1. Add the `release` label and exactly one of `bump-patch`, `bump-minor`, or `bump-major` to your PR
8-
2. Merge the PR to `main`
9-
3. Approve the release in the GitHub Environment gate (the workflow pauses for maintainer approval)
10-
4. The workflow bumps the version in `Directory.Build.props`, commits to `main`, creates a git tag, and creates a GitHub Release
11-
5. The GitHub Release triggers the [`main.yaml`](.github/workflows/main.yaml) workflow, which builds and publishes the packages to NuGet
7+
1. Either:
8+
- add the `release` label and exactly one of `bump-patch`, `bump-minor`, or `bump-major` to your PR, then merge it to `main`, or
9+
- open the `Release` workflow in GitHub Actions, click **Run workflow**, and choose `patch`, `minor`, or `major`
10+
2. Approve the release in the GitHub Environment gate (the workflow pauses for maintainer approval)
11+
3. The workflow bumps the version in `Directory.Build.props`, commits to `main`, creates a git tag, and creates a GitHub Release
12+
4. The GitHub Release triggers the [`main.yaml`](.github/workflows/main.yaml) workflow, which builds and publishes the packages to NuGet

0 commit comments

Comments
 (0)