-
Notifications
You must be signed in to change notification settings - Fork 43
53 lines (45 loc) · 1.39 KB
/
pre-commit.yaml
File metadata and controls
53 lines (45 loc) · 1.39 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
name: Run Pre-commit Hooks
on:
pull_request:
branches:
- main
push:
branches:
- main
jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
# Checkout the code and fetch all branches
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0 # Ensure the full history is fetched, not just the last commit
# Set up Python environment
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.11
# Install dependencies and pre-commit hooks
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pre-commit
# Fetch the main branch to ensure it's available for comparison
- name: Fetch main branch
run: git fetch origin main
# Run pre-commit hooks
- name: Run pre-commit hooks
run: |
# Show pre-commit version
pre-commit --version
# Run pre-commit on all files changed between the current branch and main
- name: Run pre-commit on all changed files
run: |
# Get the list of files changed between the current branch and main
files=$(git diff --name-only origin/main)
if [ -n "$files" ]; then
pre-commit run --files $files
else
echo "No modified files to check."
fi