forked from pcdshub/pcds-ci-helpers
-
Notifications
You must be signed in to change notification settings - Fork 0
93 lines (83 loc) · 2.67 KB
/
pre-commit.yml
File metadata and controls
93 lines (83 loc) · 2.67 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
name: pre-commit check
# Based on our old pre-commit check and the official action:
# https://github.com/pre-commit/action
on:
workflow_call:
inputs:
args:
default: "--all-files --show-diff-on-failure"
description: "Additional flags for pre-commit"
required: false
type: string
annotate:
default: true
description: "Use the problem matcher to annotate the PR diff"
required: false
type: boolean
jobs:
pre-commit:
runs-on: [ubuntu-20.04, self-hosted]
steps:
- uses: actions/checkout@v4
- name: Configure the matcher to annotate the diff
if: ${{ inputs.annotate }}
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 \
${{ inputs.args }}