Last active
May 16, 2019 05:40
-
-
Save yifeiwu/e71fc6025986374c9cc55844d1699fed to your computer and use it in GitHub Desktop.
Shell script to only run rubocop on changed files
This file contains 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 | |
set -e | |
run() { | |
echo "CHANGED_FILES=$(echo $CHANGED_FILES | tr ' ' ,)" | |
eval $1 | |
} | |
# Load changed files. | |
IFS=$'\n' | |
CHANGED_FILES=($(git diff $TRAVIS_COMMIT_RANGE --name-only | grep '\.rb$' | tr '\n' ' ')) | |
if [ ${#CHANGED_FILES[@]} -eq 0 ] | |
then | |
echo "No ruby files touched so nothing to cop" | |
else | |
run "bundle exec rubocop $CHANGED_FILES" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment