-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsf-deploy-index
executable file
·155 lines (148 loc) · 5.53 KB
/
sf-deploy-index
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#!/usr/bin/env bash
#
# helper script to be called by 'sf-deploy'
#
org=$1
session="$2"
publish=false
mapOption() {
option=''
case "$1" in
audience*)
option="Audience:$(echo $1 | perl -pe 's#audience/(.+?)\..+#\1#')"
;;
aura*)
option="AuraDefinitionBundle:$(echo $1 | perl -pe 's#aura/(.+?)/.+#\1#')"
;;
classes*)
option="ApexClass:$(echo $1 | perl -pe 's#classes/(.+?)\..+#\1#')"
;;
contentassets*)
option="ContentAsset:$(echo $1 | perl -pe 's#contentassets/(.+?)\..+#\1#')"
;;
documents*)
option="Document:$(echo $1 | perl -pe 's#documents/(.+?)\..+#\1#')"
;;
email*)
option="EmailTemplate:$(echo $1 | perl -pe 's#email/(.+?)\..+#\1#')"
;;
experiences*)
option="ExperienceBundle:$(echo $1 | perl -pe 's#experiences/(.+?)/.+#\1#')"
publish=true
;;
externalCredentials*)
option="ExternalCredential:$(echo $1 | perl -pe 's#externalCredentials/(.+?)\..+#\1#')"
;;
flexipages*)
option="FlexiPage:$(echo $1 | perl -pe 's#flexipages/(.+?)\..+#\1#')"
;;
flows*)
option="Flow:$(echo $1 | perl -pe 's#flows/(.+?)\..+#\1#')"
;;
globalValueSets*)
option="GlobalValueSet:$(echo $1 | perl -pe 's#globalValueSets/(.+?)\..+#\1#')"
;;
layouts*)
option="Layout:$(echo $1 | perl -pe 's#layouts/(.+?)\..+#\1#')"
;;
lwc*)
option="LightningComponentBundle:$(echo $1 | perl -pe 's#lwc/(.+?)/.+#\1#')"
;;
namedCredentials*)
option="NamedCredential:$(echo $1 | perl -pe 's#namedCredentials/(.+?)\..+#\1#')"
;;
networks*)
option="Network:$(echo $1 | perl -pe 's#networks/(.+?)\..+#\1#')"
;;
networkBranding*)
option="NetworkBranding:$(echo $1 | perl -pe 's#networkBranding/(.+?)\..+#\1#')"
;;
objects*)
object=$(echo $1 | perl -pe 's#objects/([^/]+?)/(.*)#\1#')
path=$(echo $1 | perl -pe 's#objects/([^/]+?)/(.*)#\2#' | sed 's/ /#/g')
case "$path" in
fields*)
option="CustomField:${object}.$(echo $path | perl -pe 's#fields/(.+?)\..+#\1#')"
;;
listViews*)
option="ListView:${object}.$(echo $path | perl -pe 's#listViews/(.+?)\..+#\1#')"
;;
recordTypes*)
option="RecordType:${object}.$(echo $path | perl -pe 's#recordTypes/(.+?)\..+#\1#')"
;;
*)
option="CustomObject:${object}"
;;
esac
;;
objectTranslations*)
option="CustomObjectTranslation:$(echo $1 | perl -pe 's#objectTranslations/([^/]+).*#\1#')"
;;
pages*)
option="ApexPage:$(echo $1 | perl -pe 's#pages/(.+?)\..+#\1#')"
;;
permissionsets*)
option="PermissionSet:$(echo $1 | perl -pe 's#permissionsets/(.+?)\..+#\1#')"
;;
profiles*)
option="Profile:$(echo $1 | perl -pe 's#profiles/(.+?)\..+#\1#')"
;;
quickActions*)
option="QuickAction:$(echo $1 | perl -pe 's#quickActions/(.+?\..+?)\..+#\1#')"
;;
settings*)
option="Settings:$(echo $1 | perl -pe 's#settings/(.+?)\..+#\1#')"
;;
sites*)
option="CustomSite:$(echo $1 | perl -pe 's#sites/(.+?)\..+#\1#')"
;;
staticresources*)
option="StaticResource:$(echo $1 | perl -pe 's#staticresources/(.+?)(/|\.).+#\1#')"
;;
tabs*)
option="CustomTab:$(echo $1 | perl -pe 's#tabs/(.+?)\..+#\1#')"
;;
translations*)
option="Translations:$(echo $1 | perl -pe 's#translations/(.+?)\..+#\1#')"
;;
triggers*)
option="ApexTrigger:$(echo $1 | perl -pe 's#triggers/(.+?)\..+#\1#')"
;;
webStoreTemplates*)
option="WebStoreTemplate:$(echo $1 | perl -pe 's#webStoreTemplates/(.+?)\..+#\1#')"
;;
esac
echo ${option}
}
declare -a options
while read f; do
path=$(echo $f | perl -pe 's#force-app/main/default/([^/]*)#\1#' | sed 's/ /#/g')
options=(${options[@]} "$(mapOption "${path}")")
done < <((cat "$session"; git diff HEAD --name-only) | sort | uniq | tee "$session")
# all custom label entites are within one single file
while read label; do
options=(${options[@]} "CustomLabel:$label")
done < <(git diff HEAD -U6 force-app/main/default/labels/CustomLabels.labels-meta.xml | gawk '/<labels>/{l=1}/<fullName>/{if(l==1)n=gensub(/.*<.+>(.+)<.+>.*/,"\\1","g",$0)}/^+/{if(l==1){c=1}}/<\/labels>/{if(l==1 && c==1)print n;l=0;c=0}')
uniq_options=($(for option in "${options[@]}"; do echo "${option}"; done | sort -u))
if [[ ${#uniq_options[@]} == 0 ]]; then
echo -e " $(tput setaf 1)git index does not contain any sf-metadata, nothing to deploy$(tput sgr0) ...\n"
exit 1
else
echo -e " found $(tput setaf 2)${#options[@]} file$([[ ! ${#options[@]} -eq 1 ]] && echo "s")$(tput sgr0) in git-index and in deploy-session for $(tput setaf 2)${#uniq_options[@]} metadata-entit$([[ ${#uniq_options[@]} -eq 1 ]] && echo "y" || echo "ies")$(tput sgr0) to deploy ...\n"
opts=''
for p in ${uniq_options[@]}; do
if [[ $p = *"#"* ]]; then
opts="${opts} -m \"${p//#/ }\""
else
opts="${opts} -m ${p}"
fi
done
[[ $DEBUG == "1" ]] && echo -e " $(tput setaf 0)sf project deploy start -o ${org}${opts}$(tput sgr0)\n"
eval "sf project deploy start -o ${org}${opts}"
if [[ $publish == true ]]; then
name=$(sf data query -o ${org} -q "SELECT Name FROM Site WHERE UrlPathPrefix=''" --json | jq -r '.result.records[].Name')
[[ $DEBUG == "1" ]] && echo -e " $(tput setaf 0)sf community publish -n ${name} -o ${org}$(tput sgr0)\n"
sf community publish -n ${name} -o ${org} >/dev/null
fi
echo -e " $(tput setaf 2)waiting for changes$(tput sgr0) ...\n"
fi