Skip to content

docs(examples): gracefully handle no bump-eligible commits#17

Open
bearomorphism wants to merge 3 commits intocommitizen-tools:mainfrom
bearomorphism:docs/graceful-no-bump-examples
Open

docs(examples): gracefully handle no bump-eligible commits#17
bearomorphism wants to merge 3 commits intocommitizen-tools:mainfrom
bearomorphism:docs/graceful-no-bump-examples

Conversation

@bearomorphism
Copy link
Copy Markdown
Collaborator

@bearomorphism bearomorphism commented May 8, 2026

Description

This PR contains two related changes that together fix two distinct CI papercuts uncovered by commitizen-tools/commitizen#1950 (suggested in this comment).


1. docs(examples): gracefully handle no bump-eligible commits

When users copy-paste these example workflows and only push commits that do not trigger a version bump (e.g. docs:, ci:, build(deps):), cz bump --yes exits with code 21 (NO_COMMITS_TO_BUMP), which causes the entire workflow to fail.

This commit updates both examples/bump-release.yaml and examples/trigger-other-job/.github/workflows/bump-release.yaml so that:

  • The bump step passes --no-raise 21 to cz bump to avoid hard-failing on the no-commits case.
  • It compares HEAD before and after the bump; if unchanged, it logs a message, sets bumped=false and exits 0.
  • The subsequent Build changelog, Release and trigger other workflow steps are guarded by steps.bump-version.outputs.bumped == 'true' so they are skipped on no-op runs.

This mirrors the same pattern that commitizen itself adopted in its own bumpversion workflow.

2. ci(test): skip test-trigger-other-job when token is read-only

The test-trigger-other-job job in .github/workflows/test.yaml runs gh workflow run, which requires actions: write on the GITHUB_TOKEN. This call fails with HTTP 403 (Resource not accessible by integration) in two cases where the token is read-only:

  • Fork PRs — fork-originated PRs always get a read-only GITHUB_TOKEN for security.
  • Dependabot PRs — even though the branch is in the same repo, the dependabot[bot] actor receives a restricted token by default.

Examples of the resulting failures:

This commit guards the job with:

if: >-
  github.event.pull_request.head.repo.full_name == github.repository &&
  github.actor != 'dependabot[bot]'

The job continues to run on PRs from same-repo branches authored by humans, where the token has the right permissions.

Why not other approaches?

  • pull_request_target would give fork PRs a writeable token — major security risk, not appropriate here.
  • continue-on-error: true on the trigger step would hide real failures, making the test meaningless.
  • A workflow-level permissions: { actions: write } block does not help: fork and dependabot tokens stay read-only regardless.

Checklist

  • I have read the contributing guidelines

Was generative AI tooling used to co-author this PR?

  • Yes (please specify the tool below)

Generated-by: GitHub Copilot

Expected Behavior

  • Users who copy-paste the example workflows now get one that succeeds gracefully when only non-bump-eligible commits are pushed.
  • Fork PRs and dependabot PRs no longer have a permanently failing test-trigger-other-job check; same-repo human PRs and pushes to main retain full coverage.

Update both bump-release.yaml examples so that pushing only commits
which do not trigger a version bump (e.g. docs:, ci:, build(deps):)
does not fail the workflow with exit code 21.

The bump step now passes `--no-raise 21` to cz bump and detects
whether HEAD changed; if not, it sets `bumped=false` and exits 0.
Subsequent steps (changelog, release, trigger-other-workflow) are
guarded by `steps.bump-version.outputs.bumped == 'true'` so they
are skipped on no-op runs.

This mirrors the same pattern already used in commitizen's own
bumpversion.yml workflow (see commitizen-tools/commitizen#1950).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@bearomorphism bearomorphism marked this pull request as draft May 8, 2026 08:27
@bearomorphism
Copy link
Copy Markdown
Collaborator Author

draft this and will do a human review later

The test-trigger-other-job job runs `gh workflow run`, which requires
`actions: write` on the GITHUB_TOKEN. The job has been failing on:

  - Fork PRs (e.g. contributor PRs from forks): fork-originated PRs
    always receive a read-only GITHUB_TOKEN.
  - Dependabot PRs (e.g. commitizen-tools#15): even though dependabot creates branches
    in the same repo, the dependabot[bot] actor receives a restricted
    token by default.

Both produce:

    could not create workflow dispatch event: HTTP 403:
    Resource not accessible by integration

Skip this job in both cases by gating on `head.repo.full_name` and on
`github.actor`. The job continues to run on PRs from same-repo
branches authored by humans, where the token has the required
permissions.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@bearomorphism bearomorphism changed the title docs(examples): gracefully handle no bump-eligible commits docs(examples): gracefully handle no bump-eligible commits + ci test fix May 9, 2026
@bearomorphism bearomorphism marked this pull request as ready for review May 9, 2026 05:34
@bearomorphism bearomorphism changed the title docs(examples): gracefully handle no bump-eligible commits + ci test fix docs(examples): gracefully handle no bump-eligible commits May 9, 2026
`--no-raise` is a top-level commitizen option, so it must appear
before the `bump` subcommand. With it placed after, argparse treats
`--no-raise 21` as unknown trailing arguments and the CLI exits with
code 18 (`INVALID_COMMAND_ARGUMENT`):

    Invalid commitizen arguments were found: `--no-raise`.
    Please use -- separator for extra git args

This is what failed the bump workflow on commitizen-tools/commitizen
master in run 25542335831, which copy-pasted the same pattern from
these examples.

Move the option before `bump` in both examples and add a comment so
future readers do not repeat the mistake.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant