-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathsfdeploytool.command
executable file
·302 lines (288 loc) · 11.5 KB
/
sfdeploytool.command
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
# * Copyright (c) 2019 - Present, Rahul Malhotra. All rights reserved.
# * Use of this source code is governed by a BSD 3-Clause License that can be found in the LICENSE.md file.
currentLocation=$(dirname "$0")
# * This method is used to read configuration from config.txt
readConfig() {
clear
echo "Welcome to SFDX Deployment Tool for Mac..!!"
echo "----------config----------"
while IFS= read -r line || [ -n "$line" ]
do
IFS='='
read -ra currentLine <<< "$line"
currentLine[1]="${currentLine[1]//\\//}"
echo ${currentLine[0]}: ${currentLine[1]}
case "${currentLine[0]}" in
"sourceOrg") sourceOrgAlias=${currentLine[1]}
;;
"destinationOrg") destinationOrgAlias=${currentLine[1]}
;;
"package.xmlLocationToDeploy") packageXmlLocation=$currentLocation/${currentLine[1]}
;;
"folderLocationForFetchedZip") zipFolderLocation=$currentLocation/${currentLine[1]}
;;
"waitTimeInMinutes") waitTime=${currentLine[1]}
;;
"testLevel") testLevel=${currentLine[1]}
;;
"runTests") runTests=${currentLine[1]}
;;
"folderLocationToUndeploy") folderLocationToUndeploy=$currentLocation/${currentLine[1]}
;;
esac
done < $currentLocation/config.txt
echo "--------------------------"
}
# * This method is used to check org alias in configuration
checkOrgAlias() {
readConfig
if [ "${sourceOrgAlias}" == "" ]
then
updateSourceOrgAlias
elif [ "${destinationOrgAlias}" == "" ]
then
updateDestinationOrgAlias
else
startMenu
fi
}
# * This method is used to update source org alias in configuration file
updateSourceOrgAlias() {
read -p "Enter alias for source org:- " sourceOrgAlias
echo "1. Connect to Developer/Production"
echo "2. Connect to Sandbox"
read -p "Enter your choice (1/2) or Press Enter to add a custom URL:- " orgChoice
if [ "${orgChoice}" == "1" ]
then
orgChoice=
orgUrl="https://login.salesforce.com"
elif [ "${orgChoice}" == "2" ]
then
orgChoice=
orgUrl="https://test.salesforce.com"
else
read -p "Enter the instance/login url for your org:- " orgUrl
fi
echo "Authorizing source org..."
echo "sf org login web --alias $sourceOrgAlias --instance-url $orgUrl --set-default"
sf org login web --alias $sourceOrgAlias --instance-url $orgUrl --set-default
if [ "$?" = "0" ]; then
sed -i '' "s/sourceOrg=/sourceOrg=$sourceOrgAlias/" config.txt
echo "Source org authorized successfully. Config file updated."
else
echo "Unable to authorize source org. Please try again."
sourceOrgAlias=
orgUrl=
fi
checkOrgAlias
}
# * This method is used to update destination org alias in configuration file
updateDestinationOrgAlias() {
read -p "Enter alias for destination org:- " destinationOrgAlias
echo "1. Connect to Developer/Production"
echo "2. Connect to Sandbox"
read -p "Enter your choice (1/2) or Press Enter to add a custom URL:- " orgChoice
if [ "${orgChoice}" == "1" ]
then
orgChoice=
orgUrl="https://login.salesforce.com"
elif [ "${orgChoice}" == "2" ]
then
orgChoice=
orgUrl="https://test.salesforce.com"
else
read -p "Enter the instance/login url for your org:- " orgUrl
fi
echo "Authorizing source org..."
echo "sf org login web --alias $destinationOrgAlias --instance-url $orgUrl --set-default"
sf org login web --alias $destinationOrgAlias --instance-url $orgUrl --set-default
if [ "$?" = "0" ]; then
sed -i '' "s/destinationOrg=/destinationOrg=$destinationOrgAlias/" config.txt
echo "Destination org authorized successfully. Config file updated."
else
echo "Unable to authorize destination org. Please try again."
destinationOrgAlias=
orgUrl=
fi
checkOrgAlias
}
# * This method is used to display the menu
startMenu() {
echo "0. Reload configuration"
echo "1. Fetch metadata from source org"
echo "2. Extract fetched metadata"
echo "3. Validate metadata in destination org"
echo "4. Deploy metadata in destination org"
echo "5. Validate extracted metadata in destination org"
echo "6. Deploy extracted metadata in destination org"
echo "7. Un-Deploy metadata in destination org"
echo "-> Press any other key to exit"
read -p "Enter your choice:- " choice
clear
case "$choice" in
"0")
choice=
checkOrgAlias
;;
"1")
choice=
fetchMetadata
checkOrgAlias
;;
"2")
choice=
extractFetchedMetadata
checkOrgAlias
;;
"3")
choice=
validateMetadata
checkOrgAlias
;;
"4")
choice=
deployMetadata
checkOrgAlias
;;
"5")
choice=
validateExtractedMetadata
checkOrgAlias
;;
"6")
choice=
deployExtractedMetadata
checkOrgAlias
;;
"7")
choice=
unDeployMetadata
checkOrgAlias
;;
esac
}
# * This method is used to fetch metadata from source org
fetchMetadata() {
clear
echo "Fetching the metadata from source org..."
echo "sf project retrieve start -t $zipFolderLocation -o $sourceOrgAlias -x $packageXmlLocation"
sf project retrieve start -t $zipFolderLocation -o $sourceOrgAlias -x $packageXmlLocation
if [ "$?" != "0" ]; then
echo "Unable to fetch metadata"
fi
echo "Press any key to continue...."
read
}
# * This method is used to extract the fetched metadata from source org
extractFetchedMetadata() {
echo "Extracting the metadata previously fetched from source org..."
echo "unzip $zipFolderLocation/unpackaged.zip -d $zipFolderLocation"
unzip $zipFolderLocation/unpackaged.zip -d $zipFolderLocation
if [ "$?" != "0" ]; then
echo "Unable to extract metadata"
else
echo "Metadata extracted successfully and is available in folder $zipFolderLocation/unpackaged"
fi
echo "Press any key to continue...."
read
}
# * This method is used to validate metadata in destination org
validateMetadata() {
echo "Validating metadata in destination org..."
if [ "$testLevel" == "RunSpecifiedTests" ]; then
echo "sf project deploy validate --metadata-dir $zipFolderLocation/unpackaged.zip -o $destinationOrgAlias -w $waitTime -l RunSpecifiedTests -t $runTests"
validateComponents="sf project deploy validate --metadata-dir $zipFolderLocation/unpackaged.zip -o $destinationOrgAlias -w $waitTime -l RunSpecifiedTests -t $runTests"
eval $validateComponents
else
echo sf project deploy validate --metadata-dir $zipFolderLocation/unpackaged.zip -o $destinationOrgAlias -w $waitTime -l $testLevel
validateComponents="sf project deploy validate --metadata-dir $zipFolderLocation/unpackaged.zip -o $destinationOrgAlias -w $waitTime -l $testLevel"
eval $validateComponents
fi
if [ "$?" != "0" ]; then
echo "Unable to validate metadata"
else
echo "Metadata validated successfully in destination org"
fi
echo "Press any key to continue...."
read
}
# * This method is used to deploy metadata in destination org
deployMetadata() {
echo "Deploying metadata in destination org..."
if [ "$testLevel" == "RunSpecifiedTests" ]; then
echo "sf project deploy start --metadata-dir $zipFolderLocation/unpackaged.zip -o $destinationOrgAlias -w $waitTime -l RunSpecifiedTests -t $runTests"
deployComponents="sf project deploy start --metadata-dir $zipFolderLocation/unpackaged.zip -o $destinationOrgAlias -w $waitTime -l RunSpecifiedTests -t $runTests"
eval $deployComponents
else
echo sf project deploy start --metadata-dir $zipFolderLocation/unpackaged.zip -o $destinationOrgAlias -w $waitTime -l $testLevel
deployComponents="sf project deploy start --metadata-dir $zipFolderLocation/unpackaged.zip -o $destinationOrgAlias -w $waitTime -l $testLevel"
eval $deployComponents
fi
if [ "$?" != "0" ]; then
echo "Unable to deploy metadata"
else
echo "Metadata deployed successfully in destination org"
fi
echo "Press any key to continue...."
read
}
# * This method is used to validate extracted metadata in destination org
validateExtractedMetadata() {
echo "Validating extracted metadata in destination org..."
if [ "$testLevel" == "RunSpecifiedTests" ]; then
echo "sf project deploy validate --metadata-dir $zipFolderLocation/unpackaged -o $destinationOrgAlias -w $waitTime -l RunSpecifiedTests -t $runTests"
validateComponents="sf project deploy validate --metadata-dir $zipFolderLocation/unpackaged -o $destinationOrgAlias -w $waitTime -l RunSpecifiedTests -t $runTests"
eval $validateComponents
else
echo sf project deploy validate --metadata-dir $zipFolderLocation/unpackaged -o $destinationOrgAlias -w $waitTime -l $testLevel
validateComponents="sf project deploy validate --metadata-dir $zipFolderLocation/unpackaged -o $destinationOrgAlias -w $waitTime -l $testLevel"
eval $validateComponents
fi
if [ "$?" != "0" ]; then
echo "Unable to validate metadata"
else
echo "Metadata validated successfully in destination org"
fi
echo "Press any key to continue...."
read
}
# * This method is used to deploy extracted metadata in destination org
deployExtractedMetadata() {
echo "Deploying extracted metadata in destination org..."
if [ "$testLevel" == "RunSpecifiedTests" ]; then
echo "sf project deploy start --metadata-dir $zipFolderLocation/unpackaged -o $destinationOrgAlias -w $waitTime -l RunSpecifiedTests -t $runTests"
deployComponents="sf project deploy start --metadata-dir $zipFolderLocation/unpackaged -o $destinationOrgAlias -w $waitTime -l RunSpecifiedTests -t $runTests"
eval $deployComponents
else
echo sf project deploy start --metadata-dir $zipFolderLocation/unpackaged -o $destinationOrgAlias -w $waitTime -l $testLevel
deployComponents="sf project deploy start --metadata-dir $zipFolderLocation/unpackaged -o $destinationOrgAlias -w $waitTime -l $testLevel"
eval $deployComponents
fi
if [ "$?" != "0" ]; then
echo "Unable to deploy metadata"
else
echo "Metadata deployed successfully in destination org"
fi
echo "Press any key to continue...."
read
}
# * This method is used to remove metadata from destination org
unDeployMetadata() {
echo "Removing metadata from destination org..."
if [ "$testLevel" == "RunSpecifiedTests" ]; then
echo "sf project deploy start --metadata-dir $folderLocationToUndeploy -o $destinationOrgAlias -w $waitTime"
sf project deploy start --metadata-dir $folderLocationToUndeploy -o $destinationOrgAlias -w $waitTime
else
echo sf project deploy start --metadata-dir $folderLocationToUndeploy -o $destinationOrgAlias -w $waitTime
sf project deploy start --metadata-dir $folderLocationToUndeploy -o $destinationOrgAlias -w $waitTime
fi
if [ "$?" != "0" ]; then
echo "Unable to remove metadata"
else
echo "Metadata removed successfully from destination org"
fi
echo "Press any key to continue...."
read
}
# * Calling checkOrgAlias method
checkOrgAlias