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=1"]

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=1"]

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@v4
11    - name: Install Conda environment
12      # Using a lock file is optional but heavily recommended
13      uses: mamba-org/setup-micromamba@v1
14      with:
15        environment-file: conda-lock.yml
16        environment-name: ci
17    - name: Run precommit
18      shell: bash -l {0}
19      run: |
20        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.