Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
test(travis): Added validate-commit-msg to Travis CI tests
  • Loading branch information
twolfson committed Mar 13, 2016
commit 8f2a9dd0a501f8eb4eab5f67d4677a57795eaf81
5 changes: 4 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ env:
- SAUCE_USERNAME: karmarunnerbot
- secure: "bRVY+hYZwMf1SqVnMyZRJTLD0gN1hLx9/MwO8MM/qBiu3YNjXy49XElfMdzMKN6cZeKTmhcnjmZonbJuI1PQ2t+utGkyjnlVLJ/OlWptreKLzIlcbt4hrdPoTcjmUTwDWq9Ex9cVoYX8AzCasETttpczp3P+s3+vmOUj8z25JyU="
- CXX=g++-4.8
include:
- node_js: "5"
env: VALIDATE_COMMIT_MSG=TRUE

# Make sure we have a new npm on Node 0.10. npm >= 2 should work so by not updating them
# here we have proper version coverage, especially that most people use the npm version
Expand All @@ -36,4 +39,4 @@ before_script:
- export $(openssl aes-256-cbc -pass env:CREDENTIALS_PASS -d -in credentials)

script:
- npm run travis
- 'if [ "${VALIDATE_COMMIT_MSG}" != "TRUE" ]; then npm run travis; else ./scripts/validate-commit-msg.sh "${TRAVIS_COMMIT}"; fi'
32 changes: 32 additions & 0 deletions scripts/validate-commit-msg.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/bash
#
# Validate commit message matches our expected format
#
# Arguments:
# <commit> Commit revision to validate
#
# Example:
# ./validate-commit-msg.sh abcdef0

# Exit on first error
set -e

# If we didn't receive a commit, then error out
# DEV: If want the HEAD commit, then use `git rev-parse HEAD`
COMMIT_REV="$1"
if [ -z "$COMMIT_REV" ]; then
echo "Expected a commit revision to validate but received nothing" 1>&2
exit 1
fi

# Resolve our file for output
# DEV: We use `.git` to avoid cluttering the working directory
GIT_DIR="$(git rev-parse --git-dir)"
TARGET_FILE="$GIT_DIR/VALIDATE_COMMIT_MSG"

# Output our log message to a file
# DEV: We use `--no-merges` to skip merge commits introduced by GitHub
git log --no-merges --format=format:"%s" -n 1 "$COMMIT_REV" > "$TARGET_FILE"

# Validate our message
./node_modules/.bin/validate-commit-msg "$TARGET_FILE"