|
| 1 | +# Pipeline for Nebula Cache Manager |
| 2 | +name: Build |
| 3 | + |
| 4 | +on: |
| 5 | + push: |
| 6 | + branches: |
| 7 | + - main |
| 8 | + paths-ignore: |
| 9 | + - 'content/**' |
| 10 | + - 'docs/**' |
| 11 | + - 'examples/**' |
| 12 | + - 'packages/**' |
| 13 | + - '.forceignore' |
| 14 | + - '.gitignore' |
| 15 | + - '.prettierignore' |
| 16 | + - '.prettierrc' |
| 17 | + - 'CONTRIBUTING.md' |
| 18 | + - 'LICENSE' |
| 19 | + - 'package.json' |
| 20 | + - 'README.md' |
| 21 | + - './**/README.md' |
| 22 | + - 'sfdx-project.json' |
| 23 | + pull_request: |
| 24 | + types: [opened, synchronize, reopened] |
| 25 | + paths-ignore: |
| 26 | + - 'content/**' |
| 27 | + - 'docs/**' |
| 28 | + - 'examples/**' |
| 29 | + - 'packages/**' |
| 30 | + - '.forceignore' |
| 31 | + - '.gitignore' |
| 32 | + - '.prettierignore' |
| 33 | + - '.prettierrc' |
| 34 | + - 'CONTRIBUTING.md' |
| 35 | + - 'LICENSE' |
| 36 | + - 'package.json' |
| 37 | + - 'README.md' |
| 38 | + - './**/README.md' |
| 39 | + - 'sfdx-project.json' |
| 40 | + |
| 41 | +jobs: |
| 42 | + code-quality-tests: |
| 43 | + name: 'Run Code Quality Tests' |
| 44 | + runs-on: ubuntu-latest |
| 45 | + steps: |
| 46 | + - name: 'Checkout source code' |
| 47 | + uses: actions/checkout@v3 |
| 48 | + |
| 49 | + - name: 'Restore node_modules cache' |
| 50 | + id: cache-npm |
| 51 | + uses: actions/cache@v3 |
| 52 | + with: |
| 53 | + path: node_modules |
| 54 | + key: npm-${{ hashFiles('**/package-lock.json') }} |
| 55 | + restore-keys: | |
| 56 | + npm-${{ env.cache-name }}- |
| 57 | + npm- |
| 58 | +
|
| 59 | + - name: 'Install npm dependencies' |
| 60 | + if: steps.cache-npm.outputs.cache-hit != 'true' |
| 61 | + run: npm ci |
| 62 | + |
| 63 | + - name: 'Verify Apex with SFDX Scanner' |
| 64 | + run: | |
| 65 | + npm run sfdx:plugins:link:scanner |
| 66 | + npm run scan:apex |
| 67 | +
|
| 68 | + - name: 'Verify formatting with Prettier' |
| 69 | + run: npm run prettier:verify |
| 70 | + |
| 71 | + base-scratch-org-tests: |
| 72 | + name: 'Run Base Scratch Org Tests' |
| 73 | + needs: [code-quality-tests] |
| 74 | + runs-on: ubuntu-latest |
| 75 | + environment: 'Base Scratch Org' |
| 76 | + steps: |
| 77 | + - name: 'Checkout source code' |
| 78 | + uses: actions/checkout@v3 |
| 79 | + |
| 80 | + - name: 'Restore node_modules cache' |
| 81 | + id: cache-npm |
| 82 | + uses: actions/cache@v3 |
| 83 | + with: |
| 84 | + path: node_modules |
| 85 | + key: npm-${{ hashFiles('**/package-lock.json') }} |
| 86 | + restore-keys: | |
| 87 | + npm-${{ env.cache-name }}- |
| 88 | + npm- |
| 89 | +
|
| 90 | + - name: 'Install npm dependencies' |
| 91 | + if: steps.cache-npm.outputs.cache-hit != 'true' |
| 92 | + run: npm ci |
| 93 | + |
| 94 | + - name: 'Authorize Dev Hub' |
| 95 | + shell: bash |
| 96 | + run: | |
| 97 | + echo "${{ env.DEV_HUB_JWT_SERVER_KEY }}" > ./jwt-server.key |
| 98 | + npx sfdx force:auth:jwt:grant --instanceurl ${{ env.DEV_HUB_AUTH_URL }} --clientid ${{ env.DEV_HUB_CONSUMER_KEY }} --username ${{ env.DEV_HUB_BOT_USERNAME }} --jwtkeyfile ./jwt-server.key --setdefaultdevhubusername |
| 99 | + env: |
| 100 | + DEV_HUB_AUTH_URL: ${{ secrets.DEV_HUB_AUTH_URL }} |
| 101 | + DEV_HUB_BOT_USERNAME: ${{ secrets.DEV_HUB_BOT_USERNAME }} |
| 102 | + DEV_HUB_CONSUMER_KEY: ${{ secrets.DEV_HUB_CONSUMER_KEY }} |
| 103 | + DEV_HUB_JWT_SERVER_KEY: ${{ secrets.DEV_HUB_JWT_SERVER_KEY }} |
| 104 | + |
| 105 | + - name: 'Create Base Scratch Org' |
| 106 | + run: npx sfdx force:org:create --durationdays 1 --definitionfile ./config/scratch-orgs/base-scratch-def.json --wait 20 --setdefaultusername --json |
| 107 | + |
| 108 | + - name: 'Deploy Source to Scratch Org' |
| 109 | + run: npx sfdx force:source:deploy --sourcepath ./nebula-cache-manager/ |
| 110 | + |
| 111 | + - name: 'Assign Cache Manager Admin Permission Set' |
| 112 | + run: npm run permset:assign:admin |
| 113 | + |
| 114 | + # Nebula Cache Manager has functionality that use the session partition of platform cache, which only works when the current user has an active session. |
| 115 | + # The code should work with or without an active session, so the pipeline runs the tests twice - asynchronously and synchronously. |
| 116 | + # Running the Apex tests sync & async serves as an extra level of integration testing to ensure that everything works with or without an active session. |
| 117 | + - name: 'Run Apex Tests Asynchronously' |
| 118 | + run: npm run test:apex:nocoverage |
| 119 | + |
| 120 | + - name: 'Run Apex Tests Synchronously' |
| 121 | + run: npm run test:apex:nocoverage -- --synchronous |
| 122 | + |
| 123 | + - name: 'Delete Base Scratch Org' |
| 124 | + run: npx sfdx force:org:delete --json --noprompt |
| 125 | + if: ${{ always() }} |
| 126 | + |
| 127 | + platform-cache-scratch-org-tests: |
| 128 | + name: 'Run Platform Cache Scratch Org Tests' |
| 129 | + needs: [code-quality-tests] |
| 130 | + runs-on: ubuntu-latest |
| 131 | + environment: 'Platform Cache Scratch Org' |
| 132 | + steps: |
| 133 | + - name: 'Checkout source code' |
| 134 | + uses: actions/checkout@v3 |
| 135 | + |
| 136 | + - name: 'Restore node_modules cache' |
| 137 | + id: cache-npm |
| 138 | + uses: actions/cache@v3 |
| 139 | + with: |
| 140 | + path: node_modules |
| 141 | + key: npm-${{ hashFiles('**/package-lock.json') }} |
| 142 | + restore-keys: | |
| 143 | + npm-${{ env.cache-name }}- |
| 144 | + npm- |
| 145 | +
|
| 146 | + - name: 'Install npm dependencies' |
| 147 | + if: steps.cache-npm.outputs.cache-hit != 'true' |
| 148 | + run: npm ci |
| 149 | + |
| 150 | + - name: 'Authorize Dev Hub' |
| 151 | + shell: bash |
| 152 | + run: | |
| 153 | + echo "${{ env.DEV_HUB_JWT_SERVER_KEY }}" > ./jwt-server.key |
| 154 | + npx sfdx force:auth:jwt:grant --instanceurl ${{ env.DEV_HUB_AUTH_URL }} --clientid ${{ env.DEV_HUB_CONSUMER_KEY }} --username ${{ env.DEV_HUB_BOT_USERNAME }} --jwtkeyfile ./jwt-server.key --setdefaultdevhubusername |
| 155 | + env: |
| 156 | + DEV_HUB_AUTH_URL: ${{ secrets.DEV_HUB_AUTH_URL }} |
| 157 | + DEV_HUB_BOT_USERNAME: ${{ secrets.DEV_HUB_BOT_USERNAME }} |
| 158 | + DEV_HUB_CONSUMER_KEY: ${{ secrets.DEV_HUB_CONSUMER_KEY }} |
| 159 | + DEV_HUB_JWT_SERVER_KEY: ${{ secrets.DEV_HUB_JWT_SERVER_KEY }} |
| 160 | + |
| 161 | + - name: 'Create Platform Cache Scratch Org' |
| 162 | + run: npx sfdx force:org:create --durationdays 1 --definitionfile ./config/scratch-orgs/platform-cache-scratch-def.json --wait 20 --setdefaultusername --json |
| 163 | + |
| 164 | + - name: 'Deploy Source to Scratch Org' |
| 165 | + run: npx sfdx force:source:deploy --sourcepath ./nebula-cache-manager/ |
| 166 | + |
| 167 | + - name: 'Assign Cache Manager Admin Permission Set' |
| 168 | + run: npm run permset:assign:admin |
| 169 | + |
| 170 | + # Nebula Cache Manager has functionality that use the session partition of platform cache, which only works when the current user has an active session. |
| 171 | + # The code should work with or without an active session, so the pipeline runs the tests twice - asynchronously and synchronously. |
| 172 | + # Running the Apex tests sync & async serves as an extra level of integration testing to ensure that everything works with or without an active session. |
| 173 | + - name: 'Run Apex Tests Asynchronously' |
| 174 | + run: npm run test:apex:nocoverage |
| 175 | + |
| 176 | + - name: 'Run Apex Tests Synchronously' |
| 177 | + run: npm run test:apex -- --synchronous |
| 178 | + |
| 179 | + - name: 'Upload Apex test code coverage to Codecov.io' |
| 180 | + uses: codecov/codecov-action@v3 |
| 181 | + with: |
| 182 | + token: ${{ secrets.CODECOV_TOKEN }} |
| 183 | + flags: Apex |
| 184 | + |
| 185 | + - name: 'Delete Platform Cache Scratch Org' |
| 186 | + run: npx sfdx force:org:delete --json --noprompt |
| 187 | + if: ${{ always() }} |
| 188 | + |
| 189 | + create-unlocked-package-versions: |
| 190 | + name: 'Create Package Versions' |
| 191 | + needs: [base-scratch-org-tests, platform-cache-scratch-org-tests] |
| 192 | + if: ${{ github.ref != 'refs/heads/main' }} |
| 193 | + runs-on: ubuntu-latest |
| 194 | + outputs: |
| 195 | + noNamespacePackageVersionId: ${{ steps.createNoNamespace.outputs.noNamespacePackageVersionId }} |
| 196 | + withNamespacePackageVersionId: ${{ steps.createWithNamespace.outputs.withNamespacePackageVersionId }} |
| 197 | + steps: |
| 198 | + - name: 'Checkout source code' |
| 199 | + uses: actions/checkout@v3 |
| 200 | + with: |
| 201 | + ref: ${{ github.event.pull_request.head.ref }} |
| 202 | + |
| 203 | + - name: 'Restore node_modules cache' |
| 204 | + id: cache-npm |
| 205 | + uses: actions/cache@v3 |
| 206 | + with: |
| 207 | + path: node_modules |
| 208 | + key: npm-${{ hashFiles('**/package-lock.json') }} |
| 209 | + restore-keys: | |
| 210 | + npm-${{ env.cache-name }}- |
| 211 | + npm- |
| 212 | +
|
| 213 | + - name: Set environment variables |
| 214 | + run: | |
| 215 | + echo 'SFDX_DISABLE_AUTOUPDATE=true' >> $GITHUB_ENV |
| 216 | + echo 'SFDX_DISABLE_SOURCE_MEMBER_POLLING=true' >> $GITHUB_ENV |
| 217 | + echo 'SFDX_PROJECT_AUTOUPDATE_DISABLE_FOR_PACKAGE_VERSION_CREATE=true' >> $GITHUB_ENV |
| 218 | + # echo 'SFDX_DISABLE_TELEMETRY=true' >> $GITHUB_ENV |
| 219 | + |
| 220 | + - name: 'Install npm dependencies' |
| 221 | + if: steps.cache-npm.outputs.cache-hit != 'true' |
| 222 | + run: npm ci |
| 223 | + |
| 224 | + - name: 'Authorize Dev Hub' |
| 225 | + shell: bash |
| 226 | + run: | |
| 227 | + echo '${{ env.DEV_HUB_JWT_SERVER_KEY }}' > ./jwt-server.key |
| 228 | + npx sfdx force:auth:jwt:grant --instanceurl ${{ env.DEV_HUB_AUTH_URL }} --clientid ${{ env.DEV_HUB_CONSUMER_KEY }} --username ${{ env.DEV_HUB_BOT_USERNAME }} --jwtkeyfile ./jwt-server.key --setdefaultdevhubusername |
| 229 | + # rm ./jwt-server.key |
| 230 | + env: |
| 231 | + DEV_HUB_AUTH_URL: ${{ secrets.DEV_HUB_AUTH_URL }} |
| 232 | + DEV_HUB_BOT_USERNAME: ${{ secrets.DEV_HUB_BOT_USERNAME }} |
| 233 | + DEV_HUB_CONSUMER_KEY: ${{ secrets.DEV_HUB_CONSUMER_KEY }} |
| 234 | + DEV_HUB_JWT_SERVER_KEY: ${{ secrets.DEV_HUB_JWT_SERVER_KEY }} |
| 235 | + |
| 236 | + - name: 'Create No-Namespace Package Version' |
| 237 | + id: createNoNamespace |
| 238 | + run: | |
| 239 | + noNamespacePackageVersionId=$(npx sfdx force:package:version:create --package "Nebula Cache Manager (no namespace)" --wait 120 --codecoverage --skipancestorcheck --installationkeybypass --json | jq --exit-status --raw-output ".result.SubscriberPackageVersionId") |
| 240 | + echo "noNamespacePackageVersionId=$noNamespacePackageVersionId" >> $GITHUB_ENV |
| 241 | + echo "noNamespacePackageVersionId=$noNamespacePackageVersionId" >> $GITHUB_OUTPUT |
| 242 | + echo "Created package version $noNamespacePackageVersionId" |
| 243 | +
|
| 244 | + - name: 'Create Namespaced Package Version' |
| 245 | + id: createWithNamespace |
| 246 | + run: | |
| 247 | + withNamespacePackageVersionId=$(npx sfdx force:package:version:create --package "Nebula Cache Manager (Nebula namespace)" --wait 120 --codecoverage --skipancestorcheck --installationkeybypass --json | jq --exit-status --raw-output ".result.SubscriberPackageVersionId") |
| 248 | + echo "withNamespacePackageVersionId=$withNamespacePackageVersionId" >> $GITHUB_ENV |
| 249 | + echo "withNamespacePackageVersionId=$withNamespacePackageVersionId" >> $GITHUB_OUTPUT |
| 250 | + echo "Created package version $withNamespacePackageVersionId" |
| 251 | +
|
| 252 | + - name: 'Create Platform Cache Scratch Org' |
| 253 | + run: npx sfdx force:org:create --definitionfile ./config/scratch-orgs/platform-cache-scratch-def.json --setdefaultusername --durationdays 1 |
| 254 | + |
| 255 | + - name: 'Install Namespaced Package Version' |
| 256 | + run: npx sfdx package:install --package ${{ env.withNamespacePackageVersionId }} --wait 20 |
| 257 | + |
| 258 | + - name: 'Install No-Namespace Package Version' |
| 259 | + run: npx sfdx package:install --package ${{ env.noNamespacePackageVersionId }} --wait 20 |
| 260 | + |
| 261 | + - name: 'Validate Namespaced Package Access' |
| 262 | + run: npx sfdx apex:run --file ./scripts/build/validate-access-to-no-namespace-package.apex |
| 263 | + |
| 264 | + - name: 'Validate No-Namespace Package Access' |
| 265 | + run: npx sfdx apex:run --file ./scripts/build/validate-access-to-namespaced-package.apex |
| 266 | + |
| 267 | + - name: 'Delete Platform Cache Scratch Org' |
| 268 | + run: npx sfdx force:org:delete --json --noprompt |
| 269 | + if: ${{ always() }} |
| 270 | + |
| 271 | + # - name: 'Commit New Package Versions' |
| 272 | + # run: | |
| 273 | + # git config --local user.email "[email protected]" |
| 274 | + # git config --local user.name "GitHub Action Bot" |
| 275 | + # # npm run sfdx:plugins:link:bummer |
| 276 | + # # npx sfdx bummer:package:aliases:sort |
| 277 | + # rm ./jwt-server.key |
| 278 | + # npx prettier --write ./sfdx-project.json |
| 279 | + # git add ./sfdx-project.json |
| 280 | + # git status |
| 281 | + # git commit -m "Created new package versions" |
| 282 | + # git push |
0 commit comments