11name : Repo Hygiene
22
33on :
4+ pull_request_target :
5+ branches : [main]
6+ types : [opened, synchronize, reopened]
47 pull_request :
58 branches : [main]
69 push :
@@ -12,66 +15,73 @@ permissions:
1215jobs :
1316 repo-hygiene :
1417 runs-on : ubuntu-latest
18+ if : github.event_name == 'pull_request_target' || github.event_name == 'push'
1519 steps :
16- - name : Check PR author account age
17- if : github.event_name == 'pull_request'
18- uses : actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b # v7
19- env :
20- PR_AUTHOR_MINIMUM_AGE_DAYS : ${{ vars.PR_AUTHOR_MINIMUM_AGE_DAYS || '30' }}
21- PR_AUTHOR_AGE_ALLOWLIST : ${{ vars.PR_AUTHOR_AGE_ALLOWLIST }}
20+ - uses : actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4
2221 with :
23- script : |
24- const username = context.payload.pull_request.user.login;
25- const allowlist = (process.env.PR_AUTHOR_AGE_ALLOWLIST || "PatrickJS,dependabot[bot],Copilot")
26- .split(",")
27- .map((entry) => entry.trim().toLowerCase())
28- .filter(Boolean);
29-
30- if (allowlist.includes(username.toLowerCase())) {
31- core.info(`PR author account age check passed: ${username} is allowlisted.`);
32- return;
33- }
34-
35- const minimumAgeDays = Number.parseInt(process.env.PR_AUTHOR_MINIMUM_AGE_DAYS, 10);
36- if (!Number.isInteger(minimumAgeDays) || minimumAgeDays < 0) {
37- core.setFailed(`Invalid PR_AUTHOR_MINIMUM_AGE_DAYS: ${process.env.PR_AUTHOR_MINIMUM_AGE_DAYS}`);
38- return;
39- }
40-
41- const { data: user } = await github.rest.users.getByUsername({ username });
42- const createdTime = Date.parse(user.created_at);
43- const ageDays = Math.floor((Date.now() - createdTime) / 86400000);
44-
45- if (ageDays < minimumAgeDays) {
46- core.setFailed(
47- `PR author account is too new: ${username} is ${ageDays} day(s) old; minimum is ${minimumAgeDays} day(s).`,
48- );
49- return;
50- }
51-
52- core.info(
53- `PR author account age check passed: ${username} is ${ageDays} day(s) old; minimum is ${minimumAgeDays} day(s).`,
54- );
22+ node-version : 20
5523
56- - uses : actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
24+ - name : Checkout trusted base checks
25+ if : github.event_name == 'pull_request_target'
26+ uses : actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
5727 with :
28+ ref : ${{ github.event.pull_request.base.ref }}
29+ path : .trusted-base
5830 fetch-depth : 0
31+ persist-credentials : false
5932
60- - uses : actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4
33+ - name : Check PR author account age
34+ if : github.event_name == 'pull_request_target'
35+ env :
36+ GITHUB_TOKEN : ${{ github.token }}
37+ PR_AUTHOR : ${{ github.event.pull_request.user.login }}
38+ PR_AUTHOR_MINIMUM_AGE_DAYS : ${{ vars.PR_AUTHOR_MINIMUM_AGE_DAYS || '30' }}
39+ PR_AUTHOR_AGE_ALLOWLIST : ${{ vars.PR_AUTHOR_AGE_ALLOWLIST || 'PatrickJS,dependabot[bot],Copilot' }}
40+ run : |
41+ node .trusted-base/scripts/check-pr-author.mjs \
42+ --username "$PR_AUTHOR" \
43+ --minimum-age-days "$PR_AUTHOR_MINIMUM_AGE_DAYS" \
44+ --allowlist "$PR_AUTHOR_AGE_ALLOWLIST"
45+
46+ - name : Checkout pull request content
47+ if : github.event_name == 'pull_request_target'
48+ uses : actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
6149 with :
62- node-version : 20
50+ repository : ${{ github.event.pull_request.head.repo.full_name }}
51+ ref : ${{ github.event.pull_request.head.sha }}
52+ path : pr
53+ fetch-depth : 0
54+ persist-credentials : false
6355
64- - name : Enable pnpm
56+ - name : Determine pull request changed files
57+ if : github.event_name == 'pull_request_target'
58+ shell : bash
59+ env :
60+ BASE_REF : ${{ github.event.pull_request.base.ref }}
6561 run : |
66- corepack enable
67- corepack prepare pnpm@10.20.0 --activate
62+ git -C pr remote add trusted-base "$GITHUB_SERVER_URL/${{ github.repository }}.git"
63+ git -C pr fetch --no-tags trusted-base "$BASE_REF"
64+ base="$(git -C pr rev-parse FETCH_HEAD)"
65+
66+ git -C pr diff --name-only "$base"...HEAD > pr/.changed-files
67+ git -C pr diff --unified=0 "$base"...HEAD -- README.md > pr/.readme.diff || true
68+
69+ - name : Run trusted repo hygiene checks
70+ if : github.event_name == 'pull_request_target'
71+ run : node .trusted-base/scripts/check-repo-hygiene.mjs --root "$GITHUB_WORKSPACE/pr" --changed-files .changed-files --diff-file .readme.diff
6872
69- - name : Determine changed files
73+ - name : Checkout push content
74+ if : github.event_name == 'push'
75+ uses : actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
76+ with :
77+ fetch-depth : 0
78+ persist-credentials : false
79+
80+ - name : Determine push changed files
81+ if : github.event_name == 'push'
7082 shell : bash
7183 run : |
72- if [[ "${{ github.event_name }}" == "pull_request" ]]; then
73- base="${{ github.event.pull_request.base.sha }}"
74- elif [[ -n "${{ github.event.before }}" && "${{ github.event.before }}" != "0000000000000000000000000000000000000000" ]]; then
84+ if [[ -n "${{ github.event.before }}" && "${{ github.event.before }}" != "0000000000000000000000000000000000000000" ]]; then
7585 base="${{ github.event.before }}"
7686 else
7787 base="$(git rev-list --max-parents=0 HEAD)"
@@ -80,25 +90,14 @@ jobs:
8090 git diff --name-only "$base"...HEAD > .changed-files
8191 git diff --unified=0 "$base"...HEAD -- README.md > .readme.diff || true
8292
83- - name : Checkout trusted base checks
84- if : github.event_name == 'pull_request'
85- uses : actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
86- with :
87- ref : ${{ github.event.pull_request.base.sha }}
88- path : .trusted-base
89- fetch-depth : 1
90-
91- - name : Run trusted repo hygiene checks
92- if : github.event_name == 'pull_request'
93- run : node .trusted-base/scripts/check-repo-hygiene.mjs --root "$GITHUB_WORKSPACE" --changed-files .changed-files --diff-file .readme.diff
94-
9593 - name : Run repo hygiene checks
96- if : github.event_name != 'pull_request '
94+ if : github.event_name == 'push '
9795 run : node scripts/check-repo-hygiene.mjs --changed-files .changed-files --diff-file .readme.diff
9896
9997 awesome-lint :
10098 name : awesome-lint
10199 runs-on : ubuntu-latest
100+ if : github.event_name != 'pull_request_target'
102101 steps :
103102 - uses : actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
104103 with :
0 commit comments