Skip to content

ci(auto-format): run the format step through the steps script - #496

Merged
Vivswan merged 1 commit into
mainfrom
ci/auto-format-step-script
Oct 6, 2026
Merged

Vivswan merged 1 commit into
mainfrom
ci/auto-format-step-script

Conversation

@Vivswan

@Vivswan Vivswan commented Oct 6, 2026 •

Copy link
Copy Markdown
Owner

Before

      - name: Format (biome) and stage the patch
        id: format
        run: |
          # The patch belongs to this commit alone; the push job refuses any other head.
          echo "head=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT"
          bun run lint:fix
          # Anything the formatter left staged is not this workflow's fix: start from an empty index, then stage
          # modifications and deletions of tracked files alone (a formatter adds nothing).
          git reset -q
          git add -u
          git diff --cached --binary > "$RUNNER_TEMP/format.patch"
          if [ -s "$RUNNER_TEMP/format.patch" ]; then
            git diff --cached --stat
            echo "changed=true" >> "$GITHUB_OUTPUT"
          else
            echo "nothing to format"
            echo "changed=false" >> "$GITHUB_OUTPUT"
          fi

After

      - name: Format (biome) and stage the patch
        id: format
        run: bun .github/scripts/auto-format-steps.ts format

How

  • The block is the format subcommand of auto-format-steps.ts: the same commands, outputs, log line, and patch file.
  • One deviation on a runner: a failed git rev-parse HEAD ends the step with git's status, where the shell wrote an empty head=.
  • Two more only off a runner: an unset RUNNER_TEMP ends the step before any patch, and a patch file removed under the step ends it instead of reading changed=false.
  • Library: biome confines @actions/core to src/action/ and the push job that runs this file installs nothing, so the repo's helpers stay.

Proof

  • Tests: bun test test/scripts/auto-format-steps.test.ts test/workflows/repo-owned-workflows.test.ts 16 pass (3 new, red before the subcommand existed).
  • Census: grep -c 'run: |' .github/workflows/auto-format.yml 1 before, 0 after.
  • Gates: typecheck, biome, actionlint clean. Codex review converged.
Technical details
  • The new tests pin git's staging semantics and bun's exit propagation: what reset -q plus add -u admits to the patch (modifications and deletions of tracked files, never an addition, staged earlier or made by the formatter), and that a failing formatter stops the step after head= with the formatter's status and no patch file.
  • The format job runs this file from the PR branch's checkout, as it ran the shell block: that job holds no write token, and the push job still runs its copy from the default branch.
  • Line accounting (git diff --numstat origin/main...HEAD): script +29/-6, workflow +1/-16, test +65/-2.
  • Files: .github/scripts/auto-format-steps.ts, .github/workflows/auto-format.yml, test/scripts/auto-format-steps.test.ts.

Copilot AI balanced review requested due to automatic review settings October 6, 2026 10:15

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The focused refactor preserves existing behavior and includes coverage for its key paths.

Review effort: Balanced
Findings: None

What changed in this PR

Moves auto-format workflow logic into the shared step script while preserving patch and output behavior.

Changes:

  • Adds the format script subcommand.
  • Simplifies the workflow step.
  • Tests staging, no-op, and failure behavior.
File Description
.github/​scripts/​auto-format-steps.ts Implements the format subcommand.
.github/​workflows/​auto-format.yml Invokes the new subcommand.
test/​scripts/​auto-format-steps.test.ts Covers format-step behavior.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The extracted behavior matches the workflow logic and is covered by focused tests.

Review effort: Balanced
Findings: None

The format job's one multi-line run step moves into auto-format-steps.ts as the format subcommand, beside push: the same commands, GITHUB_OUTPUT lines, log line, and patch file. On a runner, one difference: a failed git rev-parse HEAD ends the step with git's status, where the shell wrote an empty head= and went on. Off a runner, two more: an unset RUNNER_TEMP ends the step before any patch is written, and a patch file removed under the step ends it rather than reading as changed=false.
Copilot AI balanced review requested due to automatic review settings October 6, 2026 10:34
@Vivswan
Vivswan force-pushed the ci/auto-format-step-script branch from c04c21d to f12437d Compare October 6, 2026 10:34

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The refactor preserves the workflow semantics and has focused coverage for success and failure paths.

Review effort: Balanced
Findings: None

@Vivswan
Vivswan marked this pull request as ready for review October 6, 2026 10:53
@Vivswan
Vivswan merged commit 827c7c8 into main Oct 6, 2026
29 checks passed
@Vivswan Vivswan added the merge-when-green Owner approved: merge once every gate is green label Oct 6, 2026
@Vivswan
Vivswan deleted the ci/auto-format-step-script branch October 6, 2026 20:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-when-green Owner approved: merge once every gate is green

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants