Skip to content

ci: format code on pull requests and run only on PRs - #10

Merged
JTorkk merged 2 commits into
mainfrom
ci/format-on-pr
Aug 24, 2026
Merged

ci: format code on pull requests and run only on PRs#10
JTorkk merged 2 commits into
mainfrom
ci/format-on-pr

Conversation

@JTorkk

@JTorkk JTorkk commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

Problem

The EndBug/add-and-commit step failed:

Error: fatal: You are not currently on a branch.
To push the history leading to the current (detached HEAD) state now, use
    git push origin HEAD:<name-of-remote-branch>

actions/checkout defaults to a detached HEAD, and on pull_request events 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

  • Check the branch out by name with ref: ${{ github.head_ref }} so the commit step has a real branch to push to
  • Grant the job permissions: contents: write so it is allowed to push
  • Guard the commit step with if: github.event_name == 'pull_request'workflow_dispatch runs have no head_ref and nothing to push to
  • Bump actions/checkout v3 → 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-main trigger 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 to main, 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 unless main is protected.

Recommended: enable a branch protection rule on main requiring a PR and a passing [CI] check. That gets the same guarantee without running CI on pushes.

Verified locally

flutter pub get                     OK
dart format .                       Formatted 47 files (0 changed)
flutter analyze . --fatal-infos     No issues found!
flutter test --no-pub               +132: All tests passed!

JTorkk and others added 2 commits August 24, 2026 22:49
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.
@JTorkk
JTorkk merged commit 2d93ff3 into main Aug 24, 2026
1 check passed
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