Skip to content

Commit 2890767

Browse files
committed
ci: push auto-format commits via deploy key so CI re-runs
Switch the auto-format workflow to push over SSH using an AUTOFORMAT_DEPLOY_KEY deploy key instead of the default GITHUB_TOKEN. Pushes made with GITHUB_TOKEN never trigger workflows; a deploy-key push does, so the formatted commit now gets a full CI run. Add an if: guard so the workflow skips its own format commit (the deploy-key push re-triggers push), keeping it from waking itself on every fix. Drop GITHUB_TOKEN write permission since the push no longer uses it. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EGsDJWMXo8LTiQTKfvKhXN
1 parent 63259eb commit 2890767

1 file changed

Lines changed: 21 additions & 3 deletions

File tree

‎.github/workflows/auto-format.yml‎

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,17 @@ name: Auto-format
44
# the pushed branch and commits the result back. Prettier runs last so it tidies
55
# whatever ESLint rewrote; `eslint-config-prettier` means the two never fight.
66
#
7-
# The commit is pushed with the default GITHUB_TOKEN, which by design does NOT
8-
# re-trigger `push` workflows, so this can't loop on its own formatting commit.
7+
# The fix commit is pushed over SSH using the AUTOFORMAT_DEPLOY_KEY deploy key
8+
# (NOT the default GITHUB_TOKEN, whose pushes never trigger workflows). Pushing
9+
# with a deploy key DOES re-trigger CI, so the formatted commit gets a full CI
10+
# run — the whole point of using a key here. The `if:` guard below stops this
11+
# workflow from re-running on its own commit, and the `git diff --quiet` check
12+
# makes it a no-op even if it ever did.
13+
#
14+
# Setup (one-time, in repo settings):
15+
# ssh-keygen -t ed25519 -f autoformat_key -N ""
16+
# - Add autoformat_key.pub as a Deploy key WITH write access.
17+
# - Add autoformat_key (private) as an Actions secret AUTOFORMAT_DEPLOY_KEY.
918

1019
on:
1120
push:
@@ -15,7 +24,7 @@ on:
1524
workflow_dispatch:
1625

1726
permissions:
18-
contents: write
27+
contents: read # push happens over the deploy key, not GITHUB_TOKEN
1928

2029
# One in-flight run per branch; a newer push supersedes an older, half-finished
2130
# format so we never race two auto-format commits onto the same ref.
@@ -26,8 +35,17 @@ concurrency:
2635
jobs:
2736
format:
2837
runs-on: ubuntu-latest
38+
# Don't re-run on our own format commit — the deploy-key push re-triggers
39+
# `push`, so without this guard the workflow would wake itself once per fix
40+
# (harmless thanks to `git diff --quiet`, but a wasted run). workflow_dispatch
41+
# has no head_commit, so the guard passes and manual runs still work.
42+
if: "github.event_name == 'workflow_dispatch' || !startsWith(github.event.head_commit.message, 'style: apply eslint --fix and prettier')"
2943
steps:
3044
- uses: actions/checkout@v6.0.3
45+
with:
46+
# Check out over SSH with the deploy key so the later `git push` is
47+
# authenticated as the key (and therefore re-triggers CI).
48+
ssh-key: ${{ secrets.AUTOFORMAT_DEPLOY_KEY }}
3149

3250
- uses: actions/setup-node@v6
3351
with: { node-version: '22', cache: 'npm' }

0 commit comments

Comments
 (0)