From b8ae1e0e05744057f5cc3fe4ec0f73f45708a931 Mon Sep 17 00:00:00 2001 From: Jonathan Plasse <13716151+JonathanPlasse@users.noreply.github.com> Date: Fri, 24 Mar 2023 22:20:13 +0100 Subject: [PATCH] Add `pre-commit` in CI (#3707) --- .github/workflows/ci.yaml | 26 ++++++++++++++++++++++++++ .pre-commit-config.yaml | 2 +- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index fe1a5472af..9c667dfb72 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -198,3 +198,29 @@ jobs: echo '```' >> $GITHUB_STEP_SUMMARY exit 1 fi + + pre-commit: + name: "pre-commit" + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-python@v4 + with: + python-version: "3.11" + - name: "Install Rust toolchain" + run: rustup show + - uses: Swatinem/rust-cache@v2 + - name: "Install pre-commit" + run: pip install pre-commit + - name: "Cache pre-commit" + uses: actions/cache@v3 + with: + path: ~/.cache/pre-commit + key: pre-commit-${{ hashFiles('.pre-commit-config.yaml') }} + - name: "Run pre-commit" + run: | + echo '```console' > $GITHUB_STEP_SUMMARY + # Enable color output for pre-commit and remove it for the summary + SKIP=cargo-fmt,clippy,dev-generate-all pre-commit run --all-files --show-diff-on-failure --color=always | \ + tee >(sed -E 's/\x1B\[([0-9]{1,2}(;[0-9]{1,2})*)?[mGK]//g' >> $GITHUB_STEP_SUMMARY) >&1 + echo '```' >> $GITHUB_STEP_SUMMARY diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 2bd8e60d0c..da2807fd09 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -37,7 +37,7 @@ repos: pass_filenames: false - id: ruff name: ruff - entry: cargo run -p ruff_cli -- check --no-cache --force-exclude --fix --exit-non-zero-on-fix --extend-ignore=E203 + entry: cargo run -p ruff_cli -- check --no-cache --force-exclude --fix --exit-non-zero-on-fix language: system types_or: [python, pyi] require_serial: true