-
Notifications
You must be signed in to change notification settings - Fork 0
58 lines (47 loc) · 1.63 KB
/
Copy pathpre_commit_checks.yml
File metadata and controls
58 lines (47 loc) · 1.63 KB
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
55
56
57
58
name: Pre-commit checks
on:
pull_request:
push:
branches:
- develop
- main
jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.9'
- name: Install Poetry
run: |
curl -sSL https://install.python-poetry.org | python3 -
- name: Install dependencies
run: |
poetry install --with dev
- name: Install pre-commit
run: |
poetry run pip install pre-commit
# Fetch the base branch for pull request or push event
- name: Set base branch
id: base_branch
run: |
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
echo "Base branch is: ${{ github.event.pull_request.base.ref }}"
echo "BASE_BRANCH=${{ github.event.pull_request.base.ref }}" >> $GITHUB_ENV
elif [[ "${{ github.event_name }}" == "push" ]]; then
# For push events, assume the current branch is the base (e.g., main or develop)
echo "BASE_BRANCH=${GITHUB_REF#refs/heads/}" >> $GITHUB_ENV
echo "Base branch is: ${GITHUB_REF#refs/heads/}"
fi
- name: Check out the base branch (if necessary)
run: |
git checkout $BASE_BRANCH || echo "Already on the base branch."
- name: Fetch the base branch
run: |
git fetch origin $BASE_BRANCH
- name: Run pre-commit on changed files
run: |
poetry run pre-commit run --from-ref origin/${BASE_BRANCH} --to-ref HEAD