Skip to content

Instantly share code, notes, and snippets.

@sjurgis
Last active December 8, 2021 15:15
Show Gist options
  • Save sjurgis/b0414f9fd0d38caef0373ee6b03da957 to your computer and use it in GitHub Desktop.
Save sjurgis/b0414f9fd0d38caef0373ee6b03da957 to your computer and use it in GitHub Desktop.
salesforce second generation package create, install and test using github actions
#!/bin/bash
set -e
set -o pipefail
CLIENT_ID=$1
rm -f ./server.key
cat > ./server.key
sfdx auth:jwt:grant --setdefaultusername --clientid "$CLIENT_ID" --jwtkeyfile ./server.key --username [email protected] -a HubOrg
mv .forceignore .forceignore.orig
sed '/mypackage2/d' .forceignore.orig | tee .forceignore
package=$(sfdx force:package:version:create -a "Created by Github Action" --package "myns-beta" --wait 20 -x --postinstallscript=PostInstallScript -v HubOrg --json | jq ".result")
rm .forceignore
mv .forceignore.orig .forceignore
packageId=$(echo $package | jq -r .SubscriberPackageVersionId)
packageVersion=$(sfdx force:package:version:report -p $packageId --json -v HubOrg | jq -r ".result.Version")
echo LAST_PACKAGE=$packageId >> $GITHUB_ENV
echo LAST_PACKAGE_VERSION=$packageVersion >> $GITHUB_ENV
org=$(sfdx force:org:create -s -f ./config/project-scratch-def.json --nonamespace -v HubOrg --json)
sfdx force:package:install -p $packageId -r -w 20
sfdx force:source:deploy -p unpackaged/remoteSiteSettings
username=$(echo $org | jq -r ".result.username")
password=$(sfdx force:user:password:generate -v HubOrg --json | jq -r ".result.password")
loginLink=$(sfdx force:org:open -u $username -r --json | jq -r ".result.url")
echo ORG_PASSWORD=$password >> $GITHUB_ENV
echo ORG_USERNAME=$username >> $GITHUB_ENV
echo ORG_URL=$loginLink >> $GITHUB_ENV
rm -f ./server.key
name: Beta release
on:
workflow_dispatch:
pull_request:
types: [labeled]
jobs:
beta-release:
if: ${{ contains(github.event.pull_request.labels.*.name, 'Beta Release') }}
runs-on: ubuntu-latest
steps:
- name: Set environment variables
run: |
echo "SFDX_IMPROVED_CODE_COVERAGE=true" >> $GITHUB_ENV
echo "SFDX_DISABLE_SOURCE_MEMBER_POLLING=true" >> $GITHUB_ENV
- name: Checkout
uses: actions/checkout@v1
- name: Install sfdx
uses: sfdx-actions/setup-sfdx@v1
- name: Create beta release and install
run: echo "${{secrets.DEVHUB_CI_CERT_2021_PRIVATEKEY}}" | ./scripts/testBetaRelease.sh "${{secrets.DEVHUB_CI_CERT_2021_CONSUMERKEY}}"
- name: Clear defaults and setup new ones
run: |
echo "delete [SELECT Id FROM myns__Configuration__c]; delete [SELECT Id FROM myns__Mapping__c];" | sfdx force:apex:execute
sfdx force:org:open -r
sfdx force:apex:execute -f scripts/insertConfiguration.apex
- name: Assign permset
run: sfdx force:user:permset:assign -n mypackage_Admin
- uses: actions/setup-node@v1
with:
node-version: '12'
- uses: microsoft/playwright-github-action@v1
- name: Install Dependencies
run: npm ci && npm install playwright
- name: Run UI tests
run: npm run test:ui
- name: Setup integration
run: npm run integrate
- name: Run API tests
run: npm run test:api
- name: Remove integration
timeout-minutes: 5
if: always()
run: npm run disintegrate
- name: Delete org
if: always()
run: sfdx force:org:delete -p
- name: Upload screenshots
if: failure()
uses: actions/upload-artifact@v2
with:
name: screenshots
path: screenshots/*.png
- name: Delete release
if: always()
run: sfdx force:package:version:delete -v HubOrg -n -p "${{ env.LAST_PACKAGE }}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment