@@ -11,11 +11,16 @@ jobs:
11
11
runs-on : ubuntu-latest
12
12
steps :
13
13
- uses : actions/checkout@v3
14
+ with : # for gitlint
15
+ ref : ${{ github.event.pull_request.head.sha }}
16
+ fetch-depth : 0
14
17
- uses : actions/setup-python@v4
15
18
with :
16
19
python-version : " >=3.7"
17
20
cache : pip
18
- cache-dependency-path : test/requirements*.txt
21
+ cache-dependency-path : |
22
+ .github/requirements.txt
23
+ test/requirements*.txt
19
24
- uses : actions/cache@v3
20
25
with :
21
26
path : ~/.cache/pre-commit
@@ -24,54 +29,13 @@ jobs:
24
29
run : |
25
30
python3 -m venv venv # for venv-run
26
31
source venv/bin/activate
27
- python3 -m pip install -Ur test/requirements-dev.txt
28
- - name : Run checks
32
+ python3 -m pip install -Ur .github/requirements.txt
33
+ - run : venv/bin/gitlint --commits "origin/$GITHUB_BASE_REF..HEAD"
34
+ if : github.event_name == 'pull_request'
35
+ - name : Run pre-commit checks
29
36
run : |
30
37
source venv/bin/activate
31
-
32
- # Commit message checks
33
-
34
- tmpdir=$(mktemp -d)
35
- trap "rm -r '$tmpdir'" EXIT
36
- commits_json=$tmpdir/commits.json
37
- commit_txt=$tmpdir/message.txt
38
-
39
- # For push, commits are available directly in github.event.commits.
40
- # For pull_request they're not: grab them from API, transform fields
41
- # we want to a similar structure as pushes are.
42
- if [[ "${{github.event.commits}}" ]]; then
43
- cat <<\EOF >"$commits_json"
44
- ${{toJSON(github.event.commits)}}
45
- EOF
46
- else
47
- curl -fSsL ${{github.event.pull_request.commits_url}} | \
48
- jq '[.[] | {id: .sha, message: .commit.message}]' >"$commits_json"
49
- fi
50
-
51
- git config user.name $(git log -1 --format=format:%an)
52
- git config user.email $(git log -1 --format=format:%ae)
53
- rc=0
54
- for id in $(jq --raw-output '.[].id' <"$commits_json"); do
55
- jq --raw-output ".[] | select(.id==\"$id\") | .message" \
56
- <"$commits_json" >"$commit_txt"
57
- echo "Linting commit $id message..."
58
- set +e
59
- pre-commit run gitlint \
60
- --color=always \
61
- --hook-stage=commit-msg \
62
- --commit-msg-filename="$commit_txt"
63
- ((rc+=$?))
64
- set -e
65
- done
66
-
67
- # Other pre-commit checks
68
-
69
- set +e
70
38
pre-commit run --color=always --all-files --show-diff-on-failure
71
- ((rc+=$?))
72
- set -e
73
-
74
- exit $rc
75
39
76
40
distcheck :
77
41
runs-on : ubuntu-latest
0 commit comments