Skip to content

Commit 8808211

Browse files
committed
Build/Test Tools: Address some issues in GitHub Actions workflow files as reported by Zizmor.
This removes unnecessarily broad inheritance of secrets, replaces some GitHub Actions expressions with environment variables, removes git credential persistence, and adds documentation to the readme. See #64227 git-svn-id: https://develop.svn.wordpress.org/trunk@62251 602fd350-edb4-49c9-b593-d223f7449a82
1 parent ee81e2f commit 8808211

7 files changed

Lines changed: 52 additions & 24 deletions

.github/workflows/commit-built-file-changes.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,12 @@ jobs:
131131
path: 'pr-repo'
132132
show-progress: ${{ runner.debug == '1' && 'true' || 'false' }}
133133
token: ${{ env.ACCESS_TOKEN }}
134+
persist-credentials: true
134135

135136
- name: Apply patch
136137
if: ${{ steps.artifact-check.outputs.exists == 'true' }}
137138
working-directory: 'pr-repo'
138-
run: git apply ${{ github.workspace }}/changes.diff
139+
run: git apply "$GITHUB_WORKSPACE/changes.diff"
139140

140141
- name: Display changes to versioned files
141142
if: ${{ steps.artifact-check.outputs.exists == 'true' }}
@@ -149,7 +150,7 @@ jobs:
149150
GH_APP_ID: ${{ secrets.GH_PR_BUILT_FILES_APP_ID }}
150151
run: |
151152
git config user.name "wordpress-develop-pr-bot[bot]"
152-
git config user.email ${{ env.GH_APP_ID }}+wordpress-develop-pr-bot[bot]@users.noreply.github.com
153+
git config user.email "${GH_APP_ID}+wordpress-develop-pr-bot[bot]@users.noreply.github.com"
153154
154155
- name: Stage changes
155156
if: ${{ steps.artifact-check.outputs.exists == 'true' }}

.github/workflows/install-testing.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ jobs:
4949
uses: ./.github/workflows/reusable-support-json-reader-v1.yml
5050
permissions:
5151
contents: read
52-
secrets: inherit
5352
if: ${{ github.repository == 'WordPress/wordpress-develop' }}
5453
with:
5554
wp-version: ${{ inputs.wp-version }}

.github/workflows/local-docker-environment.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ jobs:
7979
uses: ./.github/workflows/reusable-support-json-reader-v1.yml
8080
permissions:
8181
contents: read
82-
secrets: inherit
8382
if: ${{ github.repository == 'WordPress/wordpress-develop' }}
8483
with:
8584
wp-version: ${{ github.event_name == 'pull_request' && github.base_ref || github.ref_name }}

.github/workflows/phpunit-tests.yml

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ jobs:
6666
uses: ./.github/workflows/reusable-phpunit-tests-v3.yml
6767
permissions:
6868
contents: read
69-
secrets: inherit
69+
secrets:
70+
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
71+
WPT_REPORT_API_KEY: ${{ secrets.WPT_REPORT_API_KEY }}
7072
if: ${{ startsWith( github.repository, 'WordPress/' ) && ( github.repository == 'WordPress/wordpress-develop' || github.event_name == 'pull_request' ) }}
7173
strategy:
7274
fail-fast: false
@@ -143,7 +145,9 @@ jobs:
143145
uses: ./.github/workflows/reusable-phpunit-tests-v3.yml
144146
permissions:
145147
contents: read
146-
secrets: inherit
148+
secrets:
149+
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
150+
WPT_REPORT_API_KEY: ${{ secrets.WPT_REPORT_API_KEY }}
147151
if: ${{ startsWith( github.repository, 'WordPress/' ) && ( github.repository == 'WordPress/wordpress-develop' || github.event_name == 'pull_request' ) }}
148152
strategy:
149153
fail-fast: false
@@ -195,7 +199,9 @@ jobs:
195199
uses: ./.github/workflows/reusable-phpunit-tests-v3.yml
196200
permissions:
197201
contents: read
198-
secrets: inherit
202+
secrets:
203+
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
204+
WPT_REPORT_API_KEY: ${{ secrets.WPT_REPORT_API_KEY }}
199205
if: ${{ startsWith( github.repository, 'WordPress/' ) && ( github.repository == 'WordPress/wordpress-develop' || github.event_name == 'pull_request' ) }}
200206
strategy:
201207
fail-fast: false
@@ -238,7 +244,9 @@ jobs:
238244
uses: ./.github/workflows/reusable-phpunit-tests-v3.yml
239245
permissions:
240246
contents: read
241-
secrets: inherit
247+
secrets:
248+
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
249+
WPT_REPORT_API_KEY: ${{ secrets.WPT_REPORT_API_KEY }}
242250
if: ${{ startsWith( github.repository, 'WordPress/' ) && ( github.repository == 'WordPress/wordpress-develop' || github.event_name == 'pull_request' ) }}
243251
strategy:
244252
fail-fast: false
@@ -267,7 +275,9 @@ jobs:
267275
uses: ./.github/workflows/reusable-phpunit-tests-v3.yml
268276
permissions:
269277
contents: read
270-
secrets: inherit
278+
secrets:
279+
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
280+
WPT_REPORT_API_KEY: ${{ secrets.WPT_REPORT_API_KEY }}
271281
if: ${{ ! startsWith( github.repository, 'WordPress/' ) && github.event_name == 'pull_request' }}
272282
strategy:
273283
fail-fast: false

.github/workflows/reusable-check-built-files.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ jobs:
4040
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
4141
with:
4242
show-progress: ${{ runner.debug == '1' && 'true' || 'false' }}
43+
persist-credentials: false
4344

4445
- name: Set up Node.js
4546
uses: actions/setup-node@53b83947a5a98c8d113130e565377fae1a50d02f # v6.3.0

.github/workflows/reusable-cleanup-pull-requests.yml

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
# - Parse fixed ticket numbers from the commit message.
2020
# - Parse the SVN revision from the commit message.
2121
# - Searches for pull requests referencing any fixed tickets.
22-
# - Leaves a comment on each PR before closing.
22+
# - Comments on pull requests referencing any fixed tickets before closing.
2323
close-prs:
2424
name: Find and close PRs
2525
runs-on: ubuntu-24.04
@@ -43,13 +43,17 @@ jobs:
4343
COMMIT_MESSAGE="$(echo "$COMMIT_MSG_RAW" | sed -n '$p')"
4444
echo "svn_revision_number=$(echo "$COMMIT_MESSAGE" | sed -n 's/.*git-svn-id: https:\/\/develop.svn.wordpress.org\/[^@]*@\([0-9]*\) .*/\1/p')" >> "$GITHUB_OUTPUT"
4545
46-
- name: Find pull requests
47-
id: linked-prs
46+
- name: Find, comment on, and close pull requests
4847
if: ${{ steps.trac-tickets.outputs.fixed_list != '' && steps.git-svn-id.outputs.svn_revision_number != '' }}
4948
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
49+
env:
50+
FIXED_LIST: ${{ steps.trac-tickets.outputs.fixed_list }}
51+
SVN_REVISION_NUMBER: ${{ steps.git-svn-id.outputs.svn_revision_number }}
5052
with:
5153
script: |
52-
const fixedList = "${{ steps.trac-tickets.outputs.fixed_list }}".split(' ').filter(Boolean);
54+
const fixedList = process.env.FIXED_LIST.split(' ').filter(Boolean);
55+
const svnRevisionNumber = process.env.SVN_REVISION_NUMBER;
56+
const githubSha = process.env.GITHUB_SHA;
5357
let prNumbers = [];
5458
5559
for (const ticket of fixedList) {
@@ -86,19 +90,10 @@ jobs:
8690
prNumbers.push(...matchingPRs);
8791
}
8892
89-
return prNumbers;
90-
91-
- name: Comment and close pull requests
92-
if: ${{ steps.trac-tickets.outputs.fixed_list != '' && steps.git-svn-id.outputs.svn_revision_number != '' }}
93-
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
94-
with:
95-
script: |
96-
const prNumbers = ${{ steps.linked-prs.outputs.result }};
97-
9893
const commentBody = `A commit was made that fixes the Trac ticket referenced in the description of this pull request.
9994
100-
SVN changeset: [${{ steps.git-svn-id.outputs.svn_revision_number }}](https://core.trac.wordpress.org/changeset/${{ steps.git-svn-id.outputs.svn_revision_number }})
101-
GitHub commit: https://github.com/WordPress/wordpress-develop/commit/${{ github.sha }}
95+
SVN changeset: [${svnRevisionNumber}](https://core.trac.wordpress.org/changeset/${svnRevisionNumber})
96+
GitHub commit: https://github.com/WordPress/wordpress-develop/commit/${githubSha}
10297
10398
This PR will be closed, but please confirm the accuracy of this and reopen if there is more work to be done.`;
10499

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,29 @@ npm run test:php -- --filter <test name>
9797
npm run test:php -- --group <group name or ticket number>
9898
```
9999

100+
#### To lint the workflow files
101+
102+
GitHub Actions workflows operate in a privileged software supply chain environment, therefore all workflow files must adhere to a high degree of quality and security standards.
103+
104+
All YAML workflow files within the `.github/workflows` directory are statically scanned when modified using [Actionlint](https://github.com/rhysd/actionlint) and [Zizmor](https://github.com/zizmorcore/zizmor). It's recommended that you install both of these tools locally using a package manager to run prior to submitting changes to workflow files.
105+
106+
- [Actionlint installations instructions](https://github.com/rhysd/actionlint/blob/main/docs/install.md)
107+
- [Zizmor installation instructions](https://docs.zizmor.sh/installation/)
108+
109+
To run Actionlint:
110+
111+
```
112+
actionlint
113+
```
114+
115+
To run Zizmor for all workflow files (note the trailing period):
116+
117+
```
118+
zizmor .
119+
```
120+
121+
**Note:** A workflow run failure will not occur when issues are detected by Zizmor. Instead, the generated report is submitted to GitHub Code Scanning and surfaced through a status check. Some locally reported issues may be ignored based on the repository's configured Code Scanning settings.
122+
100123
#### Generating a code coverage report
101124
PHP code coverage reports are [generated daily](https://github.com/WordPress/wordpress-develop/actions/workflows/test-coverage.yml) and [submitted to Codecov.io](https://app.codecov.io/gh/WordPress/wordpress-develop).
102125

0 commit comments

Comments
 (0)