Switch to pre-commit workflow (#132) #182
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: CI | |
on: | |
push: | |
branches: ["main"] | |
pull_request: | |
branches: ["main"] | |
permissions: | |
contents: read | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
python-version: ["3.10", "3.12"] | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up Python ${{ matrix.python-version }} | |
uses: actions/setup-python@v5 | |
with: | |
python-version: ${{ matrix.python-version }} | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install poetry | |
poetry export --with dev -f requirements.txt --output /tmp/requirements.txt | |
pip install -r /tmp/requirements.txt | |
- name: Test | |
run: | | |
source scripts/test.sh | |
pre-commit: | |
name: "pre-commit" | |
runs-on: ubuntu-latest | |
timeout-minutes: 10 | |
steps: | |
- name: Checkout the repository | |
uses: actions/checkout@v4 | |
- uses: actions/setup-python@v5 | |
- name: "Install pre-commit" | |
run: python -m pip install pre-commit | |
- name: "Cache pre-commit" | |
uses: actions/cache@v4 | |
with: | |
path: ~/.cache/pre-commit | |
key: pre-commit-${{ hashFiles('.pre-commit-config.yaml') }} | |
- name: "Run pre-commit" | |
run: | | |
echo '```console' > "$GITHUB_STEP_SUMMARY" | |
# Enable colour output for pre-commit and remove it for the summary. | |
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 | |
exit_code="${PIPESTATUS[0]}" | |
echo '```' >> "$GITHUB_STEP_SUMMARY" | |
exit "$exit_code" |