From 583b83938c2f8e19a0b89ef393af20e2bca36b17 Mon Sep 17 00:00:00 2001 From: Wim Velzeboer Date: Thu, 26 Mar 2026 09:21:15 +0000 Subject: [PATCH] Build pipelines for Unlocked Package --- .github/workflows/build.and.test.yml | 97 ++++++++++++++++++++++++++++ README.md | 3 +- 2 files changed, 99 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/build.and.test.yml diff --git a/.github/workflows/build.and.test.yml b/.github/workflows/build.and.test.yml new file mode 100644 index 0000000..849e2f4 --- /dev/null +++ b/.github/workflows/build.and.test.yml @@ -0,0 +1,97 @@ +name: Create a Scratch Org, Push Source, Run Apex Tests, create beta package version + +on: + pull_request: + branches: + - main + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + with: + ref: ${{github.event.pull_request.head.ref}} + repository: ${{github.event.pull_request.head.repo.full_name}} + + - name: Install SFDX CLI and authorize DevHub + uses: sfdx-actions/setup-sfdx@v1 + with: + sfdx-auth-url: ${{ secrets.SFDX_AUTH_URL }} + + - name: Setup the config parameters needed + run: sf config set target-dev-hub SFDX-ENV --global + + - name: List SFDX Connections + run: echo y | sfdx force:org:list + + - name: Setup Git Configuration + run: | + git config --global user.name 'WimVelzeboer' + git config --global user.email 'wim@velzeboer.nl' + + - name: Create the scratch org + run: sfdx force:org:create --definition-file config/project-scratch-def.json --set-default --setdefaultusername --duration-days 1 --no-track-source --alias fflibapexextensions + + - name: Install required dependency framework fflib-apex-mocks + run: | + mkdir ./temp + cd ./temp + git clone https://github.com/sforce18/fflib-apex-mocks.git + cd .. + cp -R ./temp/fflib-apex-mocks/sfdx-source/apex-mocks ./sfdx-source/ + + - name: Install required dependency framework fflib-apex-common + run: | + mkdir ./temp + cd ./temp + git clone https://github.com/sforce18/fflib-apex-common.git + cd .. + cp -R ./temp/fflib-apex-mocks/sfdx-source/apex-common ./sfdx-source/ + + + - name: Pushing source + run: sfdx force:source:push --forceoverwrite + + - name: Running Apex Tests + run: sfdx force:apex:test:run --codecoverage --resultformat human --wait 5 + + - name: Generate Package + run: | + echo "Creating new BETA package version" + OUTPUT=`sf package version create --installation-key-bypass --package "fflibApexExtensions" --code-coverage -w 30 --definition-file config/project-scratch-def.json` + echo "$OUTPUT" + [ $? -eq 0 ] && echo "successful" || exit 1 + + STRING=`echo "$OUTPUT" | grep 'Package Version Id:'` + VERSION_ID="${STRING##*: }" + VERSION=`grep $VERSION_ID sfdx-project.json | cut -d "@" -f2 | cut -d "\"" -f1` + echo "Created BETA package version: $VERSION with Id: $VERSION_ID" + + git commit -am "New package version created" + + echo "PACKAGE_ID=$VERSION_ID" >> "$GITHUB_ENV" + + - name: Listing Package Details + run: | + sf package version report --package "fflibApexExtensions" --target-dev-hub SFDX-ENV --verbose + + - name: Appending to Package version Log + run: | + DATA=`sf package version report --package $PACKAGE_ID --target-dev-hub SFDX-ENV` + VERSION=`echo "$DATA" | grep 'Name' | tail -n1 | cut -d" " -f2- | cut -d" " -f2- | tr -s '[:space:]'` + ID=`echo "$DATA" | grep 'Subscriber Package Version Id' | awk '{print $5}'` + DT=$(date '+%d/%m/%Y %H:%M:%S'); + + echo "|$VERSION (BETA) | $ID | Created on $DT" >> README.md + git add README.md + git commit -am "Update Package Version Log" + + - name: Push changes + run: | + git push + - name: Destroy scratch org + run: sfdx force:org:delete -p + if: always() diff --git a/README.md b/README.md index 6bca70c..8b50d3a 100644 --- a/README.md +++ b/README.md @@ -111,4 +111,5 @@ Thank you for your donations! ## Package version log | Package version | Package ID | Description | -|-----------------|--------------------|--------------------------||0.1.0-1-feature/UnlockedManagedPackage (BETA) | 04tJ8000000kaKQIAY | Created on 26/03/2026 18:14:51 | +|-----------------|--------------------|--------------------------| +|0.1.0-1-feature/UnlockedManagedPackage (BETA) | 04tJ8000000kaKQIAY | Created on 26/03/2026 18:14:51 |