start-packaging #45
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Unique name for this workflow | |
name: Packaging | |
# Workflow starts when receiving start-packaging custom event | |
# Event contains the packageName of the target package for which a new version will be released | |
on: | |
repository_dispatch: | |
types: [start-packaging] | |
# Jobs to be executed | |
jobs: | |
release-package-version: | |
runs-on: trailheadapps-Ubuntu | |
strategy: | |
matrix: | |
package: ${{ github.event.client_payload.packageNames }} | |
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@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: 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": "autocomp",' sfdx-project.json | |
# Add namespace to CPEs | |
- name: 'Add namespace to Custom Property Editors' | |
run: | | |
find . -type f -name "*.js-meta.xml" -print0 | xargs -0 sed -i 's,configurationEditor="c-,configurationEditor="autocomp-,' | |
# Create package version and extract its id | |
- name: 'Create package version' | |
id: createPackageVersion | |
run: | | |
set +e | |
packageName="${{ matrix.package }}" | |
json=$(sf package version create -p "$packageName" -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 (360s)' | |
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 --no-namespace -c | |
# 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: | | |
packageName="${{ matrix.package }}" | |
packageVersionId="${{ steps.createPackageVersion.outputs.packageVersionId }}" | |
packageLinkRegex="<a name=\"$packageName\" href=\"https:\/\/login\.salesforce\.com\/packaging\/installPackage\.apexp\?p0=[a-zA-ZA-ZA-Z0-9]{18}\">" | |
newPackageLink="<a name=\"${packageName}\" href=\"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 -p ${{ steps.createPackageVersion.outputs.packageVersionId }} -n | |
# Revert namespace change in project config | |
- name: 'Revert namespace change in project config' | |
run: | | |
sed -i 's,"namespace": "autocomp","namespace": "",' sfdx-project.json | |
# Revert namespace changes in CPEs | |
- name: 'Revert namespace changes in Custom Property Editors' | |
run: git checkout **/*.js-meta.xml | |
# Create PR for new package version | |
- name: 'Create PR for new package version' | |
id: create-pr | |
uses: peter-evans/create-pull-request@v4 | |
with: | |
title: 'Package: ${{ matrix.package }} - New version: ${{ steps.createPackageVersion.outputs.packageVersionId }}' | |
body: 'Released new package version ${{ steps.createPackageVersion.outputs.packageVersionId }} for package ${{ matrix.package }}' | |
author: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> | |
commit-message: 'Package: ${{ matrix.package }} - New version: ${{ steps.createPackageVersion.outputs.packageVersionId }}' | |
branch: 'auto/package-version-${{ steps.createPackageVersion.outputs.packageVersionId }}' | |
token: ${{ secrets.BOT_ACCESS_TOKEN }} | |
# Wait for PR to stabilize (auto skip CI) | |
- name: 'Wait for PR to stabilize (60s)' | |
run: sleep 60s | |
shell: bash | |
# Approve and mark PR for auto merge | |
- name: 'Approve and mark PR for auto merge' | |
run: | | |
gh pr review --approve "$PR_NUMBER" | |
gh pr merge --auto --squash "$PR_NUMBER" | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
PR_NUMBER: ${{ steps.create-pr.outputs.pull-request-number }} | |
# Housekeeping | |
- name: 'Delete scratch org' | |
if: always() | |
run: sf org delete scratch -p -o scratch-org |