Skip to content

Commit

Permalink
Use zizmor to lint GitHub Actions
Browse files Browse the repository at this point in the history
Make use of `zizmor` to lint GitHub Actions workflows and catch
potential security issues. Add `zizmor` to the `environment.yml` and to
the `requirements-style.txt`. Add a new `check-actions` target in the
`Makefile` that runs `zizmor` on every workflow. Add a new workflow for
running `zizmor` on PRs and on pushes to `main`.
  • Loading branch information
santisoler committed Dec 10, 2024
1 parent 58278ca commit 509b758
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 1 deletion.
35 changes: 35 additions & 0 deletions .github/workflows/actions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Lint GitHub Actions for common security issues using zizmor.
# Docs: https://woodruffw.github.io/zizmor

name: lint-actions

# Only run on PRs and the main branch.
# Pushes to branches will only trigger a run when a PR is opened.
on:
pull_request:
push:
branches:
- main

jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
persist-credentials: false

- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.12"

- name: Install requirements
run: python -m pip install -r env/requirements-style.txt

- name: List installed packages
run: python -m pip freeze

- name: Lint GitHub Actions
run: make lint-actions
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ TESTDIR=tmp-test-dir-with-unique-name
PYTEST_ARGS=--cov-config=../.coveragerc --cov-report=term-missing --cov=$(PROJECT) --doctest-modules -v --pyargs
NUMBATEST_ARGS=--doctest-modules -v --pyargs
CHECK_STYLE=$(PROJECT) doc
GITHUB_ACTIONS=.github/workflows

.PHONY: build install test test_coverage test_numba format check check-format check_style check-actions clean

help:
@echo "Commands:"
Expand Down Expand Up @@ -42,7 +45,7 @@ format:
black $(CHECK_STYLE)
burocrata --extension=py $(CHECK_STYLE)

check: check-format check-style
check: check-format check-style check-actions

check-format:
isort --check $(CHECK_STYLE)
Expand All @@ -52,6 +55,9 @@ check-format:
check-style:
flake8 $(CHECK_STYLE)

check-actions:
zizmor $(GITHUB_ACTIONS)

clean:
find . -name "*.pyc" -exec rm -v {} \;
find . -name "*.orig" -exec rm -v {} \;
Expand Down
1 change: 1 addition & 0 deletions env/requirements-style.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ flake8-simplify
flake8-unused-arguments
pep8-naming
burocrata
zizmor
1 change: 1 addition & 0 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,4 @@ dependencies:
- pep8-naming
- pip:
- burocrata
- zizmor

0 comments on commit 509b758

Please sign in to comment.