Local precommit dependencies
Recently a bunch of my pre-commit CI jobs started failing due to dependency resolution issues. The easiest way to ensure reliable usage is to have locally installed tools used. Consider:
1- repo: https://github.com/pocc/pre-commit-hooks
2 rev: v1.3.5
3 hooks:
4 - id: cppcheck
5 args: ["--error-exitcode=0"]
Which leaves one dependent on an external repo. This can be rewritten as:
1- repo: local
2 hooks:
3 - id: cppcheck
4 name: cppcheck
5 entry: cppcheck
6 language: system
7 types_or: [c++, c]
8 args: ["--error-exitcode=0"]
With this local setup, it is necessary to adjust the CI configuration:
1name: pre-commit
2on:
3 pull_request:
4 push:
5 branches: [main]
6jobs:
7 pre-commit:
8 runs-on: ubuntu-latest
9 steps:
10 - uses: actions/checkout@v3
11 - name: Install Conda environment
12 uses: mamba-org/provision-with-micromamba@main
13 - name: Run precommit
14 shell: bash -l {0}
15 run: |
16 pipx run pre-commit run -a
This ensures the pre-commit
action is executed within the conda
environment,
which is assumed to have pipx
and the dependencies present.
Comments