mirror of
https://github.com/kuhyx/diet-guard.git
synced 2026-11-10 22:47:11 +01:00
pre-commit took ~119 s as one job (24 s of pip, then every hook env and every hook in series); Tests took ~56 s (26 s of pip, 7 s of apt-get for an xvfb the image already ships, 17 s of -v pytest). Same hooks, same flags, same 100% bar -- just parallel runners, cached uv wheels, xdist workers. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0188kZdx3bb56QM8JFUnbHuM
84 lines
3.0 KiB
YAML
84 lines
3.0 KiB
YAML
name: pre-commit
|
|
|
|
on:
|
|
push:
|
|
branches: [main]
|
|
pull_request:
|
|
branches: [main]
|
|
|
|
jobs:
|
|
# mypy (~17 s) and pylint (~10 s, plus ~20 s to build its hook env) checked
|
|
# the whole repo inside one ~2 min job, so each gets its own runner and the
|
|
# other hooks share a third; the workflow takes as long as the slowest group
|
|
# rather than the sum.
|
|
pre-commit:
|
|
runs-on: ubuntu-latest
|
|
strategy:
|
|
fail-fast: false
|
|
matrix:
|
|
include:
|
|
- group: mypy
|
|
hooks: mypy
|
|
skip: ""
|
|
- group: pylint
|
|
hooks: pylint
|
|
skip: ""
|
|
- group: rest
|
|
hooks: ""
|
|
skip: mypy,pylint
|
|
name: pre-commit (${{ matrix.group }})
|
|
steps:
|
|
- uses: actions/checkout@v4
|
|
|
|
# The file-length, md-naming and dependency-freshness hooks delegate to
|
|
# the shared gates in kuhyx/utils, which a runner does not have at
|
|
# $HOME/src/utils. Only the rest group runs them.
|
|
- name: Check out the shared gates
|
|
if: matrix.group == 'rest'
|
|
uses: actions/checkout@v4
|
|
with:
|
|
repository: kuhyx/utils
|
|
path: .utils
|
|
- name: Point the delegates at that checkout
|
|
if: matrix.group == 'rest'
|
|
run: echo "UTILS_ROOT=$GITHUB_WORKSPACE/.utils" >> "$GITHUB_ENV"
|
|
|
|
- uses: actions/setup-python@v5
|
|
with:
|
|
python-version: "3.x"
|
|
|
|
# Only rest caches its wheels: its install is the big one, and a shared
|
|
# key would hold whichever group saved first (the suffix keeps it apart
|
|
# from the Tests workflow's cache of the same requirements.txt).
|
|
- uses: astral-sh/setup-uv@v10.2.0
|
|
with:
|
|
enable-cache: ${{ matrix.group == 'rest' }}
|
|
cache-dependency-glob: requirements.txt
|
|
cache-suffix: pre-commit-${{ matrix.group }}
|
|
|
|
# mypy and pylint bring their own hook environments, so they need only
|
|
# pre-commit. The rest group's language: system patch-targets hook
|
|
# imports diet_guard and every patched module (requests, gatelock,
|
|
# crdt_sync, freedays, mcp, pydantic), and dependency-freshness needs
|
|
# pyyaml and packaging -- so it keeps the full requirements.txt. That
|
|
# install used to run in the one job, with plain pip, for ~24 s.
|
|
- name: Install pre-commit and the system hooks' imports
|
|
run: |
|
|
if [[ "${{ matrix.group }}" == rest ]]; then
|
|
uv pip install --system -r requirements.txt
|
|
else
|
|
uv pip install --system pre-commit
|
|
fi
|
|
|
|
# One cache per group: a shared key would hold whichever group saved
|
|
# first, and the others would rebuild their hook envs on every run.
|
|
- uses: actions/cache@v4
|
|
with:
|
|
path: ~/.cache/pre-commit
|
|
key: pre-commit-${{ matrix.group }}-${{ env.pythonLocation }}-${{ hashFiles('.pre-commit-config.yaml') }}
|
|
|
|
- name: pre-commit run (${{ matrix.group }})
|
|
env:
|
|
SKIP: ${{ matrix.skip }}
|
|
run: pre-commit run ${{ matrix.hooks }} --all-files --show-diff-on-failure --color=always
|