-
Notifications
You must be signed in to change notification settings - Fork 0
64 lines (61 loc) · 2.37 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
name: pre-commit
on:
pull_request:
branches:
- "16.0*"
push:
branches:
- "16.0"
- "16.0-develop"
- "release/*"
jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
with:
python-version: "3.11"
- name: Get python version
run: echo "PY=$(python -VV | sha256sum | cut -d' ' -f1)" >> $GITHUB_ENV
- uses: actions/cache@v1
with:
path: ~/.cache/pre-commit
key: pre-commit|${{ env.PY }}|${{ hashFiles('.pre-commit-config.yaml') }}
- name: Install pre-commit
run: pip install pre-commit
- name: Get target branch name
run: echo "TARGET_BRANCH_NAME=${{ github.event.pull_request.base.ref }}" >> $GITHUB_ENV
- name: Enforce target branch can not be main branch
run: |
if [[ "${TARGET_BRANCH_NAME}" =~ \.0$ ]]; then
echo "Error: Target branch can not be a Main version branch."
exit 1
fi
- name: Run pre-commit
run: pre-commit run --all-files --show-diff-on-failure --color=always || exit 1
- name: Check that all files generated by pre-commit are in git
run: |
newfiles="$(git ls-files --others --exclude-from=.gitignore)"
if [ "$newfiles" != "" ] ; then
echo "Please check-in the following files:"
echo "$newfiles"
exit 1
fi
- name: Post pre-commit failure comment and add label
if: failure()
run: |
# Add label
curl -X POST -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/labels \
-d '{
"labels": ["Needs Fixing"]
}'
# Post comment
curl -X POST -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.pull_request.number }}/comments \
-d '{
"body": "Pre-commit checks failed. The label Needs Fixing has been added. Please review and fix the issues."
}'