Last active
March 22, 2024 18:41
-
-
Save shanerk/7767460b0adecace21aa97b4483a437c to your computer and use it in GitHub Desktop.
Deploy to Salesforce with GIT Changeset (-d flag runs against HEAD and default org with no confirmations)
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 | |
cleanExit() { | |
rm changes.txt* | |
exit | |
} | |
QUICK=false | |
while [[ $# -gt 0 ]]; do | |
case "$1" in | |
-d) | |
QUICK=true | |
shift | |
;; | |
--) | |
shift | |
break | |
;; | |
*) | |
echo "Invalid option: $1" | |
exit 1 ## Could be optional. | |
;; | |
esac | |
shift | |
done | |
if [ $QUICK != 'true' ] | |
then | |
## Get the default org | |
# echo "π Getting orgs..." | |
# DORG="" | |
# ORGS=$(sf org list) | |
# echo $ORGS | |
# set -o noglob | |
# IFS=$'\n' arr=($ORGS) | |
# set +o noglob | |
# for i in "${arr[@]}" | |
# do | |
# l="$(echo "${i}" | sed -e 's/^[[:space:]]*//')" | |
# if [[ $l = "π*" ]] || [[ $1 = "| (U) " ]] | |
# then | |
# IFS=$' ' arr2=($l) | |
# DORG="${arr2[2]}" | |
# fi | |
# done | |
DORG="dev" | |
#echo "π Default org = $DORG" | |
## Get revision ID | |
echo "π Please provide the GIT revision ID, this will be used to diff against your current HEAD (i.e. release/1.39 or HEAD~1)" | |
read -p "π GIT Revision ID: " GIT_REV | |
ANSWER=${ANSWER:-HEAD} | |
echo | |
## Confirm manifest is correct | |
echo "π Deployment manifest:" | |
echo " ====================" | |
git diff $GIT_REV --diff-filter=ACMR --name-status --color -- force-app/ | cat | |
echo | |
read -p "π Confirm the manifest above is correct (Y/n): " ANSWER | |
ANSWER=${ANSWER:-Y} | |
case ${ANSWER:0:1} in | |
y|Y ) | |
;; | |
* ) | |
echo "π Try a different GIT revision ID. Exiting..." | |
cleanExit | |
;; | |
# Continue | |
esac | |
else | |
GIT_REV=HEAD | |
fi | |
# Convert manifest to SFDX format | |
git diff $GIT_REV --diff-filter=ACMR --name-only --color -- force-app/ > temp | |
tr '\n' ',' < temp > changes.txt # replace newlines with commas | |
rm temp | |
sed -i -e "s/\,/' '/g" changes.txt # put each filename in its own quotes | |
echo "'$(cat changes.txt)" > changes.txt # fix start of file | |
sed -i -e "s/' '$/'/g" changes.txt # fix end of file | |
CHANGES=$(<changes.txt) | |
if [ $QUICK != 'true' ] | |
then | |
echo | |
read -p "π Target org to deploy to ($DORG): " ORG | |
ORG=${ORG:-$DORG} | |
if [ -z "$ORG" ] | |
then | |
echo "No org provided. Exiting..." | |
cleanExit | |
fi | |
echo | |
echo "π Deployment command:" | |
echo " =====================" | |
echo "sfdx project deploy start --ignore-conflicts -o $ORG -d $CHANGES" | |
echo | |
read -p "π To execute the deployment command above, type (d): " ANSWER | |
case ${ANSWER:0:1} in | |
d|D ) | |
;; | |
* ) | |
echo "π No deployment performed. Exiting..." | |
cleanExit | |
;; | |
# Continue | |
esac | |
fi | |
echo | |
if [ $QUICK != 'true' ] | |
then | |
eval $"sfdx project deploy start --ignore-conflicts -o $ORG -d $CHANGES" | |
read -p "π Deployment complete. Open SFDX org? (y/N): " | |
ANSWER=${ANSWER:-N} | |
case ${ANSWER:0:1} in | |
y|Y ) | |
echo | |
sfdx force:org:open -u $ORG | |
;; | |
* ) | |
;; | |
# Continue | |
esac | |
echo | |
else | |
echo "π Deploying changes to default org..." | |
echo | |
eval $"sfdx project deploy start --ignore-conflicts -d $CHANGES" | |
fi | |
echo | |
echo "π Exiting..." | |
cleanExit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment