Skip to content

Instantly share code, notes, and snippets.

@shanerk
Last active March 22, 2024 18:41
Show Gist options
  • Save shanerk/7767460b0adecace21aa97b4483a437c to your computer and use it in GitHub Desktop.
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)
#!/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