@@ -2,8 +2,13 @@ $DebugPreference = 'Continue'
22$ErrorActionPreference = ' Stop'
33# This is also the same script that runs on Github via the Github Action configured in .github/workflows - there, the
44# DEVHUB_SFDX_URL.txt file is populated in a build step
5- $testInvocation = ' npx sfdx force:apex:test:run -r human -w 20 -c -d ./tests/apex'
5+ $testInvocation = ' npx sfdx force:apex:test:run -s RoundRobinTestSuite - r human -w 20 -c -d ./tests/apex'
66$scratchOrgName = ' round-robin-scratch'
7+ function Start-Deploy () {
8+ Write-Debug " Deploying source ..."
9+ npx sfdx force:source:deploy - p core
10+ npx sfdx force:source:deploy - p integration- tests
11+ }
712
813function Start-Tests () {
914 Write-Debug " Starting test run ..."
@@ -27,60 +32,25 @@ function Start-Tests() {
2732 }
2833}
2934
30- function Reset-SFDX-Json () {
31- Write-Debug " Resetting SFDX project JSON at project root"
32- Copy-Item - Path ./ scripts/ sfdx- project.json - Destination ./ sfdx- project.json - Force
33- Remove-Item - Path ./ scripts/ sfdx- project.json
34- }
35-
3635Write-Debug " Starting build script"
3736
38- # Authorize Dev Hub using prior creds. There's some issue with the flags --setdefaultdevhubusername and --setdefaultusername both being passed when run remotely
39-
40- npx sfdx auth:sfdxurl:store -f ./ DEVHUB_SFDX_URL.txt - a round- robin
41- npx sfdx config:set defaultusername= round- robin defaultdevhubusername= round- robin
42-
43- # For local dev, store currently auth'd org to return to
44- # Also store test command shared between script branches, below
4537$scratchOrgAllotment = ((npx sfdx force:limits:api:display -- json | ConvertFrom-Json ).result | Where-Object - Property name -eq " DailyScratchOrgs" ).remaining
4638
4739Write-Debug " Total remaining scratch orgs for the day: $scratchOrgAllotment "
4840Write-Debug " Test command to use: $testInvocation "
4941
50- $shouldDeployToSandbox = $false
51-
5242if ($scratchOrgAllotment -gt 0 ) {
53- Write-Debug " Beginning scratch org creation"
54- # Create Scratch Org
55- $scratchOrgCreateMessage = npx sfdx force:org:create -f config/ project- scratch- def.json - a $scratchOrgName - s - d 1
56- # Sometimes SFDX lies (UTC date problem?) about the number of scratch orgs remaining in a given day
57- # The other issue is that this doesn't throw, so we have to test the response message ourselves
58- if ($scratchOrgCreateMessage -eq ' The signup request failed because this organization has reached its active scratch org limit' ) {
59- throw $1
60- }
61- # Deploy
62- Write-Debug ' Pushing source to scratch org ...'
63- npx sfdx force:source:push
64- # Run tests
65- Start-Tests
66- } else {
67- $shouldDeployToSandbox = $true
68- }
69-
70- if ($shouldDeployToSandbox ) {
71- Write-Debug " No scratch orgs remaining, running tests on sandbox"
72-
7343 try {
74- # Deploy
75- Write-Debug " Deploying source to sandbox ..."
76- npx sfdx force:source:deploy - p core
77- npx sfdx force:source:deploy - p integration- tests
78- Start-Tests
44+ Write-Debug " Beginning scratch org creation"
45+ # Create Scratch Org
46+ npx sfdx force:org:create -f config/ project- scratch- def.json - a $scratchOrgName - s - d 1
7947 } catch {
80- throw ' Error deploying to sandbox! '
48+ # Do nothing, we'll just try to deploy to the Dev Hub instead
8149 }
8250}
8351
52+ Start-Deploy
53+ Start-Tests
8454
8555Write-Debug " Build + testing finished successfully"
8656
0 commit comments