Spaces:
Running
Running
| # .github/workflows/precommit.yml — rejoue les hooks pre-commit en CI | |
| # | |
| # Sprint A1 (item m-7 de l'audit institutional-readiness-2026-05). | |
| # | |
| # Pourquoi : .pre-commit-config.yaml définit 12 hooks (ruff, trailing | |
| # whitespace, YAML/JSON/TOML check, merge conflict marker, detect-private-key, | |
| # check-added-large-files). Sans ce workflow, un développeur peut bypass | |
| # les hooks via ``git commit --no-verify`` et la CI ne le détecte pas. | |
| # | |
| # Ce job rejoue *exactement* les hooks ``.pre-commit-config.yaml`` sur | |
| # l'intégralité du diff de la PR. Si un hook échoue, la PR est bloquée. | |
| # | |
| # Le job ``lint`` de ci.yml reste en place pour valider ruff sur tout | |
| # l'arbre (couverture inter-fichiers que pre-commit ne fait pas par défaut). | |
| name: Pre-commit hooks | |
| on: | |
| push: | |
| branches: [main, develop, "feature/**", "claude/**"] | |
| pull_request: | |
| branches: [main, develop] | |
| workflow_dispatch: | |
| permissions: | |
| contents: read | |
| jobs: | |
| precommit: | |
| name: Replay pre-commit hooks | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| # fetch-depth: 0 nécessaire pour que pre-commit puisse comparer | |
| # la PR à sa base et ne lance les hooks que sur les fichiers | |
| # modifiés (rapide et conforme à l'usage local). | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.11" | |
| cache: pip | |
| - name: Install pre-commit | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install pre-commit | |
| - name: Cache pre-commit hooks | |
| uses: actions/cache@v4 | |
| with: | |
| path: ~/.cache/pre-commit | |
| key: precommit-${{ runner.os }}-${{ hashFiles('.pre-commit-config.yaml') }} | |
| # Sur push : on rejoue les hooks sur tous les fichiers (mode --all-files) | |
| # car on n'a pas de "base" naturelle. Sur PR : --from-ref / --to-ref | |
| # pour ne lancer que sur le diff (rapide). | |
| - name: Run pre-commit on PR diff | |
| if: github.event_name == 'pull_request' | |
| run: | | |
| pre-commit run \ | |
| --from-ref ${{ github.event.pull_request.base.sha }} \ | |
| --to-ref ${{ github.event.pull_request.head.sha }} \ | |
| --show-diff-on-failure | |
| - name: Run pre-commit on push (all files) | |
| if: github.event_name == 'push' || github.event_name == 'workflow_dispatch' | |
| run: | | |
| pre-commit run --all-files --show-diff-on-failure | |