Skip to content

Instantly share code, notes, and snippets.

@dchambers
Last active February 14, 2024 02:57
Show Gist options
  • Save dchambers/b6a9b5cb503d23d0deee1cca5c8f5485 to your computer and use it in GitHub Desktop.
Save dchambers/b6a9b5cb503d23d0deee1cca5c8f5485 to your computer and use it in GitHub Desktop.
Perform a diff of the Shipcat region values between two Git branches: `Usage: shipcat-git-diff service branch1 branch2`
#!/bin/sh
function verifyService {
local service=$1
if [ ! -f "services/$service/shipcat.yml" ]; then
echo "No such service $service"
exit 1
fi
}
function verifyBranch {
local branch=$1
local branchCommit=$(git rev-parse --verify --quiet $branch)
if [ -z "$branchCommit" ]; then
echo "No such branch $branch"
exit 1
fi
}
function writeValues {
local branch=$1
git checkout -q $branch
regions=$(awk '/^regions:$/{flag=1;next}/^[^-]/{flag=0}flag' "services/$service/shipcat.yml" | sed "s/- //")
mkdir $tempDir/$branch
for region in $regions; do
shipcat values $service -r $region > $tempDir/$branch/$region
done
}
if [ "$#" -ne 3 ]; then
echo "Usage: shipcat-git-diff service branch1 branch2"
exit 1
fi
if [[ $(git diff --stat) != '' ]]; then
echo "You currently have uncommitted work. Maybe use 'git stash' first?"
exit 1
fi
service=$1
branch1=$2
branch2=$3
verifyService $service
verifyBranch $branch1
verifyBranch $branch2
if [ "$branch1" == "$branch2" ]; then
echo "Two distinct branch names must be used."
exit 1
fi
tempDir=`mktemp -d 2>/dev/null || mktemp -d -t 'mytmpdir'`
writeValues $branch1
writeValues $branch2
diff $tempDir/$branch1 $tempDir/$branch2 | sed "s~$tempDir/~~g"
rm -rf $tempDir
@clux
Copy link

clux commented Apr 9, 2019

shipcat diff {service} --git is now a similar feature that can be used without kube access.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment