2024-04-08 15:47:44 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
set -euo pipefail
|
|
|
|
|
|
|
|
parse_commits() {
|
2024-08-14 18:55:09 +00:00
|
|
|
|
|
|
|
BASE_BRANCH=${BASE_BRANCH:-develop}
|
|
|
|
|
2024-08-13 09:58:48 +00:00
|
|
|
start_commit=${1:-origin/${BASE_BRANCH}}
|
2024-04-08 15:47:44 +00:00
|
|
|
end_commit=${2:-HEAD}
|
|
|
|
is_breaking_change=false
|
2024-08-27 21:42:06 +00:00
|
|
|
exit_code=0
|
2024-04-08 15:47:44 +00:00
|
|
|
|
2024-08-27 21:42:06 +00:00
|
|
|
echo "checking commits between: $start_commit $end_commit"
|
2024-04-08 15:47:44 +00:00
|
|
|
# Run the loop in the current shell using process substitution
|
|
|
|
while IFS= read -r message || [ -n "$message" ]; do
|
|
|
|
# Check if commit message follows conventional commits format
|
|
|
|
if [[ $message =~ ^(build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test)(\(.*\))?(\_|!):.*$ ]]; then
|
|
|
|
# Check for breaking changes
|
|
|
|
if [[ ${BASH_REMATCH[3]} == *'!'* ]]; then
|
|
|
|
is_breaking_change=true
|
|
|
|
fi
|
|
|
|
else
|
2024-08-27 21:42:06 +00:00
|
|
|
echo "Commit message \"$message\" is not well-formed"
|
|
|
|
exit_code=1
|
2024-04-08 15:47:44 +00:00
|
|
|
fi
|
2024-04-10 11:04:55 +00:00
|
|
|
done < <(git log --format=%s "$start_commit".."$end_commit")
|
2024-04-08 15:47:44 +00:00
|
|
|
|
2024-08-27 21:42:06 +00:00
|
|
|
if [[ $exit_code -ne 0 ]]; then
|
|
|
|
exit ${exit_code}
|
|
|
|
fi
|
|
|
|
|
2024-04-08 15:47:44 +00:00
|
|
|
echo "$is_breaking_change"
|
|
|
|
}
|
|
|
|
|
2024-08-13 09:58:48 +00:00
|
|
|
parse_commits "$@"
|