-
Notifications
You must be signed in to change notification settings - Fork 0
/
sf-validate
executable file
·89 lines (80 loc) · 3.27 KB
/
sf-validate
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/usr/bin/env bash
#
# Validate a SFDX project against an Org and run unit tests
#
# USAGE
#
# sf-validate -o ORG # validate deployment with unit tests on ORG
# sf-validate -n # validate deployment without unit tests
#
# COMMANDS
#
# TESTS=$(sed s/,$// scripts/test/unit-test-list.txt | awk '{ printf(" -t %s", $0) }')
# sf project deploy validate -x manifest/package.xml -l RunSpecifiedTests $TESTS -o ORG # validate and run specific unit-tests
#
# sf project deploy start -x manifest/package.xml --dry-run --concise -l NoTestRun -o ORG # validate only
#
yesno() {
echo ""
read -p "$1 [Y/n] " response
[[ $response == "n" || $response == "N" ]] && exit 1
}
show_help() {
awk '/^[^ #]/{c=1}c==0{print $0}' $0 | sed -n '/^#/p' | sed 1d | sed 's/^#/ /g' \
| perl -pe "s/ #(.*)$/$(tput setaf 0)\1$(tput sgr 0)/" \
| perl -pe "s/(USAGE|EXAMPLES|COMMANDS)/$(tput setaf 0)\1$(tput sgr 0)/" \
| perl -pe "s/\`(.+)\`/$(tput sgr 0 1)\1$(tput sgr 0)/"
exit 1
}
setTargetOrg() {
if [[ -z "$org" ]]; then
org=$(cat .sf/config.json 2>/dev/null | jq -r '."target-org" | select( . != null )')
fi
if [[ -z "$org" ]]; then
org=$(cat ~/.sf/config.json 2>/dev/null | jq -r '."target-org" | select( . != null )')
fi
if [[ -z "$org" ]]; then
echo -e >&2 "\n $(tput setaf 1)Missing target org$(tput sgr 0)\n\n Either provide with $(tput setaf 0)-o$(tput sgr 0) option, or set via $(tput setaf 0)sf config set target-org <org>$(tput sgr 0)"
exit 1
fi
}
org=""
unittests=true
result=$(mktemp)
while [ $# -gt 0 ]; do
case $1 in
-o)
shift
org=$1
;;
-n)
unittests=false
;;
-h|--help)
show_help
;;
*)
;;
esac
shift
done
setTargetOrg
showresult() {
tail -n 9 ${result} | perl -pe "s/(Successfully validated the deployment)/ $(tput setaf 2)\1$(tput sgr 0)/" | cut -c -$(tput cols)
deployid=$(cat ${result} | grep "Deploy ID" | perl -pe 's/Deploy ID: (.*)/\1/')
orgname=$(sf data query -q "SELECT Domain FROM Domain WHERE HttpsOption = 'CommunityAlt'" --json | jq -r '.result.records[].Domain' | perl -pe 's/(.+)--.+/\1/')
deployurl="https://${orgname}--${1}.sandbox.lightning.force.com/lightning/setup/DeployStatus/page?address=/changemgmt/monitorDeploymentsDetails.apexp?asyncId=${deployid}"
echo -e "\n $(tput setaf 4)Deployment Status:$(tput sgr0)\n ${deployurl}"
}
if [ $unittests == true ]; then
yesno " Validate and run Unit Tests on $(tput setaf 1)${org}$(tput sgr0) ?"
echo -e "\n $(tput setaf 2)Validate and run Unit Tests$(tput sgr0) ..."
[[ $DEBUG == "1" ]] && echo -e "\n $(tput setaf 0)sf project deploy validate -x manifest/package.xml -o ${org} -l RunSpecifiedTests [-t ...] $(tput sgr0)\n"
sf project deploy validate -x manifest/package.xml -l RunSpecifiedTests `sed s/,$// scripts/test/unit-test-list.txt | awk '{ printf(" -t %s", $0) }'` -o ${org} > ${result}
else
yesno " Validate on $(tput setaf 1)${org}$(tput sgr0) ?"
echo -e "\n $(tput setaf 2)Validate$(tput sgr0) ..."
[[ $DEBUG == "1" ]] && echo -e "\n $(tput setaf 0)sf project deploy start -x manifest/package.xml -l NoTestRun --dry-run -o ${org}$(tput sgr0)\n"
sf project deploy start -x manifest/package.xml -l NoTestRun --dry-run -o ${org} > ${result}
fi
showresult ${org}