-
Notifications
You must be signed in to change notification settings - Fork 5
81 lines (71 loc) · 2.3 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
name: pre-commit check
# Based on https://github.com/pcdshub/pcds-ci-helpers/blob/master/.github/workflows/pre-commit.yml
on:
push:
pull_request:
jobs:
pre-commit:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v4
- name: Configure the matcher to annotate the diff
run: |
# Ref: https://github.com/actions/toolkit/blob/main/docs/problem-matchers.md
cat > "$HOME/flake8_problem_matcher.json" <<'EOF'
{
"problemMatcher": [
{
"owner": "flake8_error",
"severity": "error",
"pattern": [
{
"regexp": "^(.+):(\\d+):(\\d+): (E\\d+) (.+)$",
"file": 1,
"line": 2,
"column": 3,
"code": 4,
"message": 5
}
]
},
{
"owner": "flake8_warning",
"severity": "warning",
"pattern": [
{
"regexp": "^(.+):(\\d+):(\\d+): (W\\d+) (.+)$",
"file": 1,
"line": 2,
"column": 3,
"code": 4,
"message": 5
}
]
}
]
}
EOF
echo "::add-matcher::$HOME/flake8_problem_matcher.json"
- name: Install pre-commit
run: |
python -m pip install pre-commit
- name: List Python package versions
run: |
python -m pip freeze --local
- name: Check for pre-commit configuration
run: |
if [ ! -f ".pre-commit-config.yaml" ]; then
echo "::error::No pre-commit configuration found!"
exit 1
fi
- name: Switch to temporary branch
run: |
# This is to avoid no-commit-to-branch from failing us when this is run
# on master.
git checkout -b _pre_commit_check_branch
- name: Check pre-commit usage
run: |
pre-commit run \
--show-diff-on-failure \
--color=always \
--all-files