Skip to content

Commit 8ce69f8

Browse files
feat(zizmor): enable running offline only (#956)
* chore(zizmor): enable running offline only * quote the value * move offline flag to first * add extra args to zizmor * add quotes to params * optional extra args * explicitly set the version * remove the github token arg, pass in through extra-args now * quote version * update docs * address comments * unquote extra-args * self test offline mode * rebase conflicts * update self test to include permissions * remove uv install and instead rely on uvx
1 parent 7cfe483 commit 8ce69f8

File tree

3 files changed

+77
-12
lines changed

3 files changed

+77
-12
lines changed

.github/workflows/reusable-zizmor.md

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ show the current results.
1515
[zizmor]: https://woodruffw.github.io/zizmor/
1616
[zizmor-checks]: https://woodruffw.github.io/zizmor/audits/
1717

18+
## Examples
19+
20+
**Online Checks**
21+
1822
```yaml
1923
name: Zizmor GitHub Actions static analysis
2024
on:
@@ -50,6 +54,40 @@ jobs:
5054
fail-severity: any
5155
```
5256
57+
**Faster Offline Checks**
58+
59+
```yaml
60+
name: Zizmor GitHub Actions static analysis (online checks)
61+
on:
62+
pull_request:
63+
paths:
64+
- ".github/**"
65+
push:
66+
branches:
67+
- main
68+
paths:
69+
- ".github/**"
70+
71+
jobs:
72+
scorecard:
73+
name: Analyse
74+
75+
permissions:
76+
actions: read
77+
contents: read
78+
79+
# required to comment on pull requests with the results of the check
80+
pull-requests: write
81+
# required to upload the results to GitHub's code scanning service
82+
security-events: write
83+
84+
uses: grafana/shared-workflows/.github/workflows/reusable-zizmor.yml@<some sha>
85+
with:
86+
# example: fail if there are any findings
87+
fail-severity: any
88+
extra-args: "--offline"
89+
```
90+
5391
## Inputs
5492
5593
| Name | Type | Description | Default Value | Required |
@@ -60,7 +98,8 @@ jobs:
6098
| runs-on | string | The runner to use for jobs. Configure this to use self-hosted runners. | ubuntu-latest | false |
6199
| default-config | boolean | The default Zizmor configuration to use. If `always-use-default-config` is `true`, this configuration will always be used. Otherwise, it will be used if the repository does not have a `.github/zizmor.yml` or `zizmor.yml` file. | true | false |
62100
| always-use-default-config | boolean | Whether to always use `default-config`. | false | false |
63-
| github-token | string | The GitHub token to use when authenticating with the GitHub API | ${github.token} | false |
101+
| github-token | string | Use a different token to the default | ${github.token} | false |
102+
| extra-args | string | Extra arguments to pass into zizmor | "" | false |
64103

65104
## Getting started
66105

.github/workflows/reusable-zizmor.yml

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,23 @@ on:
2727
type: string
2828
default: "ubuntu-latest"
2929

30+
github-token:
31+
description: Use a different token to the default
32+
required: false
33+
type: string
34+
default: ${{ github.token }}
35+
3036
always-use-default-config:
3137
description: Whether to always use the default configuration.
3238
required: false
3339
type: boolean
3440
default: false
3541

36-
github-token:
37-
description: "The GitHub token to use for the job"
42+
extra-args:
43+
description: Extra arguments to pass to Zizmor
3844
required: false
3945
type: string
46+
default: ""
4047

4148
permissions: {}
4249

@@ -216,9 +223,10 @@ jobs:
216223
env:
217224
MIN_SEVERITY: ${{ inputs.min-severity }}
218225
MIN_CONFIDENCE: ${{ inputs.min-confidence }}
219-
GH_TOKEN: ${{ inputs.github-token || github.token }}
220226
# renovate: datasource=pypi depName=zizmor
221227
ZIZMOR_VERSION: 1.6.0
228+
GH_TOKEN: ${{ inputs.github-token || github.token }}
229+
ZIZMOR_EXTRA_ARGS: ${{ inputs.extra-args }}
222230

223231
steps:
224232
- name: Harden the runner (Audit all outbound calls)
@@ -338,12 +346,6 @@ jobs:
338346
cache-suffix: ${{ env.ZIZMOR_VERSION }}
339347
cache-dependency-glob: ""
340348

341-
- name: Install Zizmor
342-
shell: bash
343-
run: |
344-
echo "Installing Zizmor ${ZIZMOR_VERSION}"
345-
uv pip install --no-cache-dir "zizmor==${ZIZMOR_VERSION}"
346-
347349
- name: Zizmor cache
348350
uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4
349351
with:
@@ -356,13 +358,14 @@ jobs:
356358
ZIZMOR_CACHE_DIR: ${{ runner.temp }}/.cache/zizmor
357359
shell: sh
358360
run: >-
359-
uvx zizmor
361+
uvx zizmor@"${ZIZMOR_VERSION}"
360362
--format sarif
361363
--min-severity "${MIN_SEVERITY}"
362364
--min-confidence "${MIN_CONFIDENCE}"
363365
--cache-dir "${ZIZMOR_CACHE_DIR}"
364366
${ZIZMOR_CONFIG:+--config "${ZIZMOR_CONFIG}"}
365367
${RUNNER_DEBUG:+"--verbose"}
368+
${ZIZMOR_EXTRA_ARGS:+${ZIZMOR_EXTRA_ARGS}}
366369
.
367370
> results.sarif
368371
@@ -394,13 +397,14 @@ jobs:
394397
# don't fail the build if zizmor fails - we want to capture the output
395398
# and the exit code
396399
set +e
397-
uvx zizmor \
400+
uvx zizmor@"${ZIZMOR_VERSION}" \
398401
--format plain \
399402
--min-severity "${MIN_SEVERITY}" \
400403
--min-confidence "${MIN_CONFIDENCE}" \
401404
--cache-dir "${ZIZMOR_CACHE_DIR}" \
402405
${RUNNER_DEBUG:+"--verbose"} \
403406
${ZIZMOR_CONFIG:+--config "${ZIZMOR_CONFIG}"} \
407+
${ZIZMOR_EXTRA_ARGS:+${ZIZMOR_EXTRA_ARGS}} \
404408
. \
405409
| tee -a "${GITHUB_OUTPUT}"
406410
zizmor_exit_code=$?
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: Test reusable Zizmor in offline mode
2+
on:
3+
push:
4+
pull_request:
5+
6+
permissions:
7+
contents: read
8+
9+
jobs:
10+
zizmor-offline:
11+
name: Run zizmor offline for current branch (self test)
12+
13+
permissions:
14+
actions: read
15+
contents: read
16+
id-token: write
17+
pull-requests: write
18+
security-events: write
19+
20+
uses: ./.github/workflows/reusable-zizmor.yml
21+
with:
22+
extra-args: --offline --collect=all

0 commit comments

Comments
 (0)