Skip to content

Commit 8d872a3

Browse files
authored
Harden GitHub Actions workflows with zizmor (#86)
1 parent 82e1032 commit 8d872a3

4 files changed

Lines changed: 91 additions & 21 deletions

File tree

.github/dependabot.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ updates:
55
directory: "/"
66
schedule:
77
interval: "weekly"
8+
cooldown:
9+
default-days: 7
810
groups:
911
github-actions:
1012
patterns:
@@ -13,3 +15,5 @@ updates:
1315
directory: "/"
1416
schedule:
1517
interval: "weekly"
18+
cooldown:
19+
default-days: 7

.github/workflows/main.yml

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,35 @@ on:
1414
- '*'
1515
merge_group:
1616

17+
permissions: {}
18+
1719
jobs:
1820

1921
run-type-checking:
2022

2123
name: Run tests for type-checking
2224
runs-on: ubuntu-latest
25+
permissions:
26+
contents: read
2327

2428
steps:
25-
- uses: actions/checkout@v6
26-
- uses: astral-sh/setup-uv@v7
29+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
30+
with:
31+
persist-credentials: false
32+
- uses: astral-sh/setup-uv@37802adc94f370d6bfd71619e3f0bf239e1f3b78 # v7
2733
with:
2834
enable-cache: true
2935
- name: Install just
30-
uses: extractions/setup-just@v3
36+
uses: extractions/setup-just@f8a3cce218d9f83db3a2ecd90e41ac3de6cdfd9b # v3
3137
- name: Run type checking
3238
run: just typing
3339

3440
run-tests:
3541

3642
name: Run tests for ${{ matrix.os }} on ${{ matrix.python-version }}
3743
runs-on: ${{ matrix.os }}
44+
permissions:
45+
contents: read
3846

3947
strategy:
4048
fail-fast: false
@@ -43,21 +51,23 @@ jobs:
4351
python-version: ['3.10', '3.11', '3.12', '3.13', '3.14']
4452

4553
steps:
46-
- uses: actions/checkout@v6
47-
- uses: julia-actions/setup-julia@v2
54+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
55+
with:
56+
persist-credentials: false
57+
- uses: julia-actions/setup-julia@4c0cb0fce8556fdb04a90347310e5db8b1f98fb9 # v2
4858
with:
4959
version: "1"
50-
- uses: astral-sh/setup-uv@v7
60+
- uses: astral-sh/setup-uv@37802adc94f370d6bfd71619e3f0bf239e1f3b78 # v7
5161
with:
5262
python-version: ${{ matrix.python-version }}
5363
enable-cache: true
5464
- name: Install Julia dependencies
5565
run: julia --project=. --eval 'import Pkg; Pkg.instantiate()'
5666
- name: Install just
57-
uses: extractions/setup-just@v3
67+
uses: extractions/setup-just@f8a3cce218d9f83db3a2ecd90e41ac3de6cdfd9b # v3
5868

5969
- name: Run tests
6070
run: just test-cov
6171

6272
- name: Upload test coverage reports to Codecov with GitHub Action
63-
uses: codecov/codecov-action@v5
73+
uses: codecov/codecov-action@75cd11691c0faa626561e295848008c8a7dddffe # v5

.github/workflows/publish-to-pypi.yml

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,21 @@ name: Publish Python 🐍 distribution 📦 to PyPI
22

33
on: push
44

5+
permissions: {}
6+
57
jobs:
68
build:
79
name: Build distribution 📦
810
runs-on: ubuntu-latest
11+
permissions:
12+
contents: read
913

1014
steps:
11-
- uses: actions/checkout@v6
15+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
16+
with:
17+
persist-credentials: false
1218
- name: Set up Python
13-
uses: actions/setup-python@v6
19+
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6
1420
with:
1521
python-version: "3.x"
1622
- name: Install pypa/build
@@ -22,7 +28,7 @@ jobs:
2228
- name: Build a binary wheel and a source tarball
2329
run: python3 -m build
2430
- name: Store the distribution packages
25-
uses: actions/upload-artifact@v7
31+
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7
2632
with:
2733
name: python-package-distributions
2834
path: dist/
@@ -41,12 +47,12 @@ jobs:
4147

4248
steps:
4349
- name: Download all the dists
44-
uses: actions/download-artifact@v8
50+
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8
4551
with:
4652
name: python-package-distributions
4753
path: dist/
4854
- name: Publish distribution 📦 to PyPI
49-
uses: pypa/gh-action-pypi-publish@release/v1
55+
uses: pypa/gh-action-pypi-publish@ed0c53931b1dc9bd32cbe73a98c7f6766f8a527e # release/v1
5056

5157
github-release:
5258
name: >-
@@ -62,30 +68,32 @@ jobs:
6268

6369
steps:
6470
- name: Download all the dists
65-
uses: actions/download-artifact@v8
71+
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8
6672
with:
6773
name: python-package-distributions
6874
path: dist/
6975
- name: Sign the dists with Sigstore
70-
uses: sigstore/gh-action-sigstore-python@v3.2.0
76+
uses: sigstore/gh-action-sigstore-python@a5caf349bc536fbef3668a10ed7f5cd309a4b53d # v3.2.0
7177
with:
7278
inputs: >-
7379
./dist/*.tar.gz
7480
./dist/*.whl
7581
- name: Create GitHub Release
7682
env:
7783
GITHUB_TOKEN: ${{ github.token }}
84+
RELEASE_TAG: ${{ github.ref_name }}
85+
REPOSITORY: ${{ github.repository }}
7886
run: >-
7987
gh release create
80-
'${{ github.ref_name }}'
81-
--repo '${{ github.repository }}'
88+
"$RELEASE_TAG"
89+
--repo "$REPOSITORY"
8290
--notes ""
8391
- name: Upload artifact signatures to GitHub Release
8492
env:
8593
GITHUB_TOKEN: ${{ github.token }}
86-
# Upload to GitHub Release using the `gh` CLI. `dist/` contains the built
87-
# packages, and the sigstore-produced signatures and certificates.
94+
RELEASE_TAG: ${{ github.ref_name }}
95+
REPOSITORY: ${{ github.repository }}
8896
run: >-
8997
gh release upload
90-
'${{ github.ref_name }}' dist/**
91-
--repo '${{ github.repository }}'
98+
"$RELEASE_TAG" dist/**
99+
--repo "$REPOSITORY"

.github/workflows/zizmor.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: zizmor
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- '*'
10+
schedule:
11+
- cron: '0 7 * * 1'
12+
workflow_dispatch:
13+
14+
permissions: {}
15+
16+
jobs:
17+
zizmor:
18+
name: Scan GitHub Actions
19+
runs-on: ubuntu-latest
20+
permissions:
21+
contents: read
22+
security-events: write
23+
24+
steps:
25+
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
26+
with:
27+
persist-credentials: false
28+
29+
- uses: astral-sh/setup-uv@37802adc94f370d6bfd71619e3f0bf239e1f3b78 # v7
30+
with:
31+
enable-cache: true
32+
python-version: '3.13'
33+
34+
- name: Run zizmor
35+
run: uvx --from zizmor zizmor --format=github .
36+
37+
- name: Generate SARIF report
38+
if: always()
39+
run: uvx --from zizmor zizmor --format=sarif --no-exit-codes . > zizmor.sarif
40+
41+
- name: Upload SARIF report
42+
if: >
43+
always() &&
44+
(github.event_name != 'pull_request' ||
45+
github.event.pull_request.head.repo.full_name == github.repository)
46+
uses: github/codeql-action/upload-sarif@c10b8064de6f491fea524254123dbe5e09572f13 # v4
47+
with:
48+
sarif_file: zizmor.sarif

0 commit comments

Comments
 (0)