Skip to content

Commit c42f0a9

Browse files
authored
chore: avoid auto-formatter workflow failing on fork PRs (#4600)
It bothered me that every PR from a fork always had a red check from the autoformatter PR. This sets up the autoformatter to only run on PRs from non-forks, and adds a new `fmt:check` step to the tests workflow that will work even in forks. This lets our team still use the autoformatter without causing noise for external contributors, and also enforces our formatting requirements for PRs from forks where previously we would typically admin-merge past the check (which causes noise like #4599). Once this PR merges, we'll want to update the repo's branch protection rules to add the new fmt-check job as a required check. --------- Co-authored-by: dbjorge <[email protected]>
1 parent 0d03b0a commit c42f0a9

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

.github/workflows/format.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
11
name: Formatter
22

3-
on: [pull_request]
3+
on:
4+
pull_request:
5+
branches:
6+
- develop
47

58
jobs:
69
prettier:
10+
# This conditional prevents running the job on PRs from forks; won't
11+
# have permissions to commit changes, so the job would fail if it ran.
12+
# PRs from forks will instead rely on failing the fmt_check job in test.yml
13+
if: github.event.pull_request.head.repo.full_name == github.repository
714
runs-on: ubuntu-latest
15+
timeout-minutes: 5
816
steps:
917
- uses: actions/checkout@v4
1018
with:

.github/workflows/test.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,18 @@ jobs:
2626
path: axe.js
2727
retention-days: 1
2828

29+
fmt_check:
30+
runs-on: ubuntu-latest
31+
timeout-minutes: 5
32+
steps:
33+
- uses: actions/checkout@v4
34+
- uses: actions/setup-node@v4
35+
with:
36+
node-version: 20
37+
cache: 'npm'
38+
- run: npm ci
39+
- run: npm run fmt:check
40+
2941
test_node:
3042
strategy:
3143
matrix:

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@
112112
"sri-update": "grunt build && node build/sri-update && git add sri-history.json",
113113
"sri-validate": "node build/sri-update --validate",
114114
"fmt": "prettier --write .",
115+
"fmt:check": "prettier --check .",
115116
"prepare": "husky && npm run patch",
116117
"prebuild": "node ./build/check-node-version.js",
117118
"pretest": "node ./build/check-node-version.js",

0 commit comments

Comments
 (0)