From f8c393a8cdf87f4d2b16e65a80a2ed2ddb660491 Mon Sep 17 00:00:00 2001 From: Jonathan Gillespie Date: Fri, 14 Jan 2022 09:59:52 -0500 Subject: [PATCH] Renamed deploy.yml to build.yml, added the amazing pwsh function @jamessimone created for apex-rollup to auto-promote any prod package versions that are listed in README files --- .github/workflows/{deploy.yml => build.yml} | 30 +++++++++++++++++-- .../scripts/build/promote-readme-packages.ps1 | 24 +++++++++++++++ 2 files changed, 51 insertions(+), 3 deletions(-) rename .github/workflows/{deploy.yml => build.yml} (92%) create mode 100644 config/scripts/build/promote-readme-packages.ps1 diff --git a/.github/workflows/deploy.yml b/.github/workflows/build.yml similarity index 92% rename from .github/workflows/deploy.yml rename to .github/workflows/build.yml index e115ba671..b3e0c7541 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/build.yml @@ -1,5 +1,5 @@ # Pipeline for Nebula Logger -name: Deployment +name: Build on: push: @@ -114,7 +114,6 @@ jobs: token: ${{ secrets.CODECOV_TOKEN }} flags: LWC - # TODO find a way to consolidate duplicated LOC for scratch org steps base-scratch-org-tests: name: 'Run Base Scratch Org Tests' needs: [code-quality-tests] @@ -213,7 +212,6 @@ jobs: - name: 'Run Apex Tests' run: npm run test:apex - # TODO revisit this part - for now, CodeCov.io upload will only run in the Experience Cloud org - name: 'Delete unsupported code coverage files' run: rm ./test-coverage/apex/test-result-707*-codecoverage.json @@ -317,3 +315,29 @@ jobs: - name: 'Create Beta Managed Package Version' run: npm run package:version:create:managed + + promote-package-versions: + name: 'Promote Package Versions' + needs: [lwc-tests, base-scratch-org-tests, experience-cloud-scratch-org-tests] + if: ${{ github.ref == 'refs/heads/main' }} + runs-on: ubuntu-latest + steps: + - name: 'Checkout source code' + uses: actions/checkout@v2 + + - name: 'Restore node_modules cache' + id: cache-npm + uses: actions/cache@v2 + with: + path: node_modules + key: npm-${{ hashFiles('**/package-lock.json') }} + restore-keys: | + npm-${{ env.cache-name }}- + npm- + + - name: 'Install npm dependencies' + if: steps.cache-npm.outputs.cache-hit != 'true' + run: npm ci + + - name: 'Promote package versions' + run: npx pwsh ./config/scripts/build/promote-readme-packages.ps1 diff --git a/config/scripts/build/promote-readme-packages.ps1 b/config/scripts/build/promote-readme-packages.ps1 new file mode 100644 index 000000000..914009df2 --- /dev/null +++ b/config/scripts/build/promote-readme-packages.ps1 @@ -0,0 +1,24 @@ +# This script finds any production install links for packages within README files & automatically promotes them + +$DebugPreference = 'Continue' +$ErrorActionPreference = 'Stop' + +function Start-Package-Promotion { + Write-Debug "Beginning promote script" + + $allReadmes = Get-ChildItem -Exclude node_modules, .sfdx, tests | Get-ChildItem -Filter README.md -Recurse + foreach ($readme in $allReadmes) { + $readmePackageIdResults = (Select-String -Path $readme 'https:\/\/login.salesforce.com\/packaging\/installPackage.apexp\?p0=.{0,18}') + if ($readmePackageIdResults.Matches.Length -gt 0) { + $packageIdSplit = $readmePackageIdResults.Matches[0].Value.Split("=") + if ($packageIdSplit.Length -eq 2) { + $packageId = $packageIdSplit[1] + Write-Debug "Promoting $packageId from $readme" + npx sfdx force:package:version:promote --package $packageId --noprompt + } + } + } + Write-Debug "Finished package promotion!" +} + +Start-Package-Promotion \ No newline at end of file