ci: format code on pull requests and run only on PRs - #10
Merged
Conversation
The add-and-commit step failed with "fatal: You are not currently on a branch". actions/checkout defaults to a detached HEAD, and on pull_request it checks out the merge ref rather than the source branch, so there was nothing to push formatting fixes back to. Check the branch out by name with `ref: github.head_ref` so the step has a real branch, and grant the job `contents: write` so it can push. The step is guarded to pull_request, since workflow_dispatch has no head_ref. Also drops the push-to-main trigger so CI runs on pull requests only, and bumps actions/checkout to v4 (v3 runs on a Node version GitHub is deprecating). Verified locally: pub get, dart format (0 changed), analyze --fatal-infos, and all 132 tests pass.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The
EndBug/add-and-commitstep failed:actions/checkoutdefaults to a detached HEAD, and onpull_requestevents it checks out the merge ref rather than the PR's source branch. So there was no branch for the formatting commit to be pushed to.Fix
ref: ${{ github.head_ref }}so the commit step has a real branch to push topermissions: contents: writeso it is allowed to pushif: github.event_name == 'pull_request'—workflow_dispatchruns have nohead_refand nothing to push toactions/checkoutv3 → v4 (v3 runs on a Node version GitHub is deprecating)Formatting is still applied in place by
dart format .and committed back to the PR branch, so the package's style stays consistent automatically.Also: CI now runs on pull requests only
The push-to-
maintrigger is removed, as requested.Worth being explicit about the tradeoff, since it is exactly how the bug in #9 shipped:
c915fe5("chore: update project dependencies") was pushed straight tomain, so CI never ran on it — even though the existing round-trip tests would have caught the regression immediately. With PR-only triggers that gap remains open unlessmainis protected.Recommended: enable a branch protection rule on
mainrequiring a PR and a passing[CI]check. That gets the same guarantee without running CI on pushes.Verified locally