Packaging #26
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 | |
# 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: | | |
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 code in the pull request | |
- name: 'Checkout source code' | |
uses: actions/checkout@v2 | |
# 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 force: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 | |
# Add namespace to project config | |
- name: Add namespace to project config | |
run: | | |
sed -i 's,"namespace": "","namespace": "sfqz",' 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 | |
# 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 -c -d 1 | |
# Install new package in scratch org | |
- name: Install new package version in scratch org | |
run: sfdx force:package:install --package ${{ steps.create-package-version.outputs.packageVersionId }} -w 10 -u scratch-org -r | |
# Update package install link in readme | |
- name: Update package install link in readme | |
run: | | |
packageName="${{ github.event.client_payload.packageName }}" | |
packageVersionId="${{ steps.create-package-version.outputs.packageVersionId }}" | |
packageLinkRegex="<a name=\"$packageName\" href=\"https:\/\/login\.salesforce\.com\/packaging\/installPackage\.apexp\?p0=[a-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: sfdx force: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 |