Use pre-commit
to lint code and add CI job to run it
#322
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: Check formatting | |
on: | |
push: | |
branches: | |
- main | |
paths-ignore: | |
- "_quarto.yml" | |
- "quarto-materials/*" | |
pull_request: | |
branches: | |
- main | |
paths-ignore: | |
- "_quarto.yml" | |
- "quarto-materials/*" | |
jobs: | |
# TODO(paris): pre-commit also runs clang-format. Leaving for now to gain confidence that it | |
# is doing the same thing as running clang-format directly, but remove this job once that's been | |
# confirmed | |
run-clang-format: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: "Check clang-format" | |
run: | | |
source $GITHUB_WORKSPACE/scripts/ci/check_clang_format.sh | |
shell: bash | |
# Based on: https://github.com/TileDB-Inc/TileDB-Cloud-Py/blob/main/.github/workflows/tiledb-cloud-py.yaml#L15 | |
run-pre-format: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- uses: actions/setup-python@v4 | |
with: | |
python-version: "3.9" | |
cache: pip | |
cache-dependency-path: ".github/workflows/check-formatting.yml" | |
- name: Install pre-commit | |
run: pip install ".[formatting]" | |
- name: Restore pre-commit cache | |
uses: actions/cache@v3 | |
with: | |
path: ~/.cache/pre-commit | |
key: pre-commit-${{ hashFiles('.pre-commit-config.yaml') }} | |
- name: Run pre-commit checks | |
run: pre-commit run --all-files --verbose |