Skip to content

Commit

Permalink
Fixed inaccessible methods in namespaced package (#12)
Browse files Browse the repository at this point in the history
* Fixed #11 by updating CacheManager.cls to use global on the top-level class, the Cacheable interface, and several public static methods

* Added pipeline for GitHub Actions

* Added lint-staged.config.js and automated syncing of the version number in several files within the repo/metadata
  • Loading branch information
jongpie authored Mar 6, 2023
1 parent 104a41c commit 3dbf694
Show file tree
Hide file tree
Showing 14 changed files with 9,694 additions and 3,012 deletions.
282 changes: 282 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,282 @@
# Pipeline for Nebula Cache Manager
name: Build

on:
push:
branches:
- main
paths-ignore:
- 'content/**'
- 'docs/**'
- 'examples/**'
- 'packages/**'
- '.forceignore'
- '.gitignore'
- '.prettierignore'
- '.prettierrc'
- 'CONTRIBUTING.md'
- 'LICENSE'
- 'package.json'
- 'README.md'
- './**/README.md'
- 'sfdx-project.json'
pull_request:
types: [opened, synchronize, reopened]
paths-ignore:
- 'content/**'
- 'docs/**'
- 'examples/**'
- 'packages/**'
- '.forceignore'
- '.gitignore'
- '.prettierignore'
- '.prettierrc'
- 'CONTRIBUTING.md'
- 'LICENSE'
- 'package.json'
- 'README.md'
- './**/README.md'
- 'sfdx-project.json'

jobs:
code-quality-tests:
name: 'Run Code Quality Tests'
runs-on: ubuntu-latest
steps:
- name: 'Checkout source code'
uses: actions/checkout@v3

- name: 'Restore node_modules cache'
id: cache-npm
uses: actions/cache@v3
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: 'Verify Apex with SFDX Scanner'
run: |
npm run sfdx:plugins:link:scanner
npm run scan:apex
- name: 'Verify formatting with Prettier'
run: npm run prettier:verify

base-scratch-org-tests:
name: 'Run Base Scratch Org Tests'
needs: [code-quality-tests]
runs-on: ubuntu-latest
environment: 'Base Scratch Org'
steps:
- name: 'Checkout source code'
uses: actions/checkout@v3

- name: 'Restore node_modules cache'
id: cache-npm
uses: actions/cache@v3
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: 'Authorize Dev Hub'
shell: bash
run: |
echo "${{ env.DEV_HUB_JWT_SERVER_KEY }}" > ./jwt-server.key
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
env:
DEV_HUB_AUTH_URL: ${{ secrets.DEV_HUB_AUTH_URL }}
DEV_HUB_BOT_USERNAME: ${{ secrets.DEV_HUB_BOT_USERNAME }}
DEV_HUB_CONSUMER_KEY: ${{ secrets.DEV_HUB_CONSUMER_KEY }}
DEV_HUB_JWT_SERVER_KEY: ${{ secrets.DEV_HUB_JWT_SERVER_KEY }}

- name: 'Create Base Scratch Org'
run: npx sfdx force:org:create --durationdays 1 --definitionfile ./config/scratch-orgs/base-scratch-def.json --wait 20 --setdefaultusername --json

- name: 'Deploy Source to Scratch Org'
run: npx sfdx force:source:deploy --sourcepath ./nebula-cache-manager/

- name: 'Assign Cache Manager Admin Permission Set'
run: npm run permset:assign:admin

# Nebula Cache Manager has functionality that use the session partition of platform cache, which only works when the current user has an active session.
# The code should work with or without an active session, so the pipeline runs the tests twice - asynchronously and synchronously.
# 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.
- name: 'Run Apex Tests Asynchronously'
run: npm run test:apex:nocoverage

- name: 'Run Apex Tests Synchronously'
run: npm run test:apex:nocoverage -- --synchronous

- name: 'Delete Base Scratch Org'
run: npx sfdx force:org:delete --json --noprompt
if: ${{ always() }}

platform-cache-scratch-org-tests:
name: 'Run Platform Cache Scratch Org Tests'
needs: [code-quality-tests]
runs-on: ubuntu-latest
environment: 'Platform Cache Scratch Org'
steps:
- name: 'Checkout source code'
uses: actions/checkout@v3

- name: 'Restore node_modules cache'
id: cache-npm
uses: actions/cache@v3
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: 'Authorize Dev Hub'
shell: bash
run: |
echo "${{ env.DEV_HUB_JWT_SERVER_KEY }}" > ./jwt-server.key
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
env:
DEV_HUB_AUTH_URL: ${{ secrets.DEV_HUB_AUTH_URL }}
DEV_HUB_BOT_USERNAME: ${{ secrets.DEV_HUB_BOT_USERNAME }}
DEV_HUB_CONSUMER_KEY: ${{ secrets.DEV_HUB_CONSUMER_KEY }}
DEV_HUB_JWT_SERVER_KEY: ${{ secrets.DEV_HUB_JWT_SERVER_KEY }}

- name: 'Create Platform Cache Scratch Org'
run: npx sfdx force:org:create --durationdays 1 --definitionfile ./config/scratch-orgs/platform-cache-scratch-def.json --wait 20 --setdefaultusername --json

- name: 'Deploy Source to Scratch Org'
run: npx sfdx force:source:deploy --sourcepath ./nebula-cache-manager/

- name: 'Assign Cache Manager Admin Permission Set'
run: npm run permset:assign:admin

# Nebula Cache Manager has functionality that use the session partition of platform cache, which only works when the current user has an active session.
# The code should work with or without an active session, so the pipeline runs the tests twice - asynchronously and synchronously.
# 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.
- name: 'Run Apex Tests Asynchronously'
run: npm run test:apex:nocoverage

- name: 'Run Apex Tests Synchronously'
run: npm run test:apex -- --synchronous

- name: 'Upload Apex test code coverage to Codecov.io'
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
flags: Apex

- name: 'Delete Platform Cache Scratch Org'
run: npx sfdx force:org:delete --json --noprompt
if: ${{ always() }}

create-unlocked-package-versions:
name: 'Create Package Versions'
needs: [base-scratch-org-tests, platform-cache-scratch-org-tests]
if: ${{ github.ref != 'refs/heads/main' }}
runs-on: ubuntu-latest
outputs:
noNamespacePackageVersionId: ${{ steps.createNoNamespace.outputs.noNamespacePackageVersionId }}
withNamespacePackageVersionId: ${{ steps.createWithNamespace.outputs.withNamespacePackageVersionId }}
steps:
- name: 'Checkout source code'
uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.ref }}

- name: 'Restore node_modules cache'
id: cache-npm
uses: actions/cache@v3
with:
path: node_modules
key: npm-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
npm-${{ env.cache-name }}-
npm-
- name: Set environment variables
run: |
echo 'SFDX_DISABLE_AUTOUPDATE=true' >> $GITHUB_ENV
echo 'SFDX_DISABLE_SOURCE_MEMBER_POLLING=true' >> $GITHUB_ENV
echo 'SFDX_PROJECT_AUTOUPDATE_DISABLE_FOR_PACKAGE_VERSION_CREATE=true' >> $GITHUB_ENV
# echo 'SFDX_DISABLE_TELEMETRY=true' >> $GITHUB_ENV

- name: 'Install npm dependencies'
if: steps.cache-npm.outputs.cache-hit != 'true'
run: npm ci

- name: 'Authorize Dev Hub'
shell: bash
run: |
echo '${{ env.DEV_HUB_JWT_SERVER_KEY }}' > ./jwt-server.key
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
# rm ./jwt-server.key
env:
DEV_HUB_AUTH_URL: ${{ secrets.DEV_HUB_AUTH_URL }}
DEV_HUB_BOT_USERNAME: ${{ secrets.DEV_HUB_BOT_USERNAME }}
DEV_HUB_CONSUMER_KEY: ${{ secrets.DEV_HUB_CONSUMER_KEY }}
DEV_HUB_JWT_SERVER_KEY: ${{ secrets.DEV_HUB_JWT_SERVER_KEY }}

- name: 'Create No-Namespace Package Version'
id: createNoNamespace
run: |
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")
echo "noNamespacePackageVersionId=$noNamespacePackageVersionId" >> $GITHUB_ENV
echo "noNamespacePackageVersionId=$noNamespacePackageVersionId" >> $GITHUB_OUTPUT
echo "Created package version $noNamespacePackageVersionId"
- name: 'Create Namespaced Package Version'
id: createWithNamespace
run: |
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")
echo "withNamespacePackageVersionId=$withNamespacePackageVersionId" >> $GITHUB_ENV
echo "withNamespacePackageVersionId=$withNamespacePackageVersionId" >> $GITHUB_OUTPUT
echo "Created package version $withNamespacePackageVersionId"
- name: 'Create Platform Cache Scratch Org'
run: npx sfdx force:org:create --definitionfile ./config/scratch-orgs/platform-cache-scratch-def.json --setdefaultusername --durationdays 1

- name: 'Install Namespaced Package Version'
run: npx sfdx package:install --package ${{ env.withNamespacePackageVersionId }} --wait 20

- name: 'Install No-Namespace Package Version'
run: npx sfdx package:install --package ${{ env.noNamespacePackageVersionId }} --wait 20

- name: 'Validate Namespaced Package Access'
run: npx sfdx apex:run --file ./scripts/build/validate-access-to-no-namespace-package.apex

- name: 'Validate No-Namespace Package Access'
run: npx sfdx apex:run --file ./scripts/build/validate-access-to-namespaced-package.apex

- name: 'Delete Platform Cache Scratch Org'
run: npx sfdx force:org:delete --json --noprompt
if: ${{ always() }}

# - name: 'Commit New Package Versions'
# run: |
# git config --local user.email "action@github.com"
# git config --local user.name "GitHub Action Bot"
# # npm run sfdx:plugins:link:bummer
# # npx sfdx bummer:package:aliases:sort
# rm ./jwt-server.key
# npx prettier --write ./sfdx-project.json
# git add ./sfdx-project.json
# git status
# git commit -m "Created new package versions"
# git push
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ A flexible cache management system for Salesforce Apex developers. Built to be s

Learn more about the history & implementation of this repo in [the Joys of Apex article 'Iteratively Building a Flexible Caching System for Apex'](https://www.jamessimone.net/blog/joys-of-apex/iteratively-building-a-flexible-caching-system/)

## Unlocked Package - `Nebula` Namespace - v1.0.1
## Unlocked Package - `Nebula` Namespace - v1.0.2

[![Install Unlocked Package (Nebula namespace) in a Sandbox](./images/btn-install-unlocked-package-sandbox.png)](https://test.salesforce.com/packaging/installPackage.apexp?p0=04t5Y0000015n6rQAA)
[![Install Unlocked Package (Nebula namespace) in Production](./images/btn-install-unlocked-package-production.png)](https://login.salesforce.com/packaging/installPackage.apexp?p0=04t5Y0000015n6rQAA)
[![Install Unlocked Package (Nebula namespace) in a Sandbox](./images/btn-install-unlocked-package-sandbox.png)](https://test.salesforce.com/packaging/installPackage.apexp?p0=04t5Y0000015nCfQAI)
[![Install Unlocked Package (Nebula namespace) in Production](./images/btn-install-unlocked-package-production.png)](https://login.salesforce.com/packaging/installPackage.apexp?p0=04t5Y0000015nCfQAI)

## Unlocked Package - No Namespace - v1.0.1
## Unlocked Package - No Namespace - v1.0.2

[![Install Unlocked Package (no namespace) in a Sandbox](./images/btn-install-unlocked-package-sandbox.png)](https://test.salesforce.com/packaging/installPackage.apexp?p0=04t5Y0000015n6hQAA)
[![Install Unlocked Package (no namespace) in Production](./images/btn-install-unlocked-package-production.png)](https://login.salesforce.com/packaging/installPackage.apexp?p0=04t5Y0000015n6hQAA)
[![Install Unlocked Package (no namespace) in a Sandbox](./images/btn-install-unlocked-package-sandbox.png)](https://test.salesforce.com/packaging/installPackage.apexp?p0=04t5Y0000015nCaQAI)
[![Install Unlocked Package (no namespace) in Production](./images/btn-install-unlocked-package-production.png)](https://login.salesforce.com/packaging/installPackage.apexp?p0=04t5Y0000015nCaQAI)

---

Expand Down
2 changes: 1 addition & 1 deletion config/scratch-orgs/base-scratch-def.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"features": [],
"settings": {
"securitySettings": {
"enableAdminLoginAsAnyUser": false
"enableAdminLoginAsAnyUser": true
},
"userManagementSettings": {
"enableEnhancedPermsetMgmt": true,
Expand Down
4 changes: 2 additions & 2 deletions config/scratch-orgs/platform-cache-scratch-def.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"orgName": "Nebula Cache Manager - Base Scratch Org",
"orgName": "Nebula Cache Manager - Platform Cache Scratch Org",
"edition": "Enterprise",
"hasSampleData": true,
"country": "US",
"language": "en_US",
"features": ["PlatformCache"],
"settings": {
"securitySettings": {
"enableAdminLoginAsAnyUser": false
"enableAdminLoginAsAnyUser": true
},
"userManagementSettings": {
"enableEnhancedPermsetMgmt": true,
Expand Down
9 changes: 9 additions & 0 deletions lint-staged.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = {
'sfdx-project.json': () => {
return `npm run package:version:number:sync`;
},
'*.{cls,cmp,component,css,html,js,json,md,page,trigger,yaml,yml}': filenames => filenames.map(filename => `prettier --write '${filename}'`),
'*.{cls,trigger}': () => {
return [`npm run scan:apex`];
}
};
Loading

0 comments on commit 3dbf694

Please sign in to comment.