Skip to content

Commit 81e188c

Browse files
committed
Improve security of our GitHub Actions
1 parent 9bf5169 commit 81e188c

File tree

8 files changed

+42
-17
lines changed

8 files changed

+42
-17
lines changed

.github/workflows/build_wheels.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,16 @@ on:
55
branches: [main, master, 'release*']
66
tags: ['*']
77

8-
permissions:
9-
contents: write
10-
118
jobs:
129
build-wheels:
1310
if: github.repository == 'python/mypy'
1411
runs-on: ubuntu-latest
12+
permissions:
13+
contents: write
1514
steps:
1615
- uses: actions/checkout@v4
16+
with:
17+
persist-credentials: false
1718
- uses: actions/setup-python@v5
1819
with:
1920
python-version: '3.11'

.github/workflows/docs.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ jobs:
3535
VERIFY_MYPY_ERROR_CODES: 1
3636
steps:
3737
- uses: actions/checkout@v4
38+
with:
39+
persist-credentials: false
3840
- uses: actions/setup-python@v5
3941
with:
4042
python-version: '3.12'

.github/workflows/mypy_primer.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ jobs:
3838
with:
3939
path: mypy_to_test
4040
fetch-depth: 0
41+
persist-credentials: false
4142
- uses: actions/setup-python@v5
4243
with:
4344
python-version: "3.12"
@@ -102,3 +103,7 @@ jobs:
102103
name: mypy_primer_diffs
103104
pattern: mypy_primer_diffs-*
104105
delete-merged: true
106+
- name: Call comments workflow
107+
uses: python/mypy/.github/workflows/mypy_primer_comment.yml@master
108+
with:
109+
workflow_id: ${{ workflow.id }}

.github/workflows/mypy_primer_comment.yml

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,32 @@
11
name: Comment with mypy_primer diff
22

33
on:
4-
workflow_run:
5-
workflows:
6-
- Run mypy_primer
7-
types:
8-
- completed
4+
workflow_call:
5+
input:
6+
workflow_id:
7+
required: true
8+
type: integer
99

10-
permissions:
11-
contents: read
12-
pull-requests: write
1310

1411
jobs:
1512
comment:
1613
name: Comment PR from mypy_primer
1714
runs-on: ubuntu-latest
18-
if: ${{ github.event.workflow_run.conclusion == 'success' }}
15+
permissions:
16+
contents: read
17+
pull-requests: write
1918
steps:
2019
- name: Download diffs
2120
uses: actions/github-script@v7
21+
env:
22+
WORKFLOW_ID: ${{ inputs.workflow_id }}
2223
with:
2324
script: |
2425
const fs = require('fs');
2526
const artifacts = await github.rest.actions.listWorkflowRunArtifacts({
2627
owner: context.repo.owner,
2728
repo: context.repo.repo,
28-
run_id: ${{ github.event.workflow_run.id }},
29+
run_id: process.env.WORKFLOW_ID,
2930
});
3031
const [matchArtifact] = artifacts.data.artifacts.filter((artifact) =>
3132
artifact.name == "mypy_primer_diffs");

.github/workflows/sync_typeshed.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,20 @@ on:
55
schedule:
66
- cron: "0 0 1,15 * *"
77

8-
permissions:
9-
contents: write
10-
pull-requests: write
11-
128
jobs:
139
sync_typeshed:
1410
name: Sync typeshed
1511
if: github.repository == 'python/mypy'
1612
runs-on: ubuntu-latest
13+
permissions:
14+
contents: write
15+
pull-requests: write
1716
timeout-minutes: 10
1817
steps:
1918
- uses: actions/checkout@v4
2019
with:
2120
fetch-depth: 0
21+
persist-credentials: false
2222
# TODO: use whatever solution ends up working for
2323
# https://github.com/python/typeshed/issues/8434
2424
- uses: actions/setup-python@v5

.github/workflows/test.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,8 @@ jobs:
136136

137137
steps:
138138
- uses: actions/checkout@v4
139+
with:
140+
persist-credentials: false
139141

140142
- name: Debug build
141143
if: ${{ matrix.debug_build }}
@@ -217,6 +219,8 @@ jobs:
217219
CC: i686-linux-gnu-gcc
218220
steps:
219221
- uses: actions/checkout@v4
222+
with:
223+
persist-credentials: false
220224
- name: Install 32-bit build dependencies
221225
run: |
222226
sudo dpkg --add-architecture i386 && \

.github/workflows/test_stubgenc.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ jobs:
2929
steps:
3030

3131
- uses: actions/checkout@v4
32+
with:
33+
persist-credentials: false
3234

3335
- name: Setup 🐍 3.9
3436
uses: actions/setup-python@v5

.pre-commit-config.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,15 @@ repos:
2929
-ignore=property "allow_failure" is not defined,
3030
-ignore=SC2(046|086),
3131
]
32+
- repo: https://github.com/woodruffw/zizmor-pre-commit
33+
rev: v1.0.0
34+
hooks:
35+
- id: zizmor
36+
# Should be the last one:
37+
- repo: meta
38+
hooks:
39+
- id: check-hooks-apply
40+
- id: check-useless-excludes
41+
3242
ci:
3343
autoupdate_schedule: quarterly

0 commit comments

Comments
 (0)