-
Notifications
You must be signed in to change notification settings - Fork 0
54 lines (50 loc) · 1.86 KB
/
pre-commit.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
name: pre-commit
on:
pull_request:
push:
branches:
- main
jobs:
pre-commit:
name: pre-commit
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v4
with:
fetch-depth: 0
clean: false
ref: ${{ github.head_ref }}
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.8'
cache: 'pip'
# N.B. we don't need all the dependencies to run the code for just pre-commit
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements-dev.txt
- name: Cache pre-commit envs
uses: actions/cache@v2
with:
path: ~/.cache/pre-commit
key: ${{ runner.os }}-pre-commit-${{ hashFiles('**/requirements-dev.txt') }}-${{ hashFiles('**/.pre-commit-config.yaml') }}
restore-keys: |
${{ runner.os }}-pre-commit-${{ hashFiles('**/requirements-dev.txt') }}-
${{ runner.os }}-pre-commit-
- name: Run pre-commit
env:
REF_BEFORE: ${{ github.event_name == 'pull_request' && github.base_ref || github.event.before }}
REF_AFTER: ${{ github.event_name == 'pull_request' && github.head_ref || github.event.after }}
run: |
# make sure dropped commits are fetched
git fetch origin $REF_BEFORE:$REF_BEFORE
# if it's a push, check since the common ancestor of the before/after (for forced pushes)
if [[ "${{ github.event_name }}" == "push" ]]; then
export REF_BEFORE=$(git merge-base $REF_BEFORE $REF_AFTER)
fi
# make sure gitlint knows which commits to lint
export GITLINT_COMMITS=$REF_BEFORE..$REF_AFTER
# run pre-commit
pre-commit run --from-ref $REF_BEFORE --to-ref $REF_AFTER