forked from trailheadapps/apex-recipes
-
Notifications
You must be signed in to change notification settings - Fork 0
91 lines (77 loc) · 3.51 KB
/
packaging-pr.yml
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
# Unique name for this workflow
name: Packaging on PR
# Workflow starts when receiving custom event sent by CI workflow
on:
workflow_dispatch:
repository_dispatch:
types: [start-packaging-pr]
# Workflow environment variables
env:
# Is the PR base branch a prerelease branch
IS_PRERELEASE: ${{ github.event.client_payload.isPrelease }}
# Jobs to be executed
jobs:
packaging:
runs-on: trailheadapps-Ubuntu
steps:
# Install Volta to enforce proper node and package manager versions
- name: 'Install Volta'
uses: volta-cli/action@v4
# Install Salesforce CLI
- name: 'Install Salesforce CLI'
run: |
npm install @salesforce/cli --location=global
nodeInstallPath=$(npm config get prefix)
echo "$nodeInstallPath/bin" >> $GITHUB_PATH
sf --version
# Checkout the source code
- name: 'Checkout source code'
uses: actions/checkout@v4
# Store secret for dev hub
- name: 'Populate auth file with DEVHUB_SFDX_URL secret'
run: |
echo ${{ secrets.DEVHUB_SFDX_URL }} > ./DEVHUB_SFDX_URL.txt
secretFileSize=$(wc -c "./DEVHUB_SFDX_URL.txt" | awk '{print $1}')
if [ $secretFileSize == 1 ]; then
echo "Missing DEVHUB_SFDX_URL secret. Is this workflow running on a fork?";
exit 1;
fi
# Authenticate dev hub
- name: 'Authenticate Dev Hub'
run: sf org login sfdx-url -f ./DEVHUB_SFDX_URL.txt -a devhub -d
# Remove auth file
- name: 'Remove auth file'
run: rm -f ./DEVHUB_SFDX_URL.txt
# Create package version and extract its id
- name: 'Create package version'
id: createPackageVersion
run: |
sf plugins install packaging
json=$(sf package version create -p ApexRecipes -x -w 20 -f config/project-scratch-def.json --json)
echo $json
status=$(echo $json | jq '.status')
if [ $status == "0" ]; then
packageVersionId=$(echo $json | jq -r '.result.SubscriberPackageVersionId')
echo "packageVersionId=$packageVersionId" >> $GITHUB_OUTPUT
else
echo "Failed to create package version"
fi
exit $status
# Wait for package replication
- name: 'Wait for package replication'
run: sleep 360s
# Create prerelease scratch org
- name: 'Create prerelease scratch org'
if: ${{ env.IS_PRERELEASE }}
run: sf org create scratch -f config/project-scratch-def.json -a scratch-org -d -y 1 --release=preview
# Create scratch org
- name: 'Create scratch org'
if: ${{ !env.IS_PRERELEASE }}
run: sf org create scratch -f config/project-scratch-def.json -a scratch-org -d -y 1
# Install new package in scratch org
- name: 'Install new package version in scratch org'
run: sf package install -p ${{ steps.createPackageVersion.outputs.packageVersionId }} -w 10 -o scratch-org -r
# Housekeeping
- name: 'Delete scratch org'
if: always()
run: sf org delete scratch -p -o scratch-org