leap_salesforce 0.1.18 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +4 -0
- data/.gitlab-ci.yml +589 -2
- data/.idea/.rakeTasks +2 -2
- data/.idea/leap-salesforce.iml +6 -2
- data/.leap_salesforce.yml +2 -1
- data/ChangeLog +4 -0
- data/Rakefile +1 -1
- data/assets/server.key.enc +0 -0
- data/config/general.rb +2 -0
- data/config/project-scratch-def.json +12 -0
- data/exe/leap_salesforce +7 -4
- data/lib/leap_salesforce/auth.rb +87 -0
- data/lib/leap_salesforce/generator/exe_helpers.rb +15 -17
- data/lib/leap_salesforce/generator/generator.rb +1 -1
- data/lib/leap_salesforce/generator/templates/.gitignore.erb +6 -2
- data/lib/leap_salesforce/generator/templates/.leap_salesforce.yml.erb +1 -0
- data/lib/leap_salesforce/generator/templates/config/credentials/salesforce_oauth2.yml.erb +3 -1
- data/lib/leap_salesforce/generator/templates/config/general.rb.erb +6 -0
- data/lib/leap_salesforce/get_prod_auth.sh +2 -0
- data/lib/leap_salesforce/get_scratch_auth.sh +2 -0
- data/lib/leap_salesforce/loader.rb +26 -0
- data/lib/leap_salesforce/parameters.rb +38 -3
- data/lib/leap_salesforce/rake/sfdx.rake +28 -0
- data/lib/leap_salesforce/soql_data/soql_global_object_data.rb +24 -5
- data/lib/leap_salesforce/soql_data/soql_handler.rb +9 -3
- data/lib/leap_salesforce/soql_data/tooling.rb +15 -0
- data/lib/leap_salesforce/version.rb +1 -1
- data/lib/leap_salesforce.rb +37 -44
- metadata +10 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 77695ebdd7c343c96054ec7feddc3f7fad3d6cd88faef0cebdeffdae3b1ff6dc
|
4
|
+
data.tar.gz: adccd0e5e0cc880e554fa0c7b8a3381fbf3a7e68142e23e59afdfef7846fdb2d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 04c59da4ce51c172fffdf7763dfaa6db9d3f6115016ec1afbd5dfd005b40d7592af0508c7b2d2317128f7c92118caa9349edf61fc1b4c544822ea02ea89bda9c
|
7
|
+
data.tar.gz: 7a0c30ded8226117a3480730d02daf3a3582694e9d873b37417b542f8f3e581c17fda7d4a87a4eeb3a053a302090b0a7f20e469ee8ece55b9aec1f8f2f5352ce
|
data/.gitignore
CHANGED
data/.gitlab-ci.yml
CHANGED
@@ -10,14 +10,601 @@ variables:
|
|
10
10
|
password: $password
|
11
11
|
client_id: $client_id
|
12
12
|
client_secret: $client_secret
|
13
|
-
|
13
|
+
SERVER_KEY_PASSWORD: $SERVER_KEY_PASSWORD
|
14
|
+
|
15
|
+
|
16
|
+
.sfdx_helpers: &sfdx_helpers |
|
17
|
+
|
18
|
+
# Function to install the Salesforce CLI.
|
19
|
+
# No arguments.
|
20
|
+
|
21
|
+
function install_salesforce_cli() {
|
22
|
+
|
23
|
+
# Salesforce CLI Environment Variables
|
24
|
+
# https://developer.salesforce.com/docs/atlas.en-us.sfdx_dev.meta/sfdx_dev/sfdx_dev_cli_env_variables.htm
|
25
|
+
|
26
|
+
# By default, the CLI periodically checks for and installs updates.
|
27
|
+
# Disable (false) this auto-update check to improve performance of CLI commands.
|
28
|
+
export SFDX_AUTOUPDATE_DISABLE=false
|
29
|
+
|
30
|
+
# Set to true if you want to use the generic UNIX keychain instead of the Linux libsecret library or macOS keychain.
|
31
|
+
# Specify this variable when using the CLI with ssh or "headless" in a CI environment.
|
32
|
+
export SFDX_USE_GENERIC_UNIX_KEYCHAIN=true
|
33
|
+
|
34
|
+
# Specifies the time, in seconds, that the CLI waits for the Lightning Experience custom domain to resolve and become available in a newly-created scratch org.
|
35
|
+
# If you get errors about My Domain not configured when you try to use a newly-created scratch org, increase this wait time.
|
36
|
+
export SFDX_DOMAIN_RETRY=300
|
37
|
+
|
38
|
+
# For force:package:create, disables automatic updates to the sfdx-project.json file.
|
39
|
+
export SFDX_PROJECT_AUTOUPDATE_DISABLE_FOR_PACKAGE_CREATE=true
|
40
|
+
|
41
|
+
# For force:package:version:create, disables automatic updates to the sfdx-project.json file.
|
42
|
+
export SFDX_PROJECT_AUTOUPDATE_DISABLE_FOR_PACKAGE_VERSION_CREATE=true
|
43
|
+
|
44
|
+
# Install Salesforce CLI
|
45
|
+
mkdir sfdx
|
46
|
+
CLIURL=https://developer.salesforce.com/media/salesforce-cli/sfdx-linux-amd64.tar.xz
|
47
|
+
wget -qO- $CLIURL | tar xJ -C sfdx --strip-components 1
|
48
|
+
"./sfdx/install"
|
49
|
+
export PATH=./sfdx/$(pwd):$PATH
|
50
|
+
|
51
|
+
# Output CLI version and plug-in information
|
52
|
+
sfdx update
|
53
|
+
sfdx --version
|
54
|
+
sfdx plugins --core
|
55
|
+
|
56
|
+
}
|
57
|
+
|
58
|
+
|
59
|
+
# Function to install jq json parsing library.
|
60
|
+
# No arguments.
|
61
|
+
|
62
|
+
function install_jq() {
|
63
|
+
apt update && apt -y install jq
|
64
|
+
}
|
65
|
+
|
66
|
+
|
67
|
+
# Function to install LWC Jest dependencies.
|
68
|
+
# Will create or update the package.json with { "test:lwc" : "lwc-jest" } to the scripts property.
|
69
|
+
# No arguments.
|
70
|
+
|
71
|
+
function install_lwc_jest() {
|
72
|
+
|
73
|
+
# Create a default package.json if file doesn't exist
|
74
|
+
if [ ! -f "package.json" ]; then
|
75
|
+
npm init -y
|
76
|
+
fi
|
77
|
+
|
78
|
+
# Check if the scripts property in package.json contains key for "test:lwc"
|
79
|
+
local scriptValue=$(jq -r '.scripts["test:lwc"]' < package.json)
|
80
|
+
|
81
|
+
# If no "test:lwc" script property, then add one
|
82
|
+
if [[ -z "$scriptValue" || $scriptValue == null ]]; then
|
83
|
+
local tmp=$(mktemp)
|
84
|
+
jq '.scripts["test:lwc"]="lwc-jest"' package.json > $tmp
|
85
|
+
mv $tmp package.json
|
86
|
+
echo "added test:lwc script property to package.json" >&2
|
87
|
+
cat package.json >&2
|
88
|
+
fi
|
89
|
+
|
90
|
+
# Now that we have package.json to store dependency references to
|
91
|
+
# and to run our lwc jest test scripts, run npm installer
|
92
|
+
npm install
|
93
|
+
npm install @salesforce/lwc-jest --save-dev
|
94
|
+
|
95
|
+
}
|
96
|
+
|
97
|
+
|
98
|
+
# Checks if there are LWC Jest Test files in any of the package directories of sfdx-project.json.
|
99
|
+
# This is necessary because npm will throw error if no test classes are found.
|
100
|
+
# No arguments.
|
101
|
+
# Returns `true` or `false`
|
102
|
+
|
103
|
+
function check_has_jest_tests() {
|
104
|
+
local hasJestTests=false
|
105
|
+
for pkgDir in $(jq -r '.packageDirectories[].path' < sfdx-project.json)
|
106
|
+
do
|
107
|
+
if [ -f $pkgDir ]; then
|
108
|
+
local fileCnt=$(find $pkgDir -type f -path "**/__tests__/*.test.js" | wc -l);
|
109
|
+
if [ $fileCnt -gt 0 ]; then
|
110
|
+
hasJestTests=true
|
111
|
+
fi
|
112
|
+
fi
|
113
|
+
done
|
114
|
+
echo $hasJestTests
|
115
|
+
}
|
116
|
+
|
117
|
+
|
118
|
+
# Runs `npm run test:lwc` to execute LWC Jest tests.
|
119
|
+
# Function takes no arguments.
|
120
|
+
# Should be called after `setup_lwc`.
|
121
|
+
# Uses `check_has_jest_tests` to know if there are actually any tests to run.
|
122
|
+
# If there aren't any jest tests then npm would throw an error and fail the job,
|
123
|
+
# so we skip running npm if there are no tests, essentially skipping them to avoid error.
|
124
|
+
|
125
|
+
function test_lwc_jest() {
|
126
|
+
local hasJestTests=$(check_has_jest_tests)
|
127
|
+
if [ $hasJestTests ]; then
|
128
|
+
npm run test:lwc
|
129
|
+
else
|
130
|
+
echo 'Skipping lwc tests, found no jest tests in any package directories' >&2
|
131
|
+
fi
|
132
|
+
}
|
133
|
+
|
134
|
+
|
135
|
+
# Function to test the scratch org, such as run Apex tests and/or load data.
|
136
|
+
# We leverage the script property `test:scratch` in package.json to provide developers a "hook"
|
137
|
+
# to control exactly how they want their apex test to be executed.
|
138
|
+
# Arguments:
|
139
|
+
# $1 = username or alias of org to test
|
140
|
+
# $2 = org name property
|
141
|
+
# (Assumes you've already authorized to that org)
|
142
|
+
|
143
|
+
function test_scratch_org() {
|
144
|
+
|
145
|
+
local org_username=$1
|
146
|
+
|
147
|
+
if [ ! $org_username ]; then
|
148
|
+
echo "ERROR No org username provided to 'test_scratch_org' function" >&2
|
149
|
+
exit 1;
|
150
|
+
fi
|
151
|
+
|
152
|
+
# Create a default package.json if file doesn't exist
|
153
|
+
if [ ! -f "package.json" ]; then
|
154
|
+
npm init -y
|
155
|
+
fi
|
156
|
+
|
157
|
+
# Check if the scripts property in package.json contains key for "test:scratch"
|
158
|
+
local scriptValue=$(jq -r '.scripts["test:scratch"]' < package.json)
|
159
|
+
|
160
|
+
# If no "test:scratch" script property, then add one
|
161
|
+
if [[ -z "$scriptValue" || $scriptValue == null ]]; then
|
162
|
+
local tmp=$(mktemp)
|
163
|
+
jq '.scripts["test:scratch"]="sfdx force:apex:test:run --codecoverage --resultformat human --wait 10"' package.json > $tmp
|
164
|
+
mv $tmp package.json
|
165
|
+
echo "added test:scratch script property to package.json" >&2
|
166
|
+
cat package.json >&2
|
167
|
+
fi
|
168
|
+
|
169
|
+
# Set the default username so any CLI commands
|
170
|
+
# the developer has set in their "test:scratch" script in package.json
|
171
|
+
# will operate on the correct environment.
|
172
|
+
# Afterwards, restore the original default username, just in case it was different.
|
173
|
+
local old_org_username=$(jq -r '.result[].value' <<< $(sfdx force:config:get defaultusername --json))
|
174
|
+
sfdx force:config:set defaultusername=$org_username
|
175
|
+
npm run test:scratch
|
176
|
+
sfdx force:config:set defaultusername=$old_org_username
|
177
|
+
|
178
|
+
}
|
179
|
+
|
180
|
+
|
181
|
+
# Function to authenticate to Salesforce.
|
182
|
+
# Don't expose the auth url to the logs.
|
183
|
+
# Arguments:
|
184
|
+
# $1 = alias to set
|
185
|
+
# $2 = Sfdx Auth URL
|
186
|
+
# $3 = SFDX AUth URL to use if the previous one isn't set (optional)
|
187
|
+
|
188
|
+
function authenticate() {
|
189
|
+
|
190
|
+
local alias_to_set=$1
|
191
|
+
local org_auth_url=$2
|
192
|
+
local org_auth_url_backup=$3
|
193
|
+
|
194
|
+
local file=$(mktemp)
|
195
|
+
echo $org_auth_url > $file
|
196
|
+
local cmd="sfdx force:auth:sfdxurl:store --sfdxurlfile $file --setalias $alias_to_set --json" && (echo $cmd >&2)
|
197
|
+
local output=$($cmd)
|
198
|
+
|
199
|
+
sfdx force:config:set defaultusername=$alias_to_set
|
200
|
+
sfdx force:config:set defaultdevhubusername=$alias_to_set
|
201
|
+
|
202
|
+
rm $file
|
203
|
+
}
|
204
|
+
|
205
|
+
|
206
|
+
# Function to get SFDX Auth URL for an org.
|
207
|
+
# Don't expose the force:org:display to logs to avoid exposing sensitive information like access tokens.
|
208
|
+
# Note this can only be run on a scratch org right after creating it, otherwise we won't be able to find the org
|
209
|
+
# Arguments:
|
210
|
+
# $1 = target org alias whose auth url to get
|
211
|
+
# Returns the SFDX Auth URL for the given org.
|
212
|
+
|
213
|
+
function get_org_auth_url() {
|
214
|
+
|
215
|
+
local org_username=$1
|
216
|
+
echo "org_username=$org_username" >&2
|
217
|
+
|
218
|
+
# Parse the SFDX Auth URL for the given org
|
219
|
+
local cmd="sfdx force:org:display --verbose --targetusername $org_username --json" && (echo $cmd >&2)
|
220
|
+
local output=$($cmd)
|
221
|
+
org_auth_url="$(jq -r '.result.sfdxAuthUrl' <<< $output)"
|
222
|
+
|
223
|
+
if [ ! $org_auth_url ]; then
|
224
|
+
echo "ERROR No SFDX Auth URL available for org $org_username" >&2
|
225
|
+
exit 1
|
226
|
+
fi
|
227
|
+
|
228
|
+
# Return the SFDX Auth URL
|
229
|
+
echo $org_auth_url
|
230
|
+
}
|
231
|
+
|
232
|
+
|
233
|
+
# Checks a specific limit for the given org
|
234
|
+
# and exits with error if none remaining.
|
235
|
+
# Arguments:
|
236
|
+
# $1 = target org username whose limits to check
|
237
|
+
# $2 = name of the limit to check (e.g. "DailyScratchOrgs" or "Package2VersionCreates")
|
238
|
+
|
239
|
+
function assert_within_limits() {
|
240
|
+
|
241
|
+
export local org_username=$1
|
242
|
+
export local limit_name=$2
|
243
|
+
echo "org_username=$org_username" >&2
|
244
|
+
echo "limit_name=$limit_name" >&2
|
245
|
+
|
246
|
+
local cmd="sfdx force:limits:api:display --targetusername $org_username --json" && (echo $cmd >&2)
|
247
|
+
local limits=$($cmd) && (echo $limits | jq '.' >&2)
|
248
|
+
local limit=$(jq -r '.result[] | select(.name == env.limit_name)' <<< $limits)
|
249
|
+
|
250
|
+
# If a limit was found, then check if we are within it
|
251
|
+
if [ -n "$limit" ]; then
|
252
|
+
|
253
|
+
local limit_max=$(jq -r '.max' <<< $limit)
|
254
|
+
local limit_rem=$(jq -r '.remaining' <<< $limit)
|
255
|
+
|
256
|
+
if [[ ( -z "$limit_rem" ) || ( $limit_rem == null ) || ( $limit_rem -le 0 ) ]]; then
|
257
|
+
echo "ERROR Max of $limit_max reached for limit $limit_name" >&2
|
258
|
+
exit 1
|
259
|
+
else
|
260
|
+
echo "$limit_rem of $limit_max remaining for limit $limit_name" >&2
|
261
|
+
fi
|
262
|
+
|
263
|
+
else
|
264
|
+
echo "No limits found for name $limit_name" >&2
|
265
|
+
fi
|
266
|
+
}
|
267
|
+
|
268
|
+
|
269
|
+
# Function to get package name and ID.
|
270
|
+
# Arguments:
|
271
|
+
# $1 = dev hub alias
|
272
|
+
# $2 = package name (optional, if not set then looks at $PACKAGE_NAME env variable, then in sfdx-project.json for default package directory)
|
273
|
+
# Returns the package id for the given package name owned by the given dev hub.
|
274
|
+
|
275
|
+
function get_package_id() {
|
276
|
+
|
277
|
+
# To make our local variables available to `jq` expressions,
|
278
|
+
# we need to export them to the environment. They are still scoped to this function.
|
279
|
+
export local devhub_username=$1
|
280
|
+
export local package_name=$2
|
281
|
+
echo "devhub_username=$devhub_username" >&2
|
282
|
+
echo "package_name=$package_name" >&2
|
283
|
+
|
284
|
+
# Check environment variables
|
285
|
+
if [ ! $package_name ]; then
|
286
|
+
echo "no package name argument provided, defaulting to environment variable PACKAGE_NAME" >&2
|
287
|
+
package_name=$PACKAGE_NAME
|
288
|
+
fi
|
289
|
+
|
290
|
+
# Check for default package directory in sfdx-project.json
|
291
|
+
if [ ! $package_name ]; then
|
292
|
+
echo "no PACKAGE_NAME environment variable set, defaulting to default package directory in sfdx-project.json" >&2
|
293
|
+
cat sfdx-project.json >&2
|
294
|
+
package_name=$(cat sfdx-project.json | jq -r '.packageDirectories[] | select(.default==true) | .package')
|
295
|
+
fi
|
296
|
+
|
297
|
+
# Check for any package directory in sfdx-project.json
|
298
|
+
if [ ! $package_name ]; then
|
299
|
+
echo "no package name found, defaulting to first package directory listed in sfdx-project.json" >&2
|
300
|
+
cat sfdx-project.json >&2
|
301
|
+
package_name=$(cat sfdx-project.json | jq -r '.packageDirectories | .[0] | .package')
|
302
|
+
fi
|
303
|
+
|
304
|
+
# Giving up
|
305
|
+
if [ ! $package_name ]; then
|
306
|
+
echo "ERROR Package name not specified. Set the PACKAGE_NAME environment variable or specify a default package directory in sfdx-project.json." >&2
|
307
|
+
exit 1
|
308
|
+
fi
|
309
|
+
|
310
|
+
# Retrieve package id for package name
|
311
|
+
local cmd="sfdx force:package:list --targetdevhubusername $devhub_username --json" && (echo $cmd >&2)
|
312
|
+
local output=$($cmd) && (echo $output | jq '.' >&2)
|
313
|
+
package_id=$(jq -r '.result[] | select(.Name == env.package_name) | .Id' <<< $output)
|
314
|
+
if [ ! $package_id ]; then
|
315
|
+
echo "ERROR We could not find a package with name '$package_name' owned by this Dev Hub org." >&2
|
316
|
+
exit 1
|
317
|
+
fi
|
318
|
+
|
319
|
+
echo "package_name=$package_name" >&2
|
320
|
+
echo "package_id=$package_id" >&2
|
321
|
+
|
322
|
+
# Send back the package id as the output from this command
|
323
|
+
echo $package_id
|
324
|
+
}
|
325
|
+
|
326
|
+
|
327
|
+
# Function to ensure sfdx-project.json has a package alias entry for the package id.
|
328
|
+
# Arguments:
|
329
|
+
# $1 = dev hub alias that owns the package id
|
330
|
+
# $2 = package id, the value for the package alias
|
331
|
+
|
332
|
+
function add_package_alias() {
|
333
|
+
|
334
|
+
export local devhub_username=$1
|
335
|
+
export local package_id=$2
|
336
|
+
|
337
|
+
# Retrieve package name for package id
|
338
|
+
local cmd="sfdx force:package:list --targetdevhubusername $devhub_username --json" && (echo $cmd >&2)
|
339
|
+
local output=$($cmd) && (echo $output | jq '.' >&2)
|
340
|
+
package_name=$(jq -r '.result[] | select(.Id == env.package_id) | .Name' <<< $output)
|
341
|
+
if [[ -z "$package_name" || $package_name == null ]]; then
|
342
|
+
echo "ERROR We could not find a package with id '$package_id' owned by this Dev Hub org." >&2
|
343
|
+
exit 1
|
344
|
+
fi
|
345
|
+
|
346
|
+
# Check if the alias property in sfdx-project.json contains key for package name
|
347
|
+
cat sfdx-project.json >&2
|
348
|
+
local packageAlias=$(jq -r '.packageAliases["'$package_name'"]' < sfdx-project.json)
|
349
|
+
|
350
|
+
# If no package alias, then add one
|
351
|
+
if [[ -z "$packageAlias" || $packageAlias == null ]]; then
|
352
|
+
local tmp=$(mktemp)
|
353
|
+
jq '.packageAliases["'$package_name'"]="'$package_id'"' sfdx-project.json > $tmp
|
354
|
+
mv $tmp sfdx-project.json
|
355
|
+
echo "added package alias property to sfdx-project.json" >&2
|
356
|
+
cat sfdx-project.json >&2
|
357
|
+
fi
|
358
|
+
|
359
|
+
}
|
360
|
+
|
361
|
+
|
362
|
+
# Function to build a package version.
|
363
|
+
# Arguments:
|
364
|
+
# $1 = dev hub alias
|
365
|
+
# $2 = package id
|
366
|
+
# Returns the created package version id.
|
367
|
+
|
368
|
+
function build_package_version() {
|
369
|
+
|
370
|
+
export local devhub_username=$1
|
371
|
+
export local package_id=$2
|
372
|
+
echo "devhub_username=$devhub_username" >&2
|
373
|
+
echo "package_id=$package_id" >&2
|
374
|
+
|
375
|
+
# Create a new package version
|
376
|
+
local cmd="sfdx force:package:version:create --targetdevhubusername $devhub_username --package $package_id --installationkeybypass --wait 10 --json" && (echo $cmd >&2)
|
377
|
+
local output=$($cmd) && (echo $output | jq '.' >&2)
|
378
|
+
local subscriber_package_version_id=$(jq -r '.result.SubscriberPackageVersionId' <<< $output)
|
379
|
+
|
380
|
+
if [[ -z "$subscriber_package_version_id" || $subscriber_package_version_id == null ]]; then
|
381
|
+
echo "ERROR No subscriber package version found for package id '$package_id'" >&2
|
382
|
+
exit 1
|
383
|
+
fi
|
384
|
+
|
385
|
+
# Send back the package version id as the output from this command
|
386
|
+
echo $subscriber_package_version_id
|
387
|
+
}
|
388
|
+
|
389
|
+
|
390
|
+
# Install a package version.
|
391
|
+
# Arguments:
|
392
|
+
# $1 = target username where to install package version
|
393
|
+
# $2 = package version id to install
|
394
|
+
|
395
|
+
function install_package_version() {
|
396
|
+
|
397
|
+
local org_username=$1
|
398
|
+
local package_version_id=$2
|
399
|
+
|
400
|
+
echo "org_username=$org_username" >&2
|
401
|
+
echo "package_version_id=$package_version_id" >&2
|
402
|
+
|
403
|
+
if [[ -z "$org_username" || $org_username == null ]]; then
|
404
|
+
echo "ERROR No org username provided to 'install_package_version' function" >&2
|
405
|
+
exit 1
|
406
|
+
fi
|
407
|
+
|
408
|
+
if [[ -z "$package_version_id" || $package_version_id == null ]]; then
|
409
|
+
echo "ERROR No package version id provided to 'install_package_version' function" >&2
|
410
|
+
exit 1
|
411
|
+
fi
|
412
|
+
|
413
|
+
# install the package
|
414
|
+
local cmd="sfdx force:package:install --targetusername $org_username --package $package_version_id --wait 10 --publishwait 10 --noprompt --json" && (echo $cmd >&2)
|
415
|
+
local output=$($cmd) && (echo $output | jq '.' >&2)
|
416
|
+
|
417
|
+
# assert no error response
|
418
|
+
local exit_code=$(jq -r '.exitCode' <<< $output) && (echo $exit_code >&2)
|
419
|
+
if [[ ( -n "$exit_code" ) && ( $exit_code -gt 0 ) ]]; then
|
420
|
+
exit 1
|
421
|
+
fi
|
422
|
+
|
423
|
+
}
|
424
|
+
|
425
|
+
|
426
|
+
# Promote package version.
|
427
|
+
# Only required in production.
|
428
|
+
# Arguments:
|
429
|
+
# $1 = target dev hub that owns the package to promote
|
430
|
+
# $2 = package version id to promote
|
431
|
+
|
432
|
+
function promote_package_version() {
|
433
|
+
local devhub_username=$1
|
434
|
+
local package_version_id=$2
|
435
|
+
echo "devhub_username=$devhub_username" >&2
|
436
|
+
echo "package_version_id=$package_version_id" >&2
|
437
|
+
local cmd="sfdx force:package:version:promote --targetdevhubusername $devhub_username --package $package_version_id --noprompt --json" && (echo $cmd >&2)
|
438
|
+
local output=$($cmd) && (echo $output | jq '.' >&2)
|
439
|
+
}
|
440
|
+
|
441
|
+
|
442
|
+
# Populate the URL artifact with HTML to redirect to an environment.
|
443
|
+
# Generates the URL to open the given org, and writes it to a file ENVIRONMENT.html to be shared as an artifact between stages.
|
444
|
+
# NOTE: This is a tokenized URL and must be kept secret!
|
445
|
+
# Arguments:
|
446
|
+
# $1 = org alias to get access url to
|
447
|
+
# (Assumes you are authorized to that org)
|
448
|
+
|
449
|
+
function populate_scratch_org_redirect_html() {
|
450
|
+
|
451
|
+
local org_username=$1
|
452
|
+
|
453
|
+
if [ ! $org_username ]; then
|
454
|
+
echo "ERROR No org username provided to 'populate_scratch_org_redirect_html' function" >&2
|
455
|
+
exit 1;
|
456
|
+
fi
|
457
|
+
|
458
|
+
local cmd="sfdx force:org:open --targetusername $org_username --urlonly --json" && (echo $cmd >&2)
|
459
|
+
local output=$($cmd) # don't echo/expose the output which contains the auth url
|
460
|
+
local url=$(jq -r ".result.url" <<< $output)
|
461
|
+
|
462
|
+
local environment_html="<script>window.onload=function(){window.location.href=\"$url\"}</script>"
|
463
|
+
echo "$environment_html" > ENVIRONMENT.html
|
464
|
+
echo "To browse the scratch org, click 'Browse' under 'Job artifacts' and select 'ENVIRONMENT.html'"
|
465
|
+
}
|
466
|
+
|
467
|
+
|
468
|
+
# Create a scratch org and deploy to it.
|
469
|
+
# Arguments:
|
470
|
+
# $1 = dev hub alias
|
471
|
+
# $2 = org name for the scratch org
|
472
|
+
# Populates artifacts for the username and the auth url
|
473
|
+
|
474
|
+
function deploy_scratch_org() {
|
475
|
+
local devhub=$1
|
476
|
+
local orgname=$2
|
477
|
+
assert_within_limits $devhub DailyScratchOrgs
|
478
|
+
local scratch_org_username=$(create_scratch_org $devhub $orgname)
|
479
|
+
echo $scratch_org_username > SCRATCH_ORG_USERNAME.txt
|
480
|
+
get_org_auth_url $scratch_org_username > SCRATCH_ORG_AUTH_URL.txt
|
481
|
+
push_to_scratch_org $scratch_org_username
|
482
|
+
populate_scratch_org_redirect_html $scratch_org_username
|
483
|
+
echo "Deployed to scratch org $username for $orgname"
|
484
|
+
}
|
485
|
+
|
486
|
+
|
487
|
+
# Create a new scratch org
|
488
|
+
# Arguments:
|
489
|
+
# $1 = dev hub alias
|
490
|
+
# $2 = org name for the scratch org
|
491
|
+
# Populates the artifacts for username and auth url
|
492
|
+
# Returns the newly-created scratch org username.
|
493
|
+
|
494
|
+
function create_scratch_org() {
|
495
|
+
local devhub=$1
|
496
|
+
export local orgname=$2
|
497
|
+
|
498
|
+
# Create the scratch org
|
499
|
+
local cmd="sfdx force:org:create --targetdevhubusername $devhub --wait 10 --durationdays 30 --definitionfile config/project-scratch-def.json orgName=$orgname --json" && (echo $cmd >&2)
|
500
|
+
local output=$($cmd) && (echo $output | jq '.' >&2)
|
501
|
+
scratch_org_username="$(jq -r '.result.username' <<< $output)"
|
502
|
+
echo $scratch_org_username > SCRATCH_ORG_USERNAME.txt
|
503
|
+
|
504
|
+
# Get the auth URL
|
505
|
+
local cmd="sfdx force:org:display --verbose --targetusername $org_username --json" && (echo $cmd >&2)
|
506
|
+
local output=$($cmd)
|
507
|
+
org_auth_url="$(jq -r '.result.sfdxAuthUrl' <<< $output)"
|
508
|
+
echo $org_auth_url > SCRATCH_ORG_AUTH_URL.txt
|
509
|
+
|
510
|
+
echo $scratch_org_username
|
511
|
+
}
|
512
|
+
|
513
|
+
|
514
|
+
# Get scratch org usernames
|
515
|
+
# Arguments:
|
516
|
+
# $1 = username or alias for the dev hub
|
517
|
+
# $2 = org name value for the scratch orgs
|
518
|
+
# Returns one or more usernames (newline-separated)
|
519
|
+
|
520
|
+
function get_scratch_org_usernames() {
|
521
|
+
local devhub=$1
|
522
|
+
local orgname=$2
|
523
|
+
local result=$(sfdx force:data:soql:query --targetusername $devhub --query "SELECT SignupUsername FROM ScratchOrgInfo WHERE OrgName='$orgname'" --json)
|
524
|
+
local usernames=$(jq -r ".result.records|map(.SignupUsername)|.[]" <<< $result)
|
525
|
+
echo $usernames
|
526
|
+
}
|
527
|
+
|
528
|
+
|
529
|
+
# Push to scratch org.
|
530
|
+
# Arguments
|
531
|
+
# $1 = scratch org username
|
532
|
+
|
533
|
+
function push_to_scratch_org() {
|
534
|
+
|
535
|
+
local scratch_org_username=$1
|
536
|
+
|
537
|
+
if [ ! $scratch_org_username ]; then
|
538
|
+
echo "ERROR No scratch org username provided to 'push_to_scratch_org' function" >&2
|
539
|
+
exit 1;
|
540
|
+
fi
|
541
|
+
|
542
|
+
# Create a default package.json if file doesn't exist
|
543
|
+
if [ ! -f "package.json" ]; then
|
544
|
+
npm init -y
|
545
|
+
fi
|
546
|
+
|
547
|
+
# Check if the scripts property in package.json contains key for "scratch:deploy"
|
548
|
+
cat package.json >&2
|
549
|
+
local scriptValue=$(jq -r '.scripts["scratch:deploy"]' < package.json)
|
550
|
+
|
551
|
+
# If no "scratch:deploy" script property, then add one
|
552
|
+
if [[ -z "$scriptValue" || $scriptValue == null ]]; then
|
553
|
+
local tmp=$(mktemp)
|
554
|
+
jq '.scripts["scratch:deploy"]="sfdx force:source:push"' package.json > $tmp
|
555
|
+
mv $tmp package.json
|
556
|
+
echo "added scratch:deploy script property to package.json" >&2
|
557
|
+
cat package.json >&2
|
558
|
+
fi
|
559
|
+
|
560
|
+
# Set the default username so any CLI commands
|
561
|
+
# the developer has set in their "test:apex" script in package.json
|
562
|
+
# will operate on the correct environment.
|
563
|
+
# Afterwards, restore the original default username, just in case it was different.
|
564
|
+
local old_org_username=$(jq -r '.result[].value' <<< $(sfdx force:config:get defaultusername --json))
|
565
|
+
sfdx force:config:set defaultusername=$scratch_org_username
|
566
|
+
npm run scratch:deploy
|
567
|
+
sfdx force:config:set defaultusername=$old_org_username
|
568
|
+
|
569
|
+
}
|
570
|
+
|
571
|
+
|
572
|
+
# Delete all scratch orgs associated with a ref
|
573
|
+
# Arguments
|
574
|
+
# $1 = dev hub username
|
575
|
+
# $2 = org name property of scratch orgs to delete
|
576
|
+
|
577
|
+
function delete_scratch_orgs() {
|
578
|
+
local devhub_username=$1
|
579
|
+
local scratch_org_name=$2
|
580
|
+
local usernames=$(get_scratch_org_usernames $devhub_username $scratch_org_name)
|
581
|
+
for scratch_org_username in $usernames; do
|
582
|
+
echo "Deleting $scratch_org_username"
|
583
|
+
local cmd="sfdx force:data:record:delete --sobjecttype ScratchOrgInfo --targetusername $devhub_username --where "'"SignupUsername='$scratch_org_username'"'" --json" && (echo $cmd >&2)
|
584
|
+
local output=$($cmd) && (echo $output | jq '.' >&2)
|
585
|
+
done
|
586
|
+
}
|
587
|
+
|
14
588
|
test:
|
15
589
|
stage: test
|
16
590
|
script:
|
591
|
+
- *sfdx_helpers
|
592
|
+
# Decrypt server key
|
593
|
+
- openssl aes-256-cbc -d -md md5 -in assets/server.key.enc -out assets/server.key -k $SERVER_KEY_PASSWORD
|
594
|
+
- ls -la assets
|
595
|
+
# Install jq
|
596
|
+
- apt update && apt -y install jq
|
597
|
+
- install_salesforce_cli
|
598
|
+
# Integrated test
|
17
599
|
- ruby -v
|
18
600
|
- which ruby
|
19
601
|
- gem install bundler rake
|
20
602
|
- bundle install
|
603
|
+
- sfdx force:auth:jwt:grant --clientid "$SF_CONSUMER_KEY" --jwtkeyfile assets/server.key --username "$SF_USERNAME" --setdefaultdevhubusername --setalias HubOrg
|
604
|
+
- bundle exec rake check_oauth
|
21
605
|
- bundle exec rake leaps:create_soql_objects
|
22
606
|
- bundle exec rake leaps:create_enums
|
23
|
-
- bundle exec rake
|
607
|
+
- bundle exec rake
|
608
|
+
|
609
|
+
#before_script:
|
610
|
+
# - *sfdx_helpers
|
data/.idea/.rakeTasks
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
2
|
<Settings><!--This file was automatically generated by Ruby plugin.
|
3
3
|
You are allowed to:
|
4
4
|
1. Remove rake task
|
5
5
|
2. Add existing rake tasks
|
6
6
|
To add existing rake tasks automatically delete this file and reload the project.
|
7
|
-
--><RakeGroup description="" fullCmd="" taksId="rake"><RakeTask description="Build leap_salesforce-0.
|
7
|
+
--><RakeGroup description="" fullCmd="" taksId="rake"><RakeTask description="Build leap_salesforce-0.2.0.gem into the pkg directory" fullCmd="build" taksId="build" /><RakeTask description="Check Salesforce OAuth2 authentication is working" fullCmd="check_oauth" taksId="check_oauth" /><RakeTask description="Remove any temporary products" fullCmd="clean" taksId="clean" /><RakeTask description="Remove any generated files" fullCmd="clobber" taksId="clobber" /><RakeTask description="Build and install leap_salesforce-0.2.0.gem into system gems" fullCmd="install" taksId="install" /><RakeGroup description="" fullCmd="" taksId="install"><RakeTask description="Build and install leap_salesforce-0.2.0.gem into system gems without network access" fullCmd="install:local" taksId="local" /></RakeGroup><RakeGroup description="" fullCmd="" taksId="leaps"><RakeTask description="Create objects, fields, enums" fullCmd="leaps:create_all" taksId="create_all" /><RakeTask description="Create Enumeration objects for picklists from Salesforce Metadata" fullCmd="leaps:create_enums" taksId="create_enums" /><RakeTask description="Create Soql Data objects" fullCmd="leaps:create_soql_objects" taksId="create_soql_objects" /></RakeGroup><RakeTask description="Create tag v0.2.0 and build and push leap_salesforce-0.2.0.gem to rubygems.org" fullCmd="release[remote]" taksId="release[remote]" /><RakeTask description="Run RSpec code examples" fullCmd="spec" taksId="spec" /><RakeTask description="Create stubs for dynamic methods so they're picked up by the IDE" fullCmd="stub" taksId="stub" /><RakeGroup description="" fullCmd="" taksId="yard"><RakeTask description="Run YARD doctests" fullCmd="yard:doctest" taksId="doctest" /></RakeGroup><RakeTask description="" fullCmd="default" taksId="default" /><RakeTask description="" fullCmd="release" taksId="release" /><RakeGroup description="" fullCmd="" taksId="release"><RakeTask description="" fullCmd="release:guard_clean" taksId="guard_clean" /><RakeTask description="" fullCmd="release:rubygem_push" taksId="rubygem_push" /><RakeTask description="" fullCmd="release:source_control_push" taksId="source_control_push" /></RakeGroup></RakeGroup></Settings>
|
data/.idea/leap-salesforce.iml
CHANGED
@@ -21,7 +21,7 @@
|
|
21
21
|
<orderEntry type="library" scope="PROVIDED" name="diff-lcs (v1.3, RVM: ruby-2.6.0) [gem]" level="application" />
|
22
22
|
<orderEntry type="library" scope="PROVIDED" name="domain_name (v0.5.20190701, RVM: ruby-2.6.0) [gem]" level="application" />
|
23
23
|
<orderEntry type="library" scope="PROVIDED" name="factory_bot (v5.0.2, RVM: ruby-2.6.0) [gem]" level="application" />
|
24
|
-
<orderEntry type="library" scope="PROVIDED" name="faker (v2.1
|
24
|
+
<orderEntry type="library" scope="PROVIDED" name="faker (v2.2.1, RVM: ruby-2.6.0) [gem]" level="application" />
|
25
25
|
<orderEntry type="library" scope="PROVIDED" name="gyoku (v1.3.1, RVM: ruby-2.6.0) [gem]" level="application" />
|
26
26
|
<orderEntry type="library" scope="PROVIDED" name="hashie (v3.6.0, RVM: ruby-2.6.0) [gem]" level="application" />
|
27
27
|
<orderEntry type="library" scope="PROVIDED" name="http-accept (v1.7.0, RVM: ruby-2.6.0) [gem]" level="application" />
|
@@ -67,7 +67,7 @@
|
|
67
67
|
<orderEntry type="library" scope="PROVIDED" name="sinatra (v2.0.4, RVM: ruby-2.6.0) [gem]" level="application" />
|
68
68
|
<orderEntry type="library" scope="PROVIDED" name="sinatra-basic-auth (v0.1.0, RVM: ruby-2.6.0) [gem]" level="application" />
|
69
69
|
<orderEntry type="library" scope="PROVIDED" name="sinatra-docdsl (v0.8.6, RVM: ruby-2.6.0) [gem]" level="application" />
|
70
|
-
<orderEntry type="library" scope="PROVIDED" name="soaspec (v0.2.
|
70
|
+
<orderEntry type="library" scope="PROVIDED" name="soaspec (v0.2.32, RVM: ruby-2.6.0) [gem]" level="application" />
|
71
71
|
<orderEntry type="library" scope="PROVIDED" name="socksify (v1.7.1, RVM: ruby-2.6.0) [gem]" level="application" />
|
72
72
|
<orderEntry type="library" scope="PROVIDED" name="thor (v0.20.3, RVM: ruby-2.6.0) [gem]" level="application" />
|
73
73
|
<orderEntry type="library" scope="PROVIDED" name="thread_safe (v0.3.6, RVM: ruby-2.6.0) [gem]" level="application" />
|
@@ -84,4 +84,8 @@
|
|
84
84
|
<orderEntry type="library" scope="PROVIDED" name="yard-doctest (v0.1.16, RVM: ruby-2.6.0) [gem]" level="application" />
|
85
85
|
<orderEntry type="library" scope="PROVIDED" name="zeitwerk (v2.1.9, RVM: ruby-2.6.0) [gem]" level="application" />
|
86
86
|
</component>
|
87
|
+
<component name="RModuleSettingsStorage">
|
88
|
+
<LOAD_PATH number="1" string0="$MODULE_DIR$/spec/support" />
|
89
|
+
<I18N_FOLDERS number="0" />
|
90
|
+
</component>
|
87
91
|
</module>
|