Skip to content

Commit 741cb6b

Browse files
committed
Refine check-no-persist-credentials CI job
This also tests the job by manually trying out several ways it should fail to make sure it does, but I squashed those out. The can be seen at EliahKagan#105 and are summarized as follows: * Test that we always have `actions/checkout` not persist credentials * Check that we catch `actions/checkout` with no `with` * Improve `check-no-persist-credentials` output and maintainability * Check that we catch checkout `with` without `persist-credentials` * Check that we catch `persist-credentials` not set to boolean false * Having tested the new check, restore `persist-credentials: false`
1 parent a235ac8 commit 741cb6b

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

.github/workflows/ci.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,33 @@ jobs:
561561
git status
562562
git diff --exit-code
563563
564+
# Check that all `actions/checkout` in CI jobs have `persist-credentials: false`.
565+
check-no-persist-credentials:
566+
runs-on: ubuntu-latest
567+
568+
env:
569+
GLOB: .github/workflows/*.@(yaml|yml)
570+
571+
steps:
572+
- uses: actions/checkout@v5
573+
with:
574+
persist-credentials: false
575+
sparse-checkout: '.github/workflows'
576+
- name: List workflows to be scanned
577+
run: |
578+
shopt -s extglob
579+
printf '%s\n' ${{ env.GLOB }}
580+
- name: Scan workflows
581+
run: |
582+
shopt -s extglob
583+
yq '.jobs.*.steps[]
584+
| select(.uses == "actions/checkout@*" and .with.["persist-credentials"]? != false)
585+
| {"file": filename, "line": line, "name": (.name // .uses)}
586+
| .file + ":" + (.line | tostring) + ": " + .name
587+
' -- ${{ env.GLOB }} >query-output.txt
588+
cat query-output.txt
589+
test -z "$(<query-output.txt)" # Report failure if we found anything.
590+
564591
# Check that only jobs intended not to block PR auto-merge are omitted as
565592
# dependencies of the `tests-pass` job below, so that whenever a job is
566593
# added, a decision is made about whether it must pass for PRs to merge.
@@ -615,6 +642,7 @@ jobs:
615642
- lint
616643
- cargo-deny
617644
- check-packetline
645+
- check-no-persist-credentials
618646
- check-blocking
619647

620648
if: always() # Always run even if dependencies fail.

0 commit comments

Comments
 (0)