Skip to content

Commit 31a3036

Browse files
authored
Pipeline improvements (#6)
* Pipeline improvements
1 parent 9f9da16 commit 31a3036

File tree

7 files changed

+30
-58
lines changed

7 files changed

+30
-58
lines changed

.forceignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# .forceignore v2
2+
**/jsconfig.json
3+
**/.eslintrc.json
4+
**/__tests__

.github/workflows/deploy.yml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,17 @@ jobs:
7676
- name: Install & run SFDX Scanner
7777
run: npm run scan
7878

79-
# Store secret for dev hub
80-
- name: 'Populate auth file with DEVHUB_SFDX_URL secret'
79+
# Authenticate using JWT flow
80+
- name: 'Auth to dev hub'
8181
shell: bash
8282
run: |
83-
echo ${{ env.DEVHUB_SFDX_URL }} > ./DEVHUB_SFDX_URL.txt
83+
echo "${{ env.DEVHUB_SERVER_KEY }}" > ./jwt-server.key
84+
npx sfdx force:auth:jwt:grant --clientid ${{ env.DEVHUB_CONSUMER_KEY }} --username ${{ env.DEVHUB_USERNAME }} --jwtkeyfile ./jwt-server.key --setdefaultdevhubusername
85+
npx sfdx config:set defaultusername=${{ env.DEVHUB_USERNAME }}
8486
env:
85-
DEVHUB_SFDX_URL: ${{ secrets.DEVHUB_SFDX_URL }}
87+
DEVHUB_USERNAME: ${{ secrets.DEVHUB_USERNAME }}
88+
DEVHUB_CONSUMER_KEY: ${{ secrets.DEVHUB_CONSUMER_KEY }}
89+
DEVHUB_SERVER_KEY: ${{ secrets.DEVHUB_SERVER_KEY }}
8690

8791
- name: 'Deploy & Test'
8892
shell: pwsh

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55

66
## Deployment
77

8-
<a href="https://login.salesforce.com/packaging/installPackage.apexp?p0=04t6g000008SjREAA0">
8+
<a href="https://login.salesforce.com/packaging/installPackage.apexp?p0=04t6g000008SjZEAA0">
99
<img alt="Deploy to Salesforce"
1010
src="./media/deploy-package-to-prod.png">
1111
</a>
1212

13-
<a href="https://test.salesforce.com/packaging/installPackage.apexp?p0=04t6g000008SjREAA0">
13+
<a href="https://test.salesforce.com/packaging/installPackage.apexp?p0=04t6g000008SjZEAA0">
1414
<img alt="Deploy to Salesforce Sandbox"
1515
src="./media/deploy-package-to-sandbox.png">
1616
</a>

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "salesforce-round-robin",
3-
"version": "0.0.3",
3+
"version": "0.0.4",
44
"description": "Round robin records in Salesforce (SFDC) using Flow or Apex. Performant, fair, fast assignment with configurable user pools",
55
"repository": {
66
"type": "git",

scripts/build-and-promote-package.ps1

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,6 @@ function Start-Package-Promotion {
2525
Write-Debug "Finished package promotion!"
2626
}
2727

28-
if(Test-Path ".\DEVHUB_SFDX_URL.txt") {
29-
npx sfdx auth:sfdxurl:store -f ./DEVHUB_SFDX_URL.txt -a packaging-org
30-
npx sfdx force:config:set defaultdevhubusername=packaging-org
31-
} else {
32-
throw 'No packaging auth info!'
33-
}
34-
3528
# Create/promote package version(s)
3629
$currentBranch = Get-Current-Git-Branch
3730
if ($currentBranch -eq "main") {

scripts/test.ps1

Lines changed: 12 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -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

813
function 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-
3635
Write-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

4739
Write-Debug "Total remaining scratch orgs for the day: $scratchOrgAllotment"
4840
Write-Debug "Test command to use: $testInvocation"
4941

50-
$shouldDeployToSandbox = $false
51-
5242
if($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

8555
Write-Debug "Build + testing finished successfully"
8656

sfdx-project.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"package": "salesforce-round-robin",
77
"path": "core",
88
"versionName": "Better error handling when assignment Ids don't exist",
9-
"versionNumber": "0.0.3.0",
9+
"versionNumber": "0.0.4.0",
1010
"versionDescription": "Invocable & Apex-ready Round Robin Assigner for Salesforce Flow, Process Builder, Apex and more",
1111
"releaseNotesUrl": "https://github.com/jamessimone/salesforce-round-robin/releases/latest"
1212
},
@@ -21,6 +21,7 @@
2121
"salesforce-round-robin": "0Ho6g000000GnClCAK",
2222
"[email protected]": "04t6g000008SjNvAAK",
2323
"[email protected]": "04t6g000008SjOFAA0",
24-
"[email protected]": "04t6g000008SjREAA0"
24+
"[email protected]": "04t6g000008SjREAA0",
25+
"[email protected]": "04t6g000008SjZEAA0"
2526
}
2627
}

0 commit comments

Comments
 (0)