Skip to content

Commit

Permalink
chore: add pre-commit for GitHub workflow with cache
Browse files Browse the repository at this point in the history
  • Loading branch information
ayharano committed Jan 23, 2024
1 parent fb883af commit c301a03
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/run_pre_commit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Pre-commit
on: [push, pull_request]

jobs:
test:
runs-on: ubuntu-latest

steps:
- name: Checkout repo files
uses: actions/checkout@v4

- name: Install Python
uses: actions/setup-python@v5
with:
python-version: '3.12.1'

- name: set PY for pre-commit
run: echo "PY=$(python -VV | sha256sum | cut -d' ' -f1)" >> $GITHUB_ENV

- uses: actions/cache/restore@v4
id: pre-commit-cache-restore
with:
path: ~/.cache/pre-commit
key: pre-commit|${{ env.PY }}|${{ hashFiles('.pre-commit-config.yaml') }}
fail-on-cache-miss: false

- name: Setup git config for pre-commit
run: git init && git config --global --add safe.directory /__w/lacrei-api/lacrei-api && git add .

- name: Install pre-commit
run: pip install pre-commit && pre-commit install --install-hooks --overwrite

- uses: actions/cache/save@v4
id: pre-commit-cache-save
with:
path: ~/.cache/pre-commit
key: pre-commit|${{ env.PY }}|${{ hashFiles('.pre-commit-config.yaml') }}

- name: Run pre-commit all files - fails if adjustments are required
run: pre-commit run --all-files
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ $ pipx install pre-commit
$ pre-commit install --install-hooks --overwrite
```

`pre-commit` is configured to also run per push and pull requests in GitHub workflow.

## Run the project using Docker Compose (recommended way)

After [installing Docker Compose](https://docs.docker.com/compose/install/),
Expand Down

0 comments on commit c301a03

Please sign in to comment.