Last active
April 17, 2020 23:48
-
-
Save jsullivanlive/e879efec3bce3ee2f400efc778c9946b to your computer and use it in GitHub Desktop.
incremental deploy for salesforce metadata
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 | |
# TODO don't do master, do wherever the PR is going to? | |
# TODO validate that there were diffs? | |
# needed or diff will not be based on our current git | |
Echo "********** RESETTING GIT FOR CLEAN DIFF **********" | |
git reset --hard | |
ZIPFILE=diff-archive.zip | |
if test -f $ZIPFILE ; then | |
echo "********** REMOVING OLD ARCHIVE **********" | |
rm $ZIPFILE | |
fi | |
# master deploys only since last merge | |
BRANCH=$(git rev-parse --abbrev-ref HEAD) | |
DIFF_TO="HEAD^" | |
# if you're not on master, then you want to test a diff from here to master, not the last commit | |
if [[ $BRANCH != "master" ]] ; then | |
DIFF_TO="..master" | |
fi | |
FILES_TO_DEPLOY=$(git diff --name-only $DIFF_TO src/) | |
FILES_TO_ADD=() | |
for f in $FILES_TO_DEPLOY ; do | |
if !(test -f $f) ; then | |
# skipping file that doesn't exist, we most likely deleted it | |
continue | |
fi | |
FILES_TO_ADD+=($f) | |
if [[ $f == *"-meta.xml"* ]]; then | |
f_without_meta=${f/'-meta.xml'/''} | |
if test -f $f_without_meta ; then | |
FILES_TO_ADD+=($f_without_meta) | |
fi | |
else | |
f_with_meta="$f-meta.xml" | |
if test -f $f_with_meta ; then | |
FILES_TO_ADD+=($f_with_meta) | |
fi | |
fi | |
done | |
echo "********** FILES TO DEPLOY **********" | |
printf "%s\n" "${FILES_TO_ADD[@]}" | sort -u | |
FILES_TO_DEPLOY=$(printf "%s\n" "${FILES_TO_ADD[@]}" | sort -u) | |
echo "********** CREATING ARCHIVE ZIP **********" | |
git archive -o $ZIPFILE HEAD $FILES_TO_DEPLOY | |
echo "********** RESETTING SRC FOLDER **********" | |
rm -fr src/ | |
mkdir src | |
# we need the package.xml file with api version | |
git checkout src/package.xml | |
unzip $ZIPFILE | |
echo "********** TESTING **********" | |
ant test | |
# TODO ant deploy? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment