Skip to content

Commit 840ad26

Browse files
committed
Run pre-commit in CI on a lint-only environment
pre-commit has never run in GitHub Actions; only the external pre-commit.ci service ran it. Now that the formatting hooks are skipped there, because they need an environment that service does not build, this job runs them. It installs the "lint" extra alone, read out of pyproject.toml at run time so the versions are not restated in the workflow. That needs neither torch nor the optional dependencies, unlike static-checks, which installs .[all,testing] before running formatters. static-checks is left unchanged. Running both routes keeps the copyright and pyrefly coverage it provides, and makes CI fail if pre-commit and runtests.sh ever disagree about the same files. Signed-off-by: Hans Johnson <hans-johnson@uiowa.edu>
1 parent 7e50b13 commit 840ad26

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

.github/workflows/cicd_tests.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,34 @@ env:
5252
# When support is dropped for a version it is important to update these as appropriate.
5353

5454
jobs:
55+
pre-commit: # Run the hooks pre-commit.ci skips, using the tools pyproject.toml pins
56+
runs-on: ubuntu-latest
57+
permissions:
58+
contents: read
59+
steps:
60+
# This job executes the hooks named by a PR's own .pre-commit-config.yaml, so
61+
# it must not leave a usable token in .git/config for those hooks to reach.
62+
- uses: actions/checkout@v7
63+
with:
64+
persist-credentials: false
65+
# reads the pins below with tomllib, which needs 3.11+; the hooks take their
66+
# target from pyproject.toml, so the interpreter version does not affect them
67+
- name: Set up Python ${{ env.PYTHON_VER3 }}
68+
uses: actions/setup-python@v6
69+
with:
70+
python-version: ${{ env.PYTHON_VER3 }}
71+
cache: 'pip'
72+
- name: Install lint tools
73+
run: |
74+
# the lint extra alone, so this job needs neither torch nor the optional dependencies
75+
python -m pip install --upgrade pip
76+
python -c "import tomllib; print('\n'.join(tomllib.load(open('pyproject.toml','rb'))['project']['optional-dependencies']['lint']))" > lint-requirements.txt
77+
cat lint-requirements.txt
78+
python -m pip install -r lint-requirements.txt
79+
rm lint-requirements.txt
80+
- name: Run pre-commit
81+
run: python -m pre_commit run --all-files --show-diff-on-failure
82+
5583
static-checks: # Perform static type and other checks using runtests.sh
5684
runs-on: ubuntu-latest
5785
strategy:

0 commit comments

Comments
 (0)