ci: add commit message check

This commit is contained in:
Jan Komarek
2024-02-13 14:06:36 +01:00
committed by Jan Komárek
parent 5f17a363a7
commit 2b6fbd9a4e
5 changed files with 31 additions and 27 deletions

View File

@@ -1,23 +0,0 @@
#!/bin/bash
# check whether there was a change to libs that need to be built
for path in "packages/components" "packages/blockchain-link" "packages/suite-storage"
do
diff="$(git diff HEAD^ --name-only --diff-filter=ACMR "$path")"
if [ ! -z "$diff" ]
then
yarn build:libs
fi
done
# check whether yarn.lock changed and if yes call yarn install
for path in "yarn.lock"
do
diff="$(git diff HEAD^ --name-only --diff-filter=ACMR "$path")"
if [ ! -z "$diff" ]
then
yarn
fi
done

View File

@@ -0,0 +1,12 @@
name: "[Check]: Commit messages"
on: [pull_request]
jobs:
commit-message-check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Check commit messages
run: ./scripts/check-commit-messages.sh

View File

@@ -1,6 +1,6 @@
# Commits
Using [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) is strongly recommended and might be enforced in future.
Using [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) is enforced by a CI check.
### Examples
@@ -12,7 +12,7 @@ feat(lang): added polish language
### Git hook
Use this git hook to auto-check your commit messages. Save the following snippet into `.git/hooks/commit-msg`
Use this git hook to auto-check your commit messages. Save the following snippet into `.git/hooks/commit-msg`. This way, the check will run locally and can avoid some unnecessary CI runs.
```bash
#!/bin/sh
@@ -23,7 +23,7 @@ if echo "$commit_msg" | grep -qE "^(Revert|fixup! )"; then
exit 0
fi
if ! grep -qE "^(build|ci|docs|feat|fix|perf|refactor|style|test|chore|revert)(\([a-z\-]+\))?: " "$1" ; then
if ! grep -qE "^(build|ci|docs|feat|fix|perf|refactor|style|test|chore|revert)(\([a-z, -]+\))?: " "$1" ; then
echo "Conventional Commits validation failed"
exit 1
fi

View File

@@ -51,7 +51,7 @@ Run a dev build:
Inspired by [GitLab Contributing Guide](https://docs.gitlab.com/ee/development/contributing/)
Using [Conventional Commits](COMMITS.md) is strongly recommended.
Using [Conventional Commits](COMMITS.md) is required.
## Security vulnerability disclosure

View File

@@ -0,0 +1,15 @@
#!/usr/bin/env bash
for commit in $(git rev-list origin/HEAD..HEAD); do
commit_msg=$(git log --format=%B -n 1 "$commit")
# Skip validation in case of fixup and revert commits
if echo "$commit_msg" | grep -qE "^(Revert|fixup! )"; then
continue
fi
if ! echo "$commit_msg" | grep -qE "^(build|ci|docs|feat|fix|perf|refactor|style|test|chore|revert)(\([a-z, -]+\))?: "; then
echo "Conventional Commits validation failed for commit $commit: $commit_msg"
exit 1
fi
done