From bdbc4786048924c02db46e00c4dd2175d6215690 Mon Sep 17 00:00:00 2001 From: Todd Wolfson Date: Sun, 13 Mar 2016 17:58:13 -0500 Subject: [PATCH] test(travis): Added validate-commit-msg to Travis CI tests --- .travis.yml | 51 ++++++++++++++++++---------------- scripts/validate-commit-msg.sh | 31 +++++++++++++++++++++ 2 files changed, 58 insertions(+), 24 deletions(-) create mode 100755 scripts/validate-commit-msg.sh diff --git a/.travis.yml b/.travis.yml index 7678b5cf7..2cdfe7975 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,16 +1,19 @@ sudo: false language: node_js -node_js: - - "0.10" - - "0.12" - - "4" - - "5" +# node_js: +# - "0.10" +# - "0.12" +# - "4" +# - "5" env: - global: - - SAUCE_USERNAME: karmarunnerbot - - secure: "bRVY+hYZwMf1SqVnMyZRJTLD0gN1hLx9/MwO8MM/qBiu3YNjXy49XElfMdzMKN6cZeKTmhcnjmZonbJuI1PQ2t+utGkyjnlVLJ/OlWptreKLzIlcbt4hrdPoTcjmUTwDWq9Ex9cVoYX8AzCasETttpczp3P+s3+vmOUj8z25JyU=" - - CXX=g++-4.8 + # global: + # - 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 @@ -18,22 +21,22 @@ env: before_install: - '[ "${TRAVIS_NODE_VERSION}" != "0.10" ] || npm install -g npm' - npm config set loglevel warn - - g++-4.8 --version + # - g++-4.8 --version -addons: - firefox: - "latest" - apt: - sources: - - ubuntu-toolchain-r-test - packages: - - g++-4.8 +# addons: +# firefox: +# "latest" +# apt: +# sources: +# - ubuntu-toolchain-r-test +# packages: +# - g++-4.8 -before_script: - - export DISPLAY=:99.0 - - sh -e /etc/init.d/xvfb start - - npm run init - - export $(openssl aes-256-cbc -pass env:CREDENTIALS_PASS -d -in credentials) +# before_script: +# - export DISPLAY=:99.0 +# - sh -e /etc/init.d/xvfb start +# - npm run init +# - 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' diff --git a/scripts/validate-commit-msg.sh b/scripts/validate-commit-msg.sh new file mode 100755 index 000000000..38b24be6b --- /dev/null +++ b/scripts/validate-commit-msg.sh @@ -0,0 +1,31 @@ +#!/bin/bash +# +# Validate commit message matches our expected format +# +# Arguments: +# 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 +git log --format=format:"%s" -n 1 "$COMMIT_REV" > "$TARGET_FILE" + +# Validate our message +./node_modules/.bin/validate-commit-msg "$TARGET_FILE"