Skip to content

Commit 7eb10e8

Browse files
committed
feat: cancel run when no changes detected
1 parent 8d1a04a commit 7eb10e8

3 files changed

Lines changed: 25 additions & 7 deletions

File tree

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ jobs:
100100
| `publish_npm` | Whether to publish to npm registry | No | `true` |
101101
| `publish_github_packages` | Whether to publish to GitHub Packages | No | `true` |
102102
| `skip_if_unchanged` | Skip version bump/publish if the local npm tarball matches the latest published tarball (ignoring version/gitHead) | No | `false` |
103-
| `neutral_on_no_changes` | Mark workflow as neutral (exit 78) when no changes are detected | No | `false` |
103+
| `neutral_on_no_changes` | Stop early without failing when no changes are detected | No | `false` |
104+
| `cancel_on_no_changes` | Cancel the workflow run when no changes are detected (requires `actions: write`) | No | `false` |
104105
| `npm_token` | NPM authentication token | No (required if `publish_npm` is true) | - |
105106
| `github_token` | GitHub token for releases and packages | Yes | - |
106107

SETUP.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ permissions:
9696
### Optional Behavior
9797

9898
- `skip_if_unchanged` - When enabled, the action compares the local npm tarball with the latest published tarball (ignoring version/gitHead) and skips the release if identical. For private npm packages, provide `NPM_TOKEN` so the comparison can fetch the published tarball.
99-
- `neutral_on_no_changes` - When enabled, the action exits with code 78 (neutral/gray) if no changes are detected.
99+
- `neutral_on_no_changes` - When enabled, the action stops early without failing if no changes are detected.
100+
- `cancel_on_no_changes` - When enabled, the action cancels the workflow run (requires `actions: write` permission).
100101

101102
### Action Permissions Policy
102103

action.yml

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,11 @@ inputs:
5555
required: false
5656
default: "false"
5757
neutral_on_no_changes:
58-
description: "Mark workflow as neutral (exit 78) when no changes are detected"
58+
description: "Do not fail the workflow when no changes are detected"
59+
required: false
60+
default: "false"
61+
cancel_on_no_changes:
62+
description: "Cancel the workflow run when no changes are detected (requires actions: write)"
5963
required: false
6064
default: "false"
6165
npm_token:
@@ -180,13 +184,25 @@ runs:
180184
git stash drop >/dev/null 2>&1 || true
181185
fi
182186
183-
- name: Stop with neutral status on no changes
184-
if: inputs.neutral_on_no_changes == 'true' && steps.compare_npm.outputs.should_release == 'false'
187+
- name: Handle no changes conclusion
188+
if: steps.compare_npm.outputs.should_release == 'false'
185189
shell: bash
186190
run: |
187191
set -euo pipefail
188-
echo "::notice::No changes detected; marking workflow neutral."
189-
exit 78
192+
193+
if [ "${{ inputs.cancel_on_no_changes }}" = "true" ]; then
194+
echo "::notice::No changes detected; canceling workflow run."
195+
curl -sS -X POST \
196+
-H "Authorization: Bearer ${{ inputs.github_token }}" \
197+
-H "Accept: application/vnd.github+json" \
198+
"https://api.github.com/repos/${{ github.repository }}/actions/runs/${{ github.run_id }}/cancel" >/dev/null
199+
exit 0
200+
fi
201+
202+
if [ "${{ inputs.neutral_on_no_changes }}" = "true" ]; then
203+
echo "::notice::No changes detected; stopping early."
204+
exit 0
205+
fi
190206
191207
- name: Auto changeset (patch if no changeset exists)
192208
id: auto_changeset

0 commit comments

Comments
 (0)