Last active
August 29, 2015 14:07
-
-
Save jimmygle/f942894a6d08c7fb9db1 to your computer and use it in GitHub Desktop.
Generates a diff between two commit hashes after a build process (ie grunt, npm install, etc)
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 | |
# Static config | |
CMD_GIT="/usr/bin/git"; | |
CMD_NPMPRUNE="/usr/bin/npm prune"; | |
CMD_NPMCACHECLEAN="/usr/bin/npm cache clean"; | |
CMD_NPMINSTALL="/usr/bin/npm install"; | |
CMD_GRUNT="/usr/bin/grunt"; | |
DIR_A="a"; | |
DIR_B="b"; | |
DIR_DIFF="diff"; | |
# User input config | |
printf "Path to build everything in: "; read -r PROJECT_DIRECTORY; | |
printf "Remote repo URL: "; read -r REMOTE_REPO; | |
printf "First (older) commit hash: "; read -r REMOTE_HASH_A; | |
printf "Second (newer) commit hash: "; read -r REMOTE_HASH_B; | |
# Create project directory | |
mkdir -p $PROJECT_DIRECTORY; cd $PROJECT_DIRECTORY; | |
# Pull remote repos, checkout respective commits | |
$CMD_GIT clone --recursive $REMOTE_REPO $DIR_A; cp -r $DIR_A $DIR_B; | |
cd $DIR_A; git checkout $REMOTE_HASH_A; cd ..; | |
cd $DIR_B; git checkout $REMOTE_HASH_B; cd ..; | |
# Build both projects | |
cd $DIR_A; $CMD_NPMPRUNE; $CMD_NPMCACHECLEAN; $CMD_NPMINSTALL; $CMD_GRUNT; cd ..; | |
cd $DIR_B; $CMD_NPMPRUNE; $CMD_NPMCACHECLEAN; $CMD_NPMINSTALL; $CMD_GRUNT; cd ..; | |
# Create new diff repo, move deploy folders into their own branches | |
mkdir -p $DIR_DIFF; cd $DIR_DIFF; | |
$CMD_GIT init; | |
mv ../$DIR_A/deploy/* .; | |
$CMD_GIT add -A && $CMD_GIT commit -m "A"; | |
$CMD_GIT branch b && $CMD_GIT checkout b; rm -rf *; | |
mv ../$DIR_B/deploy/* .; | |
$CMD_GIT add -A && $CMD_GIT commit -m "B"; | |
# Generate diff file and perform clean up | |
$CMD_GIT diff master...b > ../diff.txt; | |
echo "\n\nDIFF SUCCESSFULLY GENERATED... beginning cleanup\n\n"; | |
cd ..; rm -rf $DIR_A $DIR_B $DIR_DIFF; | |
echo "\n\nCLEANUP SUCCESSFUL... diff available in $PROJECT_DIRECTORY/diff.txt\n\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment