Last active
December 12, 2016 20:45
-
-
Save kimniche/6da55d41f26b5d3170b2fa58b14ef8a0 to your computer and use it in GitHub Desktop.
Safety net: 1) asks user to confirm that files have been linted, and 2) enforces passing tests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Confirm we actually have commits to push | |
commits=`git log @{u}..` | |
if [ -z "$commits" ]; then | |
exit 0 | |
fi | |
LOG="[pre-push]" | |
# --- | |
# CHECK 1: confirm linted files | |
# --- | |
# TODO: eventually we want to truly | |
# perform the check, | |
# (some combo of git diff/tree/grep) | |
# but for now the question confirm will do. | |
# --- | |
tput setaf 3 | |
read -p "$LOG You're about to push, are all touched files linted? (y/n) " -n 1 -r < /dev/tty | |
echo | |
if [[ $REPLY =~ ^[Nn]$ ]]; then | |
tput setaf 7 | |
exit 1 # Push will fail | |
fi | |
# --- | |
# CHECK 2: all tests pass | |
# --- | |
# Get OX-specific test command | |
# Assume not Mac OSX by default | |
TEST_CMD="npm run test:nowatch-win" | |
if [[ $OSTYPE == darwin* ]]; then | |
TEST_CMD="npm run test:nowatch" | |
fi | |
tput setaf 6; echo "$LOG Running tests with \`$TEST_CMD\`" | |
tput setaf 7 | |
$TEST_CMD | |
RESULT=$? | |
if [ $RESULT -ne 0 ]; then | |
tput setaf 1; echo "$LOG Some tests failed, not pushing" | |
tput setaf 7 | |
exit 1 | |
else | |
tput setaf 2; echo "$LOG Tests passing!" | |
fi | |
tput setaf 7 | |
# Exit status code 1 is error and will prevent push | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment