Skip to content

Commit 6dc8549

Browse files
committed
ci: Add conventional commit check to Tekton linter
* Added a new script step (`conventional-commits`) to the Tekton linter pipeline (`.tekton/linter.yaml`). * Validated the format of the latest commit message using a regex check against the Conventional Commits standard. * Failed the pipeline run if the commit message did not conform to the specification. * Aimed to improve commit history clarity and enable automated changelog generation. Signed-off-by: Chmouel Boudjnah <chmouel@redhat.com>
1 parent e702071 commit 6dc8549

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

.tekton/linter.yaml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,32 @@ spec:
7777
pip3 install gitlint
7878
gitlint --commit "$(git log --format=format:%H --no-merges -1)" --ignore "Merge branch"
7979
80+
- name: conventional-commits
81+
displayName: "conventional commit check"
82+
image: registry.access.redhat.com/ubi9/python-312
83+
workingDir: $(workspaces.source.path)
84+
script: |
85+
set -x
86+
git config --global --add safe.directory /workspace/source
87+
base_sha="{{ body.pull_request.base.sha }}"
88+
# make sure we have a conventional commit
89+
invalid_commits=0
90+
while read -r commit_msg; do
91+
if ! echo "$commit_msg" | grep -E -q '^(feat|fix|docs|style|refactor|perf|test|build|ci|chore|revert)(\([a-z0-9-]+\))?:'; then
92+
echo "ERROR: Found commit message that does not follow conventional commit format:"
93+
echo "$commit_msg"
94+
invalid_commits=$((invalid_commits + 1))
95+
fi
96+
done < <(git log "${base_sha}..HEAD" --format=format:%s)
97+
98+
if [ $invalid_commits -gt 0 ]; then
99+
echo "ERROR: $invalid_commits commit(s) do not follow conventional commit format."
100+
echo "Expected format: type(scope): description"
101+
echo "Types: feat, fix, docs, style, refactor, perf, test, build, ci, chore, revert"
102+
echo "See: https://www.conventionalcommits.org/en/v1.0.0/#summary"
103+
exit 1
104+
fi
105+
80106
- name: yamllint
81107
displayName: "YAML Linter"
82108
image: cytopia/yamllint

0 commit comments

Comments
 (0)