Skip to content

Commit 3f2ccc9

Browse files
authored
Merge pull request #877 from scop/chore/gitlint-config
chore(gitlint): simplify config
2 parents 780d373 + d21fb93 commit 3f2ccc9

File tree

4 files changed

+18
-47
lines changed

4 files changed

+18
-47
lines changed

.github/renovate.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@
4444
"versioning": "pep440",
4545
"groupName": "flake8"
4646
},
47+
{
48+
"matchPackagePatterns": ["(^|/)gitlint$"],
49+
"versioning": "pep440",
50+
"groupName": "gitlint"
51+
},
4752
{
4853
"matchPackagePatterns": ["(^|/)isort$"],
4954
"versioning": "pep440",

.github/requirements.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
-r ../test/requirements-dev.txt
2+
3+
gitlint ==0.18.0

.github/workflows/ci.yaml

Lines changed: 10 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,16 @@ jobs:
1111
runs-on: ubuntu-latest
1212
steps:
1313
- uses: actions/checkout@v3
14+
with: # for gitlint
15+
ref: ${{ github.event.pull_request.head.sha }}
16+
fetch-depth: 0
1417
- uses: actions/setup-python@v4
1518
with:
1619
python-version: ">=3.7"
1720
cache: pip
18-
cache-dependency-path: test/requirements*.txt
21+
cache-dependency-path: |
22+
.github/requirements.txt
23+
test/requirements*.txt
1924
- uses: actions/cache@v3
2025
with:
2126
path: ~/.cache/pre-commit
@@ -24,54 +29,13 @@ jobs:
2429
run: |
2530
python3 -m venv venv # for venv-run
2631
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
2936
run: |
3037
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
7038
pre-commit run --color=always --all-files --show-diff-on-failure
71-
((rc+=$?))
72-
set -e
73-
74-
exit $rc
7539
7640
distcheck:
7741
runs-on: ubuntu-latest

.pre-commit-config.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ repos:
66
rev: v0.18.0
77
hooks:
88
- id: gitlint
9-
stages: [commit-msg]
109

1110
- repo: https://github.com/scop/pre-commit-shfmt
1211
rev: v3.6.0-1

0 commit comments

Comments
 (0)