@@ -44,34 +44,35 @@ jobs:
4444 toolchain : stable
4545 components : rustfmt
4646
47- - uses : swatinem/rust-cache@98c8021b550208e191a6a3145459bfc9fb29c4c0 # v2.8.0
48-
4947 - name : Run rustfmt
5048 run : cargo fmt -- --check
5149
5250 clippy :
5351 name : Run clippy on the minimum supported toolchain
5452 runs-on : ubuntu-latest
53+ # reduce job-level privileges so this job can run for forked PRs without requiring maintainer approval
5554 permissions :
5655 contents : read
57- security-events : write
5856 steps :
59-
6057 - name : Harden Runner
6158 uses : step-security/harden-runner@ec9f2d5744a09debf3a187a3f4f675c53b671911 # v2.13.0
6259 with :
6360 egress-policy : audit
6461
6562 - uses : actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
63+ with :
64+ ref : ${{ github.event.pull_request.head.sha }}
65+ persist-credentials : false
66+
67+ - name : Ensure bash is installed
68+ run : sudo apt-get update && sudo apt-get install -y bash
6669
6770 - name : Install Rust
6871 uses : dtolnay/rust-toolchain@56f84321dbccf38fb67ce29ab63e4754056677e0 # stable
6972 with :
7073 toolchain : stable
7174 components : rustfmt, clippy
7275
73- - uses : swatinem/rust-cache@98c8021b550208e191a6a3145459bfc9fb29c4c0 # v2.8.0
74-
7576 - name : Install cargo-binstall
7677 uses : taiki-e/install-action@f37a1e4d34f3e1c6a571e294b0258f2805eab48d # v2.58.4
7778 with :
8788 --all-features
8889 --message-format=json | ${CARGO_HOME}/bin/clippy-sarif | tee rust-clippy-results.sarif | ${CARGO_HOME}/bin/sarif-fmt
8990
91+ - name : Upload SARIF as artifact (so a separate, trusted job can upload to GitHub)
92+ uses : actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
93+ with :
94+ name : rust-clippy-results
95+ path : rust-clippy-results.sarif
96+
97+ upload-sarif :
98+ name : Upload CodeQL results
99+ needs : clippy
100+ runs-on : ubuntu-latest
101+ # grant the write permission only to this job (trusted execution)
102+ permissions :
103+ contents : read
104+ security-events : write
105+ # Only run the upload step for trusted contexts:
106+ # - pushes (e.g. push to main)
107+ # - pull requests whose head repo is not a fork (i.e. runs from trusted repository)
108+ if : ${{ github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.fork == false) }}
109+ steps :
110+
111+ - name : Harden Runner
112+ uses : step-security/harden-runner@ec9f2d5744a09debf3a187a3f4f675c53b671911 # v2.13.0
113+ with :
114+ egress-policy : audit
115+
116+ - uses : actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
117+
118+ - name : Download SARIF artifact
119+ uses : actions/download-artifact@abefc31eafcfbdf6c5336127c1346fdae79ff41c # v5.0.0
120+ with :
121+ name : rust-clippy-results
122+ path : .
123+
90124 - name : Upload analysis results to GitHub
91125 uses : github/codeql-action/upload-sarif@2d92b76c45b91eb80fc44c74ce3fce0ee94e8f9d # v3.30.0
92126 with :
@@ -97,15 +131,15 @@ jobs:
97131 name : Spell Check with Typos
98132 runs-on : ubuntu-latest
99133 steps :
100- - name : Harden Runner
101- uses : step-security/harden-runner@ec9f2d5744a09debf3a187a3f4f675c53b671911 # v2.13.0
102- with :
103- egress-policy : audit
104-
105- - name : Checkout Actions Repository
106- uses : actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
107-
108- - name : Check spelling of file.txt
109- uses : crate-ci/typos@7436548694def3314aacd93ed06c721b1f91ea04 # v1.37.2
110- with :
111- config : typos.toml
134+ - name : Harden Runner
135+ uses : step-security/harden-runner@ec9f2d5744a09debf3a187a3f4f675c53b671911 # v2.13.0
136+ with :
137+ egress-policy : audit
138+
139+ - name : Checkout Actions Repository
140+ uses : actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
141+
142+ - name : Check for typos
143+ uses : crate-ci/typos@7436548694def3314aacd93ed06c721b1f91ea04 # v1.37.2
144+ with :
145+ config : typos.toml
0 commit comments