Skip to content

Instantly share code, notes, and snippets.

@yifeiwu
Last active May 16, 2019 05:40
Show Gist options
  • Save yifeiwu/e71fc6025986374c9cc55844d1699fed to your computer and use it in GitHub Desktop.
Save yifeiwu/e71fc6025986374c9cc55844d1699fed to your computer and use it in GitHub Desktop.
Shell script to only run rubocop on changed files
#!/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