-
Notifications
You must be signed in to change notification settings - Fork 1
/
mdapi-deploy
executable file
·51 lines (50 loc) · 2.27 KB
/
mdapi-deploy
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
#!/bin/bash -e
fullname=$1
apppath=${1%/}
if [ -d "$apppath" ]
then
re1='s/.*\({[^}]*"path"\s*:\s*"'"$apppath"'[/]*"\s*[^}]*}\).*/\1\n/p'
re2='s/.*"package"\s*:\s*"\([^"]*\)"\s*.*/\1/p'
fullname="$(sed -z -n -e "$re1" < sfdx-project.json|sed -z -n -e "$re2")"
else
re1='s/.*\({[^}]*"package"\s*:\s*"'"$fullname"'"\s*[^}]*}\).*/\1\n/p'
re2='s/.*"path"\s*:\s*"\([^"]*\)"\s*.*/\1/p'
apppath="$(sed -z -n -e "$re1" < sfdx-project.json|sed -z -n -e "$re2")"
apppath=${apppath%/}
fi
if ( grep -q "\"$fullname@" sfdx-project.json )
then
echo "Assuming the $fullname package has already been deployed."
fullname=""
fi
if [ ! -d "$apppath" ]
then
echo "usage: $0 <package> ..." 1>&2
echo "-or- usage: $0 <path> ..." 1>&2
exit 1
fi
shift
mdapipath="$apppath".mdapi
rm -rf "$mdapipath"
if [ -n "$fullname" ]
then
echo sfdx force:source:convert -r "$apppath"/ -d "$mdapipath"/ -n "$fullname"
sfdx force:source:convert -r "$apppath"/ -d "$mdapipath"/ -n "$fullname"
else
echo sfdx force:source:convert -r "$apppath"/ -d "$mdapipath"/
sfdx force:source:convert -r "$apppath"/ -d "$mdapipath"/
fi
if [ -d "$mdapipath/testSuites" ]
then
echo "Warning: ApexTestSuite cannot be deployed as part of an unmanaged package." 1>&2
script='for i in "$@";do if [ -r "$mdapipath/testSuites/$i.testSuite" ] ; then sed -i -z -e "s,\(\\s*<name>ApexTestSuite</name>\)\\s*<members>$i</members>,\\1," "$mdapipath/package.xml";fi;done'
sed -n -e 's,\s*<members>\(.*\)</members>\s*,\1,p' $mdapipath/package.xml | mdapipath="$mdapipath" xargs bash -c "$script" -
sed -i -z -e 's,\s*<types>\s*<name>ApexTestSuite</name>\s*</types>,,' "$mdapipath/package.xml"
fi
echo sfdx force:mdapi:deploy -d "$mdapipath" --testlevel=RunSpecifiedTests -r "$(cd "$mdapipath"/classes/ && fgrep -i -l '@isTest' *.cls|sed -n -e 's,[.]cls$,,p'|tr '\n' ',')" --loglevel=warn -w 10 "$@"
sfdx force:mdapi:deploy -d "$mdapipath" --testlevel=RunSpecifiedTests -r "$(cd "$mdapipath"/classes/ && fgrep -i -l '@isTest' *.cls|sed -n -e 's,[.]cls$,,p'|tr '\n' ',')" --loglevel=warn -w 10 "$@"
echo rm -rf "$mdapipath"
rm -rf "$mdapipath"
# This is just to make sure we have all the console output before we return to the command prompt
sleep 3
i=0;while [ $i -lt 25 ] ; do echo "";i=$(expr $i + 1);done