Skip to content

Commit f1b984c

Browse files
committed
Updating build script to increase resiliency and reduce verbosity
1 parent 74e1bb2 commit f1b984c

File tree

1 file changed

+23
-21
lines changed

1 file changed

+23
-21
lines changed

scripts/test.ps1

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,12 @@
11

22
# This is also the same script that runs on Github via the Github Action configured in .github/workflows - there, the
33
# DEVHUB_SFDX_URL.txt file is populated in a build step
4-
$testInvocation = 'sfdx force:apex:test:run -n "RollupTests, RollupEvaluatorTests, RollupFieldInitializerTests, RollupCalculatorTests, RollupIntegrationTests, RollupFlowBulkProcessorTests" -c -d ./tests/apex -r json -w 20'
4+
$testInvocation = 'sfdx force:apex:test:run -n "RollupTests, RollupEvaluatorTests, RollupFieldInitializerTests, RollupCalculatorTests, RollupIntegrationTests, RollupFlowBulkProcessorTests" -c -d ./tests/apex -r human -w 20'
55

66
function Start-Tests() {
77
# Run tests
88
Write-Output "Starting test run ..."
9-
$testOutput = Invoke-Expression $testInvocation | ConvertFrom-Json
10-
Write-Output $testOutput.result.summary
11-
Write-Output $testOutput.result.tests
12-
if(0 -ne $testOutput.status) {
13-
throw $testOutput
14-
}
15-
Write-Output "Tests finished running successfully"
9+
Invoke-Expression $testInvocation
1610
}
1711

1812
function Reset-SFDX-Json() {
@@ -47,26 +41,34 @@ $scratchOrgAllotment = ((sfdx force:limits:api:display --json | ConvertFrom-Json
4741
Write-Output "Total remaining scratch orgs for the day: $scratchOrgAllotment"
4842
Write-Output "Test command to use: $testInvocation"
4943

44+
$shouldDeployToSandbox = $false
45+
5046
if($scratchOrgAllotment -gt 0) {
5147
Write-Output "Beginning scratch org creation"
52-
$userNameHasBeenSet = $true
5348
# Create Scratch Org
5449
try {
55-
sfdx force:org:create -f config/project-scratch-def.json -a apex-rollup-scratch-org -s -d 1
56-
# Deploy
57-
Write-Output 'Pushing source to scratch org ...'
58-
sfdx force:source:push
59-
# Run tests
60-
Start-Tests
61-
Write-Output "Scratch org tests finished running with success: $?"
62-
# Delete scratch org
63-
sfdx force:org:delete -p -u apex-rollup-scratch-org
50+
$scratchOrgCreateMessage = sfdx force:org:create -f config/project-scratch-def.json -a apex-rollup-scratch-org -s -d 1
51+
# Sometimes SFDX lies (UTC date problem?) about the number of scratch orgs remaining in a given day
52+
# The other issue is that this doesn't throw, so we have to test the response message ourselves
53+
if($scratchOrgCreateMessage -eq 'The signup request failed because this organization has reached its active scratch org limit') {
54+
throw $1
55+
}
56+
$userNameHasBeenSet = $true
57+
# Deploy
58+
Write-Output 'Pushing source to scratch org ...'
59+
sfdx force:source:push
60+
# Run tests
61+
Start-Tests
62+
Write-Output "Scratch org tests finished running with success: $?"
63+
# Delete scratch org
64+
sfdx force:org:delete -p -u apex-rollup-scratch-org
6465
} catch {
6566
Write-Output "There was an issue with scratch org creation, continuing ..."
66-
Reset-SFDX-Json
67-
throw 'Error!'
67+
$shouldDeployToSandbox = $true
6868
}
69-
} else {
69+
}
70+
71+
if($shouldDeployToSandbox) {
7072
Write-Output "No scratch orgs remaining, running tests on sandbox"
7173

7274
try {

0 commit comments

Comments
 (0)