forked from trailheadapps/lwc-recipes
-
Notifications
You must be signed in to change notification settings - Fork 0
122 lines (106 loc) · 5.31 KB
/
packaging.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
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
# Unique name for this workflow
name: Packaging
# Workflow starts when receiving custom event sent by CI workflow
on:
repository_dispatch:
types: [start-packaging]
# Jobs to be executed
jobs:
release-package-version:
runs-on: trailheadapps-Ubuntu
steps:
# Install Salesforce CLI
- name: 'Install Salesforce CLI'
run: |
wget https://developer.salesforce.com/media/salesforce-cli/sfdx/channels/stable/sfdx-linux-x64.tar.xz
mkdir ~/sfdx
tar xJf sfdx-linux-x64.tar.xz -C ~/sfdx --strip-components 1
echo "$HOME/sfdx/bin" >> $GITHUB_PATH
~/sfdx/bin/sfdx version
# Checkout the source code
- name: 'Checkout source code'
uses: actions/checkout@v3
with:
ref: ${{ github.event.client_payload.ref }}
# 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: sfdx auth:sfdxurl:store -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: |
set +e
json=$(sfdx force:package:version:create -p LWCRecipes -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 "::set-output name=packageVersionId::$packageVersionId"
else
echo "sfdx force:package:version:create failed"
fi
exit $status
# Wait for package replication
- name: 'Wait for package replication'
uses: maddox/actions/sleep@master
with:
args: 360
# Create scratch org
- name: 'Create scratch org'
run: sfdx force:org:create -f config/project-scratch-def.json -a scratch-org -s -d 1
# Install new package in scratch org
- name: 'Install new package version in scratch org'
run: sfdx force:package:install -p ${{ steps.createPackageVersion.outputs.packageVersionId }} -w 10 -u 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
# Create PR for new package version
- name: 'Create PR for new package version'
id: create-pr
uses: peter-evans/create-pull-request@v3
with:
title: 'Released new package version ${{ steps.createPackageVersion.outputs.packageVersionId }}'
body: 'Released new package version ${{ steps.createPackageVersion.outputs.packageVersionId }}'
author: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
commit-message: 'Released new package version ${{ steps.createPackageVersion.outputs.packageVersionId }}'
branch: 'auto/release-package-version'
token: ${{ secrets.BOT_ACCESS_TOKEN }}
# Approve pull request
- name: 'Approve pull request'
uses: juliangruber/approve-pull-request-action@v1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
number: ${{ steps.create-pr.outputs.pull-request-number }}
# Wait for CI to be skipped on pull request
- name: 'Wait for CI to be skipped on pull request'
uses: maddox/actions/sleep@master
with:
args: 60
# Merge pull request
- name: 'Merge pull request'
uses: juliangruber/merge-pull-request-action@v1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
number: ${{ steps.create-pr.outputs.pull-request-number }}
method: squash
# Housekeeping
- name: 'Delete scratch org'
if: always()
run: sfdx force:org:delete -p -u scratch-org