-
Notifications
You must be signed in to change notification settings - Fork 1
59 lines (57 loc) · 2.24 KB
/
test.yaml
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
name: Test
on:
workflow_dispatch:
push:
branches:
- main
pull_request:
merge_group:
permissions:
id-token: write
pages: write
jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: pre-commit check
run: |
pip install pre-commit
ret=0
if [ "${{ github.event_name }}" == "push" ]
then
if [ "${{ github.event.created }}" == "true" ]
then
pre-commit run --all-files --show-diff-on-failure || ret=$?
else
git fetch origin ${{ github.event.before }}:old_head
pre-commit run --from-ref ${{ github.event.before }} --to-ref ${{ github.event.after }} --show-diff-on-failure || ret=$?
fi
elif [ "${{ github.event_name }}" == "pull_request" ]
then
if [ "${{ github.event.action }}" == "opened" ]
then
pre-commit run --from-ref ${{ github.event.pull_request.base.sha }} --to-ref ${{ github.event.pull_request.head.sha }} --show-diff-on-failure || ret=$?
elif [ "${{ github.event.action }}" == "synchronize" ]
then
git fetch origin ${{ github.event.before }}:old_head
pre-commit run --from-ref ${{ github.event.before }} --to-ref ${{ github.event.after }} --show-diff-on-failure || ret=$?
fi
elif [ "${{ github.event_name }}" == "merge_group" ]
then
git fetch origin ${{ github.event.merge_group.base_sha }}:old_head
pre-commit run --from-ref ${{ github.event.merge_group.base_sha }} --to-ref ${{ github.event.merge_group.head_sha }} --show-diff-on-failure || ret=$?
fi
if [ "$ret" != "0" ]
then
echo ''
echo '=== Code style issue detected! ==='
echo 'Suggest changes are listed above.'
echo 'Please install pre-commit and run `pre-commit run --all-files` to fix it.'
echo 'Strongly recommended to run `pre-commit install` to catch issues before pushing.'
echo 'You can learn more abour pre-commit from https://pre-commit.com/'
exit $ret
fi