test: Ensure github CI tests commit messages
Without this patch, the travis var is empty, and we just pass. This is a problem, as we are using github CI nowadays. This should fix it.
This commit is contained in:
committed by
James Shubin
parent
7f3970541b
commit
4511c54fad
@@ -10,55 +10,55 @@ echo running "$0"
|
||||
ROOT=$(dirname "${BASH_SOURCE}")/..
|
||||
cd "${ROOT}" || exit 1
|
||||
|
||||
travis_regex='^\([a-z0-9]\(\(, \)\|[a-z0-9]\)\+[a-z0-9]: \)\+[A-Z0-9][^:]\+[^:.]$'
|
||||
commit_title_regex='^\([a-z0-9]\(\(, \)\|[a-z0-9]\)\+[a-z0-9]: \)\+[A-Z0-9][^:]\+[^:.]$'
|
||||
|
||||
# Testing the regex itself.
|
||||
|
||||
# Correct patterns.
|
||||
[[ $(echo "foo, bar: Bar" | grep -c "$travis_regex") -eq 1 ]]
|
||||
[[ $(echo "foo: Bar" | grep -c "$travis_regex") -eq 1 ]]
|
||||
[[ $(echo "f1oo, b2ar: Bar" | grep -c "$travis_regex") -eq 1 ]]
|
||||
[[ $(echo "2foo: Bar" | grep -c "$travis_regex") -eq 1 ]]
|
||||
[[ $(echo "foo: bar: Barfoo" | grep -c "$travis_regex") -eq 1 ]]
|
||||
[[ $(echo "foo: bar, foo: Barfoo" | grep -c "$travis_regex") -eq 1 ]]
|
||||
[[ $(echo "foo: bar, foo: Barfoo" | grep -c "$travis_regex") -eq 1 ]]
|
||||
[[ $(echo "resources: augeas: New resource" | grep -c "$travis_regex") -eq 1 ]]
|
||||
[[ $(echo "foo, bar: Bar" | grep -c "$commit_title_regex") -eq 1 ]]
|
||||
[[ $(echo "foo: Bar" | grep -c "$commit_title_regex") -eq 1 ]]
|
||||
[[ $(echo "f1oo, b2ar: Bar" | grep -c "$commit_title_regex") -eq 1 ]]
|
||||
[[ $(echo "2foo: Bar" | grep -c "$commit_title_regex") -eq 1 ]]
|
||||
[[ $(echo "foo: bar: Barfoo" | grep -c "$commit_title_regex") -eq 1 ]]
|
||||
[[ $(echo "foo: bar, foo: Barfoo" | grep -c "$commit_title_regex") -eq 1 ]]
|
||||
[[ $(echo "foo: bar, foo: Barfoo" | grep -c "$commit_title_regex") -eq 1 ]]
|
||||
[[ $(echo "resources: augeas: New resource" | grep -c "$commit_title_regex") -eq 1 ]]
|
||||
|
||||
# Space required after :
|
||||
[[ $(echo "foo:bar" | grep -c "$travis_regex") -eq 0 ]]
|
||||
[[ $(echo "foo:bar" | grep -c "$commit_title_regex") -eq 0 ]]
|
||||
|
||||
# First char must be a a-z0-9
|
||||
[[ $(echo ", bar: bar" | grep -c "$travis_regex") -eq 0 ]]
|
||||
[[ $(echo ", bar: bar" | grep -c "$commit_title_regex") -eq 0 ]]
|
||||
|
||||
# Last char before : must be a a-z0-9
|
||||
[[ $(echo "foo, : bar" | grep -c "$travis_regex") -eq 0 ]]
|
||||
[[ $(echo "foo, : bar" | grep -c "$commit_title_regex") -eq 0 ]]
|
||||
|
||||
# Last char before : must be a a-z0-9
|
||||
[[ $(echo "foo,: bar" | grep -c "$travis_regex") -eq 0 ]]
|
||||
[[ $(echo "foo,: bar" | grep -c "$commit_title_regex") -eq 0 ]]
|
||||
|
||||
# No caps
|
||||
[[ $(echo "Foo: bar" | grep -c "$travis_regex") -eq 0 ]]
|
||||
[[ $(echo "Foo: bar" | grep -c "$commit_title_regex") -eq 0 ]]
|
||||
|
||||
# No dot at the end of the message.
|
||||
[[ $(echo "foo: bar." | grep -c "$travis_regex") -eq 0 ]]
|
||||
[[ $(echo "foo: bar." | grep -c "$commit_title_regex") -eq 0 ]]
|
||||
|
||||
# Capitalize the first word after :
|
||||
[[ $(echo "foo: bar" | grep -c "$travis_regex") -eq 0 ]]
|
||||
[[ $(echo "foo: bar" | grep -c "$commit_title_regex") -eq 0 ]]
|
||||
|
||||
# More than one char is required before :
|
||||
[[ $(echo "a: bar" | grep -c "$travis_regex") -eq 0 ]]
|
||||
[[ $(echo "a: bar" | grep -c "$commit_title_regex") -eq 0 ]]
|
||||
|
||||
# Run checks agains multiple :.
|
||||
[[ $(echo "a: bar:" | grep -c "$travis_regex") -eq 0 ]]
|
||||
[[ $(echo "a: bar, fooX: Barfoo" | grep -c "$travis_regex") -eq 0 ]]
|
||||
[[ $(echo "a: bar, foo: barfoo foo: Nope" | grep -c "$travis_regex") -eq 0 ]]
|
||||
[[ $(echo "nope a: bar, foo: barfoofoo: Nope" | grep -c "$travis_regex") -eq 0 ]]
|
||||
[[ $(echo "a: bar:" | grep -c "$commit_title_regex") -eq 0 ]]
|
||||
[[ $(echo "a: bar, fooX: Barfoo" | grep -c "$commit_title_regex") -eq 0 ]]
|
||||
[[ $(echo "a: bar, foo: barfoo foo: Nope" | grep -c "$commit_title_regex") -eq 0 ]]
|
||||
[[ $(echo "nope a: bar, foo: barfoofoo: Nope" | grep -c "$commit_title_regex") -eq 0 ]]
|
||||
|
||||
test_commit_message() {
|
||||
echo "Testing commit message $1"
|
||||
if ! git log --format=%s $1 | head -n 1 | grep -q "$travis_regex"
|
||||
if ! git log --format=%s $1 | head -n 1 | grep -q "$commit_title_regex"
|
||||
then
|
||||
echo "FAIL: Commit message should match the following regex: '$travis_regex'"
|
||||
echo "FAIL: Commit message should match the following regex: '$commit_title_regex'"
|
||||
echo
|
||||
echo "eg:"
|
||||
echo "prometheus: Implement rest api"
|
||||
@@ -116,6 +116,16 @@ then
|
||||
commits=$(git log --format=%H origin/${TRAVIS_BRANCH}..${TRAVIS_PULL_REQUEST_SHA})
|
||||
[[ -n "$commits" ]]
|
||||
|
||||
for commit in $commits
|
||||
do
|
||||
test_commit_message $commit
|
||||
test_commit_message_common_bugs $commit
|
||||
done
|
||||
elif [[ -n "$GITHUB_SHA" ]]
|
||||
then
|
||||
commits=$(git log --no-merges --format=%H origin/${GITHUB_BASE_REF}..${GITHUB_SHA})
|
||||
[[ -n "$commits" ]]
|
||||
|
||||
for commit in $commits
|
||||
do
|
||||
test_commit_message $commit
|
||||
|
||||
Reference in New Issue
Block a user