Skip to content

Commit

Permalink
build: sf cli migration
Browse files Browse the repository at this point in the history
  • Loading branch information
pozil committed Oct 8, 2024
1 parent f8ccb25 commit ecfc60e
Show file tree
Hide file tree
Showing 5 changed files with 144 additions and 102 deletions.
75 changes: 48 additions & 27 deletions .github/workflows/ci-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,36 @@ name: CI (PR)
# Definition when the workflow should run
on:
workflow_dispatch:
inputs:
prerelease:
description: 'Run on a prerelease org?'
required: false
type: boolean
pull_request:
types: [opened, synchronize, reopened]

# Workflow environment variables
env:
# Is the PR base branch a prerelease branch
IS_PRERELEASE: ${{ startsWith(github.event.pull_request.base.ref, 'prerelease/') || inputs.prerelease }}

# Jobs to be executed
jobs:
formatting-and-lwc-tests:
runs-on: ubuntu-latest
steps:
# Checkout the code in the pull request
# Checkout the source code
- name: 'Checkout source code'
uses: actions/checkout@v2
uses: actions/checkout@v4

# Install Volta to enforce proper node and package manager versions
- name: 'Install Volta'
uses: volta-cli/action@v4

# Cache node_modules to speed up the process
- name: Restore node_modules cache
- name: 'Restore node_modules cache'
id: cache-npm
uses: actions/cache@v1
uses: actions/cache@v4
with:
path: node_modules
key: npm-${{ hashFiles('**/package-lock.json') }}
Expand All @@ -30,7 +44,7 @@ jobs:
# Install npm dependencies for Prettier and Jest
- name: 'Install npm dependencies'
if: steps.cache-npm.outputs.cache-hit != 'true'
run: npm ci
run: HUSKY=0 npm ci

# Prettier formatting
- name: 'Code formatting'
Expand All @@ -44,10 +58,11 @@ jobs:
- name: 'LWC unit tests'
run: npm run test:unit:coverage

# Upload LWC code coverage data
# Upload code coverage data
- name: 'Upload code coverage for LWC to Codecov.io'
uses: codecov/codecov-action@v1
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
flags: LWC

scratch-org-tests:
Expand All @@ -57,21 +72,20 @@ jobs:
# 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
npm install @salesforce/cli --location=global
nodeInstallPath=$(npm config get prefix)
echo "$nodeInstallPath/bin" >> $GITHUB_PATH
sf --version
# Checkout the code in the pull request
# Checkout the source code
- name: 'Checkout source code'
uses: actions/checkout@v2
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
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?";
Expand All @@ -80,35 +94,42 @@ jobs:
# Authenticate dev hub
- name: 'Authenticate Dev Hub'
run: 'sfdx force:auth:sfdxurl:store -f ./DEVHUB_SFDX_URL.txt -a devhub -d'
run: sf org login sfdx-url -f ./DEVHUB_SFDX_URL.txt -a devhub -d

# Create prerelease scratch org
- name: 'Create prerelease scratch org'
if: ${{ env.IS_PRERELEASE }}
run: sf org create scratch -f config/project-scratch-def.json -a scratch-org -d -y 1 --release=preview

# Create scratch org
- name: 'Create scratch org'
run: 'sfdx force:org:create -f config/project-scratch-def.json -a quiz-ci -c -s -d 1'
if: ${{ !env.IS_PRERELEASE }}
run: sf org create scratch -f config/project-scratch-def.json -a scratch-org -d -y 1

# Deploy source to scratch org
- name: 'Push source'
run: 'sfdx force:source:push'
- name: 'Push source to scratch org'
run: sf project deploy start

# Assign permission set
- name: 'Assign permission set'
run: 'sfdx force:user:permset:assign -n Quiz_Host'
# Assign permissionset
- name: 'Assign permissionset to default user'
run: sf org assign permset -n Quiz_Host

# Deploy test metadata
- name: 'Deploy test metadata'
run: sfdx force:mdapi:deploy -d test-metadata -w 10
run: sf project deploy start --metadata-dir=test-metadata -w 10

# Run Apex tests in scratch org
- name: 'Run Apex tests'
run: 'sfdx force:apex:test:run -c -r human -d ./tests/apex -w 20'
run: sf apex test run -c -r human -d ./tests/apex -w 20

# Upload Apex code coverage data
# Upload code coverage data
- name: 'Upload code coverage for Apex to Codecov.io'
uses: codecov/codecov-action@v1
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
flags: Apex

# Housekeeping
- name: 'Delete scratch org'
if: always()
run: 'sfdx force:org:delete -p -u quiz-ci'
run: sf org delete scratch -p -o scratch-org
69 changes: 37 additions & 32 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ name: CI

# Definition when the workflow should run
on:
workflow_dispatch:
push:
workflow_dispatch:
branches:
- master
paths-ignore:
Expand All @@ -16,14 +16,18 @@ jobs:
formatting-and-lwc-tests:
runs-on: ubuntu-latest
steps:
# Checkout the code in the pull request
# Checkout the source code
- name: 'Checkout source code'
uses: actions/checkout@v2
uses: actions/checkout@v4

# Install Volta to enforce proper node and package manager versions
- name: 'Install Volta'
uses: volta-cli/action@v4

# Cache node_modules to speed up the process
- name: Restore node_modules cache
- name: 'Restore node_modules cache'
id: cache-npm
uses: actions/cache@v1
uses: actions/cache@v4
with:
path: node_modules
key: npm-${{ hashFiles('**/package-lock.json') }}
Expand All @@ -34,24 +38,25 @@ jobs:
# Install npm dependencies for Prettier and Jest
- name: 'Install npm dependencies'
if: steps.cache-npm.outputs.cache-hit != 'true'
run: npm ci
run: HUSKY=0 npm ci

# Prettier formatting
- name: 'Code formatting'
- name: 'Code formatting verification with Prettier'
run: npm run prettier:verify

# ESlint
- name: 'Linting'
# Lint LWC
- name: 'Lint Lightning Web Components'
run: npm run lint

# LWC unit tests
- name: 'LWC unit tests'
- name: 'Unit test Lightning Web Components'
run: npm run test:unit:coverage

# Upload LWC code coverage data
# Upload code coverage data
- name: 'Upload code coverage for LWC to Codecov.io'
uses: codecov/codecov-action@v1
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
flags: LWC

scratch-org-tests:
Expand All @@ -61,21 +66,20 @@ jobs:
# 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
npm install @salesforce/cli --location=global
nodeInstallPath=$(npm config get prefix)
echo "$nodeInstallPath/bin" >> $GITHUB_PATH
sf --version
# Checkout the code in the pull request
# Checkout the source code
- name: 'Checkout source code'
uses: actions/checkout@v2
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
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?";
Expand All @@ -84,35 +88,36 @@ jobs:
# Authenticate dev hub
- name: 'Authenticate Dev Hub'
run: 'sfdx force:auth:sfdxurl:store -f ./DEVHUB_SFDX_URL.txt -a devhub -d'
run: sf org login sfdx-url -f ./DEVHUB_SFDX_URL.txt -a devhub -d

# Create scratch org
- name: 'Create scratch org'
run: 'sfdx force:org:create -f config/project-scratch-def.json -a quiz-ci -c -s -d 1'
run: sf org create scratch -f config/project-scratch-def.json -a scratch-org -d -y 1

# Deploy source to scratch org
- name: 'Push source'
run: 'sfdx force:source:push'
- name: 'Push source to scratch org'
run: sf project deploy start

# Assign permission set
- name: 'Assign permission set'
run: 'sfdx force:user:permset:assign -n Quiz_Host'
# Assign permissionset
- name: 'Assign permissionset to default user'
run: sf org assign permset -n Quiz_Host

# Deploy test metadata
- name: 'Deploy test metadata'
run: sfdx force:mdapi:deploy -d test-metadata -w 10
run: sf project deploy start --metadata-dir=test-metadata -w 10

# Run Apex tests in scratch org
- name: 'Run Apex tests'
run: 'sfdx force:apex:test:run -c -r human -d ./tests/apex -w 20'
run: sf apex test run -c -r human -d ./tests/apex -w 20

# Upload Apex code coverage data
# Upload code coverage data
- name: 'Upload code coverage for Apex to Codecov.io'
uses: codecov/codecov-action@v1
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
flags: Apex

# Housekeeping
- name: 'Delete scratch org'
if: always()
run: 'sfdx force:org:delete -p -u quiz-ci'
run: sf org delete scratch -p -o scratch-org
62 changes: 37 additions & 25 deletions .github/workflows/packaging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,20 @@ jobs:
# 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
npm install @salesforce/cli --location=global
nodeInstallPath=$(npm config get prefix)
echo "$nodeInstallPath/bin" >> $GITHUB_PATH
sf --version
# Checkout the code in the pull request
# Checkout the source code
- name: 'Checkout source code'
uses: actions/checkout@v2
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
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?";
Expand All @@ -38,10 +37,10 @@ jobs:
# Authenticate dev hub
- name: 'Authenticate Dev Hub'
run: 'sfdx force:auth:sfdxurl:store -f ./DEVHUB_SFDX_URL.txt -a devhub -d'
run: sf org login sfdx-url -f ./DEVHUB_SFDX_URL.txt -a devhub -d

# Remove auth file
- name: Remove auth file
- name: 'Remove auth file'
run: rm -f ./DEVHUB_SFDX_URL.txt

# Add namespace to project config
Expand Down Expand Up @@ -70,32 +69,45 @@ jobs:
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
uses: maddox/actions/sleep@master
with:
args: 360
- name: 'Wait for package replication'
run: sleep 360s

# 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
- 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: sfdx force:package:install --package ${{ steps.create-package-version.outputs.packageVersionId }} -w 10 -u scratch-org -r
- 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
- 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}\">"
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: sfdx force:package:version:promote --package ${{ steps.create-package-version.outputs.packageVersionId }} -n
- 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'
Expand Down
Loading

0 comments on commit ecfc60e

Please sign in to comment.