Skip to content

Commit be77666

Browse files
committedJan 12, 2024
ci(commitlint): addition of commit message linter (#767)
Adds commitlint to check the commit message style against agreed conventional commits configuration. Changes script argument values to always use linter names (e.g. shellcheck). Changes argument handling to allow only one checking action that can now accept further optional arguments.
1 parent 0b6e631 commit be77666

File tree

4 files changed

+86
-69
lines changed

4 files changed

+86
-69
lines changed
 

‎.commitlintrc.yaml

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
rules:
2+
body-case: [2, always, sentence-case]
3+
body-full-stop: [2, always]
4+
body-leading-blank: [2, always]
5+
body-max-line-length: [2, always, 72]
6+
footer-leading-blank: [2, always]
7+
footer-max-line-length: [2, always, 72]
8+
header-max-length: [2, always, 72]
9+
scope-case: [2, always, lower-case]
10+
subject-case:
11+
- 2
12+
- never
13+
- [pascal-case, sentence-case, start-case, upper-case]
14+
subject-empty: [2, never]
15+
subject-full-stop: [2, never, "."]
16+
type-case: [2, always, lower-case]
17+
type-empty: [2, never]
18+
type-enum:
19+
- 2
20+
- always
21+
- [build, chore, ci, docs, feat, fix, perf, refactor, style, test]

‎.github/workflows/ci.yml

+28-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# This file is part of REANA.
2-
# Copyright (C) 2020 CERN.
2+
# Copyright (C) 2020, 2024 CERN.
33
#
44
# REANA is free software; you can redistribute it and/or modify it
55
# under the terms of the MIT License; see LICENSE file for more details.
@@ -9,6 +9,32 @@ name: CI
99
on: [push, pull_request]
1010

1111
jobs:
12+
lint-commitlint:
13+
runs-on: ubuntu-20.04
14+
steps:
15+
- name: Checkout
16+
uses: actions/checkout@v3
17+
with:
18+
fetch-depth: 0
19+
20+
- name: Setup Node
21+
uses: actions/setup-node@v4
22+
23+
- name: Install commitlint
24+
run: |
25+
npm install conventional-changelog-conventionalcommits
26+
npm install commitlint@latest
27+
28+
- name: Check commit message compliance of the recently pushed commit
29+
if: github.event_name == 'push'
30+
run: |
31+
./run-tests.sh --check-commitlint HEAD~1 HEAD
32+
33+
- name: Check commit message compliance of the pull request
34+
if: github.event_name == 'pull_request'
35+
run: |
36+
./run-tests.sh --check-commitlint ${{ github.event.pull_request.head.sha }}~${{ github.event.pull_request.commits }} ${{ github.event.pull_request.head.sha }}
37+
1238
lint-shellcheck:
1339
runs-on: ubuntu-20.04
1440
steps:
@@ -18,7 +44,7 @@ jobs:
1844
- name: Runs shell script static analysis
1945
run: |
2046
sudo apt-get install shellcheck
21-
./run-tests.sh --check-shellscript
47+
./run-tests.sh --check-shellcheck
2248
2349
lint-black:
2450
runs-on: ubuntu-20.04

‎run-tests.sh

+37-22
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,34 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
22
#
33
# This file is part of REANA.
4-
# Copyright (C) 2017, 2018, 2019, 2020, 2021 CERN.
4+
# Copyright (C) 2017, 2018, 2019, 2020, 2021, 2024 CERN.
55
#
66
# REANA is free software; you can redistribute it and/or modify it
77
# under the terms of the MIT License; see LICENSE file for more details.
88

9-
# Quit on errors
109
set -o errexit
11-
12-
# Quit on unbound symbols
1310
set -o nounset
1411

15-
check_script () {
16-
shellcheck run-tests.sh
12+
check_commitlint () {
13+
from=${2:-master}
14+
to=${3:-HEAD}
15+
npx commitlint --from="$from" --to="$to"
16+
found=0
17+
while IFS= read -r line; do
18+
if echo "$line" | grep -qP "\(\#[0-9]+\)$"; then
19+
true
20+
else
21+
echo "✖ PR number missing in $line"
22+
found=1
23+
fi
24+
done < <(git log "$from..$to" --format="%s")
25+
if [ $found -gt 0 ]; then
26+
exit 1
27+
fi
28+
}
29+
30+
check_shellcheck () {
31+
find . -name "*.sh" -exec shellcheck {} \;
1732
}
1833

1934
check_black () {
@@ -45,7 +60,8 @@ check_helm () {
4560
}
4661

4762
check_all () {
48-
check_script
63+
check_commitlint
64+
check_shellcheck
4965
check_black
5066
check_flake8
5167
check_pydocstyle
@@ -60,17 +76,16 @@ if [ $# -eq 0 ]; then
6076
exit 0
6177
fi
6278

63-
for arg in "$@"
64-
do
65-
case $arg in
66-
--check-shellscript) check_script;;
67-
--check-black) check_black;;
68-
--check-flake8) check_flake8;;
69-
--check-pydocstyle) check_pydocstyle;;
70-
--check-manifest) check_manifest;;
71-
--check-sphinx) check_sphinx;;
72-
--check-pytest) check_pytest;;
73-
--check-helm) check_helm;;
74-
*)
75-
esac
76-
done
79+
arg="$1"
80+
case $arg in
81+
--check-commitlint) check_commitlint "$@";;
82+
--check-shellcheck) check_shellcheck;;
83+
--check-black) check_black;;
84+
--check-flake8) check_flake8;;
85+
--check-pydocstyle) check_pydocstyle;;
86+
--check-manifest) check_manifest;;
87+
--check-sphinx) check_sphinx;;
88+
--check-pytest) check_pytest;;
89+
--check-helm) check_helm;;
90+
*) echo "[ERROR] Invalid argument '$arg'. Exiting." && exit 1;;
91+
esac

‎scripts/update_images.sh

-45
This file was deleted.

0 commit comments

Comments
 (0)