From ecfc60eb444698bfb1be634e107ecc124cd37e59 Mon Sep 17 00:00:00 2001 From: Philippe Ozil Date: Tue, 8 Oct 2024 08:49:50 +0200 Subject: [PATCH] build: sf cli migration --- .github/workflows/ci-pr.yml | 75 +++++++++++++++++++++------------ .github/workflows/ci.yml | 69 ++++++++++++++++-------------- .github/workflows/packaging.yml | 62 ++++++++++++++++----------- install-dev.bat | 19 +++++---- install-dev.sh | 21 ++++----- 5 files changed, 144 insertions(+), 102 deletions(-) diff --git a/.github/workflows/ci-pr.yml b/.github/workflows/ci-pr.yml index ddf7a33..d51ea52 100644 --- a/.github/workflows/ci-pr.yml +++ b/.github/workflows/ci-pr.yml @@ -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') }} @@ -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' @@ -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: @@ -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?"; @@ -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 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c253f0c..e671425 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -3,8 +3,8 @@ name: CI # Definition when the workflow should run on: + workflow_dispatch: push: - workflow_dispatch: branches: - master paths-ignore: @@ -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') }} @@ -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: @@ -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?"; @@ -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 diff --git a/.github/workflows/packaging.yml b/.github/workflows/packaging.yml index dc44a64..6af99ea 100644 --- a/.github/workflows/packaging.yml +++ b/.github/workflows/packaging.yml @@ -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?"; @@ -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 @@ -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="" - newPackageLink="" + 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' diff --git a/install-dev.bat b/install-dev.bat index 0a0777b..83ffca5 100644 --- a/install-dev.bat +++ b/install-dev.bat @@ -20,31 +20,36 @@ echo - Data: %DATA% rem Install script echo Cleaning previous scratch org... -cmd.exe /c sfdx force:org:delete -p -u %ORG_ALIAS% 2>NUL +cmd.exe /c sf org delete scratch -p -o %ORG_ALIAS% 2>NUL @echo: echo Creating scratch org... -cmd.exe /c sfdx force:org:create -c -s -f config/project-scratch-def.json -a %ORG_ALIAS% -d 30 +cmd.exe /c sf org create scratch -f config/project-scratch-def.json -a %ORG_ALIAS% -d -y 30 --no-ancestors --no-namespace call :checkForError @echo: echo Pushing source... -cmd.exe /c sfdx force:source:push -f -u %ORG_ALIAS% +cmd.exe /c sf project deploy start call :checkForError @echo: echo Assigning permissions... -cmd.exe /c sfdx force:user:permset:assign -n Quiz_Host -u %ORG_ALIAS% +cmd.exe /c sf org assign permset -n Quiz_Host call :checkForError @echo: echo Importing data... -cmd.exe /c sfdx force:data:tree:import -p data/%DATA%/plan.json -u %ORG_ALIAS% +cmd.exe /c sf data tree import -p data/%DATA%/plan.json call :checkForError @echo: echo Generating user password... -cmd.exe /c sfdx force:user:password:generate -u %ORG_ALIAS% +cmd.exe /c sf org generate password +call :checkForError +@echo: + +echo Opening org... +cmd.exe /c sf org open -p lightning/setup/SecurityRemoteProxy/home call :checkForError @echo: @@ -52,8 +57,6 @@ rem Check exit code @echo: if ["%errorlevel%"]==["0"] ( echo Installation completed. - @echo: - cmd.exe /c sfdx force:org:open -p /lightning/setup/SecurityremoteProxy/home -u %ORG_ALIAS% ) :: ======== FN ====== diff --git a/install-dev.sh b/install-dev.sh index f050aee..6ee4968 100755 --- a/install-dev.sh +++ b/install-dev.sh @@ -21,27 +21,31 @@ echo "" # Install script echo "Cleaning previous scratch org..." -sfdx force:org:delete -p -u $ORG_ALIAS &> /dev/null +sf org delete scratch -p -o $ORG_ALIAS &> /dev/null echo "" echo "Creating scratch org..." && \ -sfdx force:org:create -c -s -f config/project-scratch-def.json -a $ORG_ALIAS -d 30 && \ +sf org create scratch -f config/project-scratch-def.json -a $ORG_ALIAS -d -y 30 --no-ancestors --no-namespace && \ echo "" && \ echo "Pushing source..." && \ -sfdx force:source:push -f -u $ORG_ALIAS && \ +sf project deploy start && \ echo "" && \ -echo "Assigning permissions..." && \ -sfdx force:user:permset:assign -n Quiz_Host -u $ORG_ALIAS && \ +echo "Assigning permission sets..." && \ +sf org assign permset -n Quiz_Host && \ echo "" && \ echo "Importing data..." && \ -sfdx force:data:tree:import -p data/$DATA/plan.json -u $ORG_ALIAS && \ +sf data tree import -p data/$DATA/plan.json && \ echo "" && \ echo "Generating user password..." && \ -sfdx force:user:password:generate -u $ORG_ALIAS && \ +sf org generate password && \ +echo "" && \ + +echo "Opening org..." && \ +sf org open -p lightning/setup/SecurityRemoteProxy/home && \ echo "" EXIT_CODE="$?" @@ -50,10 +54,7 @@ EXIT_CODE="$?" echo "" if [ "$EXIT_CODE" -eq 0 ]; then echo "Installation completed." - echo "" - sfdx force:org:open -p /lightning/setup/SecurityRemoteProxy/home -u $ORG_ALIAS else echo "Installation failed." fi - exit $EXIT_CODE