Skip to content

Commit d44a40f

Browse files
weiji14seisman
andauthored
Add pre-commit hook for Zizmor (#3861)
A static analysis tool for GitHub Actions. Docs at https://woodruffw.github.io/zizmor/usage/#use-with-pre-commit * Set persist-credentials: false with actions/checkout Xref https://woodruffw.github.io/zizmor/audits/#artipacked * Set permissions: {} for GitHub Actions workflows Xref https://woodruffw.github.io/zizmor/audits/#excessive-permissions * Fix potential sources of code injection via template expansion Xref https://woodruffw.github.io/zizmor/audits/#template-injection * Back to using Windows cmd, use %GMT_INSTALL_DIR% --------- Co-authored-by: Dongdong Tian <[email protected]>
1 parent 4380c50 commit d44a40f

17 files changed

+66
-6
lines changed

.github/workflows/benchmarks.yml

+3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ concurrency:
2323
group: ${{ github.workflow }}-${{ github.ref }}
2424
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
2525

26+
permissions: {}
27+
2628
jobs:
2729
benchmarks:
2830
runs-on: ubuntu-latest
@@ -38,6 +40,7 @@ jobs:
3840
with:
3941
# fetch all history so that setuptools-scm works
4042
fetch-depth: 0
43+
persist-credentials: false
4144

4245
- name: Get current week number of year
4346
id: date

.github/workflows/cache_data.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ on:
2525
schedule:
2626
- cron: '0 12 * * 0'
2727

28+
permissions: {}
29+
2830
jobs:
2931
gmt_cache:
3032
name: Cache GMT artifacts
@@ -40,6 +42,7 @@ jobs:
4042
with:
4143
# fetch all history so that setuptools-scm works
4244
fetch-depth: 0
45+
persist-credentials: false
4346

4447
# Install Micromamba with conda-forge dependencies
4548
- name: Setup Micromamba

.github/workflows/check-links.yml

+6-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ on:
1515
schedule:
1616
- cron: '0 12 * * 0'
1717

18+
permissions: {}
19+
1820
jobs:
1921
check_links:
2022
name: Check Links
@@ -26,12 +28,14 @@ jobs:
2628
uses: actions/[email protected]
2729
with:
2830
path: repository
31+
persist-credentials: false
2932

3033
- name: Checkout the documentation
3134
uses: actions/[email protected]
3235
with:
3336
ref: gh-pages
3437
path: documentation
38+
persist-credentials: false
3539

3640
- name: Link Checker
3741
id: lychee
@@ -72,7 +76,8 @@ jobs:
7276
if: env.lychee_exit_code != 0
7377
run: |
7478
cd repository/
75-
title="Link Checker Report on ${{ steps.date.outputs.date }}"
79+
title="Link Checker Report on ${CURRENT_DATE}"
7680
gh issue create --title "$title" --body-file /tmp/lychee-out.md
7781
env:
7882
GH_TOKEN: ${{ github.token }}
83+
CURRENT_DATE: ${{ steps.date.outputs.date }}

.github/workflows/ci_docs.yml

+6-1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ concurrency:
4343
group: ${{ github.workflow }}-${{ github.ref }}
4444
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
4545

46+
permissions: {}
47+
4648
jobs:
4749
docs:
4850
name: ${{ matrix.os }}
@@ -73,6 +75,7 @@ jobs:
7375
with:
7476
# fetch all history so that setuptools-scm works
7577
fetch-depth: 0
78+
persist-credentials: false
7679

7780
- name: Get current week number of year
7881
id: date
@@ -159,10 +162,11 @@ jobs:
159162
if: github.event_name == 'push' && matrix.os == 'ubuntu-latest'
160163

161164
- name: Upload the HTML ZIP archive and PDF as release assets
162-
run: gh release upload ${{ github.ref_name }} doc/_build/pygmt-docs.zip doc/_build/pygmt-docs.pdf
165+
run: gh release upload ${REF_NAME} doc/_build/pygmt-docs.zip doc/_build/pygmt-docs.pdf
163166
if: github.event_name == 'release' && matrix.os == 'ubuntu-latest'
164167
env:
165168
GH_TOKEN: ${{ github.token }}
169+
REF_NAME: ${{ github.ref_name }}
166170

167171
- name: Checkout the gh-pages branch
168172
uses: actions/[email protected]
@@ -172,6 +176,7 @@ jobs:
172176
path: deploy
173177
# Download the entire history
174178
fetch-depth: 0
179+
persist-credentials: false
175180
if: (github.event_name == 'release' || github.event_name == 'push') && (matrix.os == 'ubuntu-latest')
176181

177182
- name: Push the built HTML to gh-pages

.github/workflows/ci_doctests.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ concurrency:
1818
group: ${{ github.workflow }}-${{ github.ref }}
1919
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
2020

21+
permissions: {}
22+
2123
jobs:
2224
test:
2325
name: ${{ matrix.os }}
@@ -39,6 +41,7 @@ jobs:
3941
with:
4042
# fetch all history so that setuptools-scm works
4143
fetch-depth: 0
44+
persist-credentials: false
4245

4346
# Install Micromamba with conda-forge dependencies
4447
- name: Setup Micromamba

.github/workflows/ci_tests.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ jobs:
108108
with:
109109
# fetch all history so that setuptools-scm works
110110
fetch-depth: 0
111+
persist-credentials: false
111112

112113
- name: Get current week number of year
113114
id: date

.github/workflows/ci_tests_dev.yaml

+6-2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ concurrency:
2828
group: ${{ github.workflow }}-${{ github.ref }}
2929
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
3030

31+
permissions: {}
32+
3133
jobs:
3234
test_gmt_dev:
3335
name: ${{ matrix.os }} - GMT ${{ matrix.gmt_git_ref }}
@@ -50,6 +52,7 @@ jobs:
5052
with:
5153
# fetch all history so that setuptools-scm works
5254
fetch-depth: 0
55+
persist-credentials: false
5356

5457
- name: Get current week number of year
5558
id: date
@@ -96,6 +99,7 @@ jobs:
9699
repository: 'GenericMappingTools/gmt'
97100
ref: ${{ matrix.gmt_git_ref }}
98101
path: 'gmt'
102+
persist-credentials: false
99103

100104
# Build GMT from source on Linux/macOS, script is adapted from
101105
# https://github.com/GenericMappingTools/gmt/blob/6.5.0/ci/build-gmt.sh
@@ -105,7 +109,7 @@ jobs:
105109
mkdir build
106110
cd build
107111
cmake -G Ninja .. \
108-
-DCMAKE_INSTALL_PREFIX=${{ env.GMT_INSTALL_DIR }} \
112+
-DCMAKE_INSTALL_PREFIX=${GMT_INSTALL_DIR} \
109113
-DCMAKE_BUILD_TYPE=Release \
110114
-DGMT_ENABLE_OPENMP=TRUE \
111115
-DGMT_USE_THREADS=TRUE
@@ -125,7 +129,7 @@ jobs:
125129
cd build
126130
call "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvars64.bat"
127131
cmake -G Ninja .. ^
128-
-DCMAKE_INSTALL_PREFIX=${{ env.GMT_INSTALL_DIR }} ^
132+
-DCMAKE_INSTALL_PREFIX=%GMT_INSTALL_DIR% ^
129133
-DCMAKE_BUILD_TYPE=Release ^
130134
-DCMAKE_PREFIX_PATH=${{ env.MAMBA_ROOT_PREFIX }}\envs\pygmt\Library ^
131135
-DGMT_ENABLE_OPENMP=TRUE ^

.github/workflows/ci_tests_legacy.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ concurrency:
2626
group: ${{ github.workflow }}-${{ github.ref }}
2727
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
2828

29+
permissions: {}
30+
2931
jobs:
3032
test:
3133
name: ${{ matrix.os }} - GMT ${{ matrix.gmt_version }}
@@ -48,6 +50,7 @@ jobs:
4850
with:
4951
# fetch all history so that setuptools-scm works
5052
fetch-depth: 0
53+
persist-credentials: false
5154

5255
# Install Micromamba with conda-forge dependencies
5356
- name: Setup Micromamba

.github/workflows/dvc-diff.yml

+5-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ on:
1414
paths:
1515
- 'pygmt/tests/baseline/*.png.dvc'
1616

17+
permissions: {}
18+
1719
jobs:
1820
dvc-diff:
1921
name: DVC image diff
@@ -25,6 +27,7 @@ jobs:
2527
with:
2628
# fetch all history so that dvc diff works
2729
fetch-depth: 0
30+
persist-credentials: false
2831

2932
- name: Setup data version control (DVC)
3033
uses: iterative/[email protected]
@@ -53,6 +56,7 @@ jobs:
5356
- name: Generate the image diff report
5457
env:
5558
repo_token: ${{ github.token }}
59+
PR_HEAD_SHA: ${{ github.event.pull_request.head.sha }}
5660
run: |
5761
echo -e "## Summary of changed images\n" > report.md
5862
echo -e "This is an auto-generated report of images that have changed on the DVC remote\n" >> report.md
@@ -94,7 +98,7 @@ jobs:
9498
echo -e "</details>\n" >> report.md
9599
96100
# Mention git commit SHA in the report
97-
echo -e "Report last updated at commit ${{ github.event.pull_request.head.sha }}" >> report.md
101+
echo -e "Report last updated at commit ${PR_HEAD_SHA}" >> report.md
98102
99103
# create/update PR comment
100104
cml comment update report.md

.github/workflows/format-command.yml

+5
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,13 @@
33
# This workflow is triggered in a PR if the slash command `/format` is used.
44
#
55
name: format-command
6+
67
on:
78
repository_dispatch:
89
types: [format-command]
10+
11+
permissions: {}
12+
913
jobs:
1014
format:
1115
runs-on: ubuntu-latest
@@ -23,6 +27,7 @@ jobs:
2327
token: ${{ steps.generate-token.outputs.token }}
2428
repository: ${{ github.event.client_payload.pull_request.head.repo.full_name }}
2529
ref: ${{ github.event.client_payload.pull_request.head.ref }}
30+
persist-credentials: false
2631

2732
# Setup Python environment
2833
- uses: actions/[email protected]

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

+2
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ on:
3434
# branches:
3535
# - main
3636

37+
permissions: {}
38+
3739
jobs:
3840
build:
3941
name: Build distribution 📦

.github/workflows/release-baseline-images.yml

+4-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ jobs:
2424
steps:
2525
- name: Checkout
2626
uses: actions/[email protected]
27+
with:
28+
persist-credentials: false
2729

2830
- name: Setup data version control (DVC)
2931
uses: iterative/[email protected]
@@ -39,6 +41,7 @@ jobs:
3941
shasum -a 256 baseline-images.zip
4042
4143
- name: Upload baseline image as a release asset
42-
run: gh release upload ${{ github.ref_name }} baseline-images.zip
44+
run: gh release upload ${REF_NAME} baseline-images.zip
4345
env:
4446
GH_TOKEN: ${{ github.token }}
47+
REF_NAME: ${{ github.ref_name }}

.github/workflows/release-drafter.yml

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ on:
1111
branches:
1212
- main
1313

14+
permissions: {}
15+
1416
jobs:
1517
update_release_draft:
1618
runs-on: ubuntu-latest

.github/workflows/slash-command-dispatch.yml

+4
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,15 @@
33
# Currently, only one slash command `format` is supported.
44
#
55
name: Slash Command Dispatch
6+
67
on:
78
issue_comment:
89
types: [created]
910
# Add "edited" type for test purposes. Where possible, avoid using to prevent processing unnecessary events.
1011
# types: [created, edited]
12+
13+
permissions: {}
14+
1115
jobs:
1216
slashCommandDispatch:
1317
if: ${{ github.event.issue.pull_request }}

.github/workflows/style_checks.yaml

+4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ on:
1616
schedule:
1717
- cron: '0 0 * * *'
1818

19+
permissions: {}
20+
1921
jobs:
2022
style_check:
2123
name: Style Checks
@@ -25,6 +27,8 @@ jobs:
2527
# Checkout current git repository
2628
- name: Checkout
2729
uses: actions/[email protected]
30+
with:
31+
persist-credentials: false
2832

2933
# Setup Python
3034
- name: Set up Python

.github/workflows/type_checks.yml

+4
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ concurrency:
2525
group: ${{ github.workflow }}-${{ github.ref }}
2626
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
2727

28+
permissions: {}
29+
2830
jobs:
2931
static_check:
3032
name: Static Type Check
@@ -34,6 +36,8 @@ jobs:
3436
# Checkout current git repository
3537
- name: Checkout
3638
uses: actions/[email protected]
39+
with:
40+
persist-credentials: false
3741

3842
# Setup Python
3943
- name: Set up Python

.pre-commit-config.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ repos:
1515
- id: remove-crlf
1616
- id: chmod
1717
args: ['644']
18+
- repo: https://github.com/woodruffw/zizmor-pre-commit
19+
rev: v1.5.1
20+
hooks:
21+
- id: zizmor
22+
1823

1924
# https://pre-commit.ci/#configuration
2025
ci:

0 commit comments

Comments
 (0)