|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +COMMIT_MSG_SCRIPT=$1 |
| 4 | + |
| 5 | +# build ci docs feat fix perf refactor style test chore |
| 6 | +allowed_commit_messages=("build: change build details" \ |
| 7 | + "ci: make continuous integration change" \ |
| 8 | + "docs: updates some documentation" \ |
| 9 | + "feat: implements a new feature" \ |
| 10 | + "fix: correct typo in function" \ |
| 11 | + "perf: improve perf" \ |
| 12 | + "refactor: implement a refactor" \ |
| 13 | + "style: make a style change" \ |
| 14 | + "test(ui): add a new test" \ |
| 15 | + "chore: complete a simple chore" \ |
| 16 | + "Revert \"test: add a new test\" " \ |
| 17 | + "Revert: \"refactor(labels): implement a refactor\" " \ |
| 18 | + "revert: \"feat: implements a new feature\" " \ |
| 19 | + "Merge branch 'feature-branch'" \ |
| 20 | + "merge branch 'Feature-Branch'" \ |
| 21 | + "0.1.0") |
| 22 | + |
| 23 | +disallowed_commit_messages=("implements a new feature" \ |
| 24 | + "" \ |
| 25 | + "docs: implements a new feature that we have been greatly anticipating") |
| 26 | + |
| 27 | +TMPFILE=$(mktemp) |
| 28 | +ERROR_FILE=$(mktemp) |
| 29 | +COUNT=0 |
| 30 | +for allowed_commit_message in "${allowed_commit_messages[@]}" |
| 31 | +do |
| 32 | + echo "$allowed_commit_message" > $TMPFILE |
| 33 | + $COMMIT_MSG_SCRIPT $TMPFILE |
| 34 | + # Track the number of failed tests |
| 35 | + if [[ "$?" != "0" ]] |
| 36 | + then |
| 37 | + COUNT=$(echo "$COUNT + 1" | bc -l) |
| 38 | + echo "---" |
| 39 | + fi |
| 40 | +done |
| 41 | + |
| 42 | +for disallowed_commit_message in "${disallowed_commit_messages[@]}" |
| 43 | +do |
| 44 | + echo "$disallowed_commit_message" > $TMPFILE |
| 45 | + # Since it passed, there is no error to be seen. |
| 46 | + $COMMIT_MSG_SCRIPT $TMPFILE >> $TMPFILE |
| 47 | + # Track the number of failed tests |
| 48 | + if [[ "$?" == "0" ]] |
| 49 | + then |
| 50 | + echo -e "\e[1;32mFailed: $disallowed_commit_message\003\e[0m" >> $ERROR_FILE |
| 51 | + COUNT=$(echo "$COUNT + 1" | bc -l) |
| 52 | + fi |
| 53 | +done |
| 54 | + |
| 55 | +# Print summary of the number of failed tests |
| 56 | +cat $ERROR_FILE |
| 57 | +if [[ $COUNT -eq 0 ]] |
| 58 | +then |
| 59 | + echo -e "\e[1;32m All tests passed!\033\e[0m" |
| 60 | +elif [[ $COUNT -eq 1 ]] |
| 61 | +then |
| 62 | + echo -e "\e[1;32m $COUNT test failed\033\e[0m" |
| 63 | +elif [[ $COUNT -gt 1 ]] |
| 64 | +then |
| 65 | + echo -e "\e[1;32m $COUNT tests failed\033\e[0m" |
| 66 | +fi |
| 67 | + |
| 68 | +# Cleanup |
| 69 | +rm $TMPFILE |
| 70 | +rm $ERROR_FILE |
0 commit comments