-
Notifications
You must be signed in to change notification settings - Fork 65
139 lines (119 loc) · 5.82 KB
/
packaging.yml
File metadata and controls
139 lines (119 loc) · 5.82 KB
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# Unique name for this workflow
name: Packaging
# Definition when the workflow should run
on:
workflow_dispatch:
release:
types: [released]
# Jobs to be executed
jobs:
packaging:
runs-on: ubuntu-latest
steps:
# 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'
shell: bash
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
# Add namespace to project config
- name: Add namespace to project config
run: |
sed -i 's,"namespace": "","namespace": "sfq",' sfdx-project.json
# Remove unpackageable metadata
- name: Remove unpackageable metadata (PlatformEventChannelMember)
run: rm -fr src/main/default/platformEventChannelMembers
# Create package version and extract its id
- name: Create package version
id: create-package-version
run: |
set +e
packageName="${{ github.event.client_payload.packageName }}"
json=$(sfdx force:package:version:create -c -p Quiz -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 '.result.SubscriberPackageVersionId')
echo "::set-output name=packageVersionId::$packageVersionId"
else
echo "sfdx force:package:version:create failed"
fi
exit $status
# Create package version and extract its id
- name: 'Create package version'
id: createPackageVersion
run: |
set +e
json=$(sf package version create -p Quiz -c -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 scratch org
- name: 'Create scratch org'
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
# Update package install link in readme
- name: 'Update package install link in readme'
run: |
packageVersionId="${{ steps.createPackageVersion.outputs.packageVersionId }}"
packageLinkRegex="https:\/\/login\.salesforce\.com\/packaging\/installPackage\.apexp\?p0=[a-zA-ZA-ZA-Z0-9]{18}"
newPackageLink="https://login.salesforce.com/packaging/installPackage.apexp?p0=${packageVersionId}"
sed -E -i "s,${packageLinkRegex},${newPackageLink}," README.md
# Promote package version
- name: 'Promote package version'
run: sf package version promote --package ${{ steps.create-package-version.outputs.packageVersionId }} -n
# Update sfdx-project.json and README to use only latest package version
- name: 'Update sfdx-project.json and README'
uses: trailheadapps/github-action-sfdx-packaging-updater@main
# Remove namespace from project config
- name: Remove namespace from project config
run: |
sed -i 's,"namespace": "sfqz","namespace": "",' sfdx-project.json
# Commit project config and readme
- name: Commit project config and readme
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add sfdx-project.json
git add README.md
git commit -m "Released new package version"
# Push changes in git
- name: Push changes in git
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
# Housekeeping
- name: Delete scratch org
if: always()
run: sfdx force:org:delete -p -u scratch-org