diff --git a/.github/workflows/create-org-and-deploy.yaml b/.github/workflows/create-org-and-deploy.yaml new file mode 100644 index 00000000000..24278e60e40 --- /dev/null +++ b/.github/workflows/create-org-and-deploy.yaml @@ -0,0 +1,76 @@ +name: Deploy and Run all Unit Tests +on: + push: + branches: + - '*' + - main + pull_request: + types: [ opened ] + branches: + - '*' + - main +jobs: + create-org-and-deploy: + runs-on: ubuntu-latest + env: + DEVHUB_ORG_ALIAS: OrtooISV + ORG_ALIAS_PREFIX: 'FTST' + steps: + # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it + - uses: actions/checkout@v2 + + - name: Salesforce SFDX CLI Action + uses: sfdx-actions/setup-sfdx@v1 + + # Update ./config/project-scratch-def.json + + - name: Update project-scratch-def.json orgName + uses: jossef/action-set-json-field@6e6d7e639f24b3955ef682815317b5613ac6ca12 + with: + file: ./config/project-scratch-def.json + field: orgName + value: "${{env.ORG_ALIAS_PREFIX}}${{github.run_number}}" + + - name: Update project-scratch-def.json description + uses: jossef/action-set-json-field@6e6d7e639f24b3955ef682815317b5613ac6ca12 + with: + file: ./config/project-scratch-def.json + field: description + value: "${{ github.repository }} , Org Alias ${{env.ORG_ALIAS_PREFIX}}${{github.run_number}}. Created by ${{ github.actor }}" + + - name: Show project-scratch-def.json + run: 'cat ./config/project-scratch-def.json' + + # sfdx-project.json file should be ok as is + + - name: Show sfdx-project.json + run: 'cat ./sfdx-project.json' + + # Dev Hub needed to create scratch org + + - name: Create DevHub Auth File + run: echo "${{ secrets.AUTH_SECRET_ISV }}" > devhub_auth_file.txt + + - name: Authorise Dev Hub Org + run: sfdx auth:sfdxurl:store -f devhub_auth_file.txt -d -a ${{ env.DEVHUB_ORG_ALIAS }} + + # Create Scratch Org + + - name: Run script CreateScratchOrgWithNamespaceOnlyHeadless.sh + run: ./scripts/std_batch/CreateScratchOrgWithNamespaceOnlyHeadless.sh "${{env.ORG_ALIAS_PREFIX}}${{github.run_number}}" + shell: sh + + # Push code to org + + - name: Deploy force-app to Org + run: sfdx force:source:deploy -p force-app --targetusername "${{env.ORG_ALIAS_PREFIX}}${{github.run_number}}" + + # Run All Unit Tests + + - name: Run All Unit Tests + run: sfdx force:apex:test:run -r human -u "${{env.ORG_ALIAS_PREFIX}}${{github.run_number}}" --wait 20 --codecoverage + + # Delete Scratch Org + + - name: Delete Scratch Org + run: sfdx force:org:delete --noprompt --targetusername "${{env.ORG_ALIAS_PREFIX}}${{github.run_number}}" \ No newline at end of file diff --git a/.gitignore b/.gitignore index f891339082e..e3e13e86f1d 100644 --- a/.gitignore +++ b/.gitignore @@ -37,4 +37,5 @@ ehthumbs.db $RECYCLE.BIN/ # Local environment variables -.env \ No newline at end of file +.env +.pmdCache diff --git a/.pmdCache b/.pmdCache deleted file mode 100644 index ebe2776c02a..00000000000 Binary files a/.pmdCache and /dev/null differ diff --git a/framework/default/ortoo-core/default/classes/utils/PackageUtils.cls b/framework/default/ortoo-core/default/classes/utils/PackageUtils.cls index f2fef9c0a19..9803d8fb4ec 100644 --- a/framework/default/ortoo-core/default/classes/utils/PackageUtils.cls +++ b/framework/default/ortoo-core/default/classes/utils/PackageUtils.cls @@ -36,11 +36,18 @@ public inherited sharing class PackageUtils String potentialNamespace = String.valueOf( classType ).substringBefore( '.' ); String remainingName = String.valueOf( classType ).substringAfter( '.' ); + if ( potentialNamespace == 'System' ) + { + return 'System'; + } + if ( ! String.isEmpty( remainingName ) ) { // We test this in case we were passed an inner class and the potentialNamespace - // is actually the name of the containing class, and there is no namespace - if ( classType == Type.forName( potentialNamespace, remainingName ) ) + // is actually the name of the containing class, and there is no namespace. + // If that's the case, the potentialNamespace actually contains the name of a class + Type potentialClassType = Type.forName( potentialNamespace ); + if ( potentialClassType != null ) { namespacePrefix = potentialNamespace; } diff --git a/framework/default/ortoo-core/default/classes/utils/tests/PackageUtilsTest.cls b/framework/default/ortoo-core/default/classes/utils/tests/PackageUtilsTest.cls index c5f670b2c36..2681d2e381f 100644 --- a/framework/default/ortoo-core/default/classes/utils/tests/PackageUtilsTest.cls +++ b/framework/default/ortoo-core/default/classes/utils/tests/PackageUtilsTest.cls @@ -2,11 +2,19 @@ private without sharing class PackageUtilsTest { @isTest - private static void getNamespace_whenCalledWithASystemClass_willReturnSystem() // NOPMD: Test method name format + private static void getNamespace_whenCalledWithASystemClassFullyDescribed_willReturnSystem() // NOPMD: Test method name format { String packageUtilsNamespace = PackageUtils.getNamespace( System.Test.class ); - System.assertEquals( 'System', packageUtilsNamespace, 'getNamespace, when called with a class, will the namespace it is defined in' ); + System.assertEquals( 'System', packageUtilsNamespace, 'getNamespace, when called with a System class, will return System' ); + } + + @isTest + private static void getNamespace_whenCalledWithASystemClass_willReturnSystem() // NOPMD: Test method name format + { + String packageUtilsNamespace = PackageUtils.getNamespace( Test.class ); + + System.assertEquals( 'System', packageUtilsNamespace, 'getNamespace, when called with a System class, will return System' ); } @isTest @@ -14,7 +22,7 @@ private without sharing class PackageUtilsTest { String packageUtilsNamespace = PackageUtils.getNamespace( PackageUtils.class ); // we can't test more than this because we don't know what namespace we will be installed in - System.assertNotEquals( null, packageUtilsNamespace, 'getNamespace, when called with a custom class, will return a String' ); + System.assertNotEquals( null, packageUtilsNamespace, 'getNamespace, when called with a custom class, will return the namespace it is in - cal only test it is a string though' ); } @isTest diff --git a/scripts/std_batch/CreateScratchOrgWithNamespaceOnlyHeadless.sh b/scripts/std_batch/CreateScratchOrgWithNamespaceOnlyHeadless.sh new file mode 100644 index 00000000000..3eb6161b7b3 --- /dev/null +++ b/scripts/std_batch/CreateScratchOrgWithNamespaceOnlyHeadless.sh @@ -0,0 +1,71 @@ +#!/bin/bash + +# chmod u+x CreateScratchOrgWithNamespaceOnlyHeadless.sh +# run in Terminal window of SFDX project with ./scripts/std_batch/CreateScratchOrgWithNamespaceOnlyHeadless.sh OrtooQassignScratch + +# CREATE SCRATCH ORG WITH NAMESPACE AND GENERATE PASSWORD +# +echo "Scratch Org Creation With Namespace ONLY (no data loaded) started." + +ORG_ALIAS="OrtooQassignScratch" + +if [ $# = 1 ]; then + ORG_ALIAS=$1 +else + echo + echo "Script requires one parameter" + echo "1. Org Alias for created org. e.g. OrtooQassignScratch" + echo + echo "**** Remember to update config/project-scratch-def.json file as appropriate." + echo " Include your public facing IP Address to prevent two-factor authentication." + echo " Update Business Hours if necessary." + echo + echo "**** Remember to update sfdx-project.json file with Namespace to be used." + echo + exit 1 +fi + +echo +echo "Using $ORG_ALIAS for Org alias" +echo + +echo "1. create" +sfdx force:org:create -f config/project-scratch-def.json --setalias "$ORG_ALIAS" --durationdays 30 --setdefaultusername --loglevel fatal +if [ $? = 0 ]; then + echo "Created Scratch Org with alias $ORG_ALIAS" +else + echo + echo "Non zero exit code: $?" + echo "Exiting script" + exit 1 +fi + +echo "2. password generation" +sfdx force:user:password:generate -u "$ORG_ALIAS" +if [ $? = 0 ]; then + echo "Password generated" +else + echo + echo "Non zero exit code: $?" + echo "Exiting script" + echo + exit 1 +fi + +echo "3. display Org details" +sfdx force:org:display -u "$ORG_ALIAS" +if [ $? = 0 ]; then + echo "Org details displayed" +else + echo + echo "Non zero exit code: $?" + echo "Exiting script" + echo + exit 1 +fi + +echo +echo "Scratch Org Creation With Namespace ONLY completed." +echo + +exit 0 \ No newline at end of file diff --git a/sfdx-project.json b/sfdx-project.json index 25698977964..10b34ec17a3 100644 --- a/sfdx-project.json +++ b/sfdx-project.json @@ -9,6 +9,7 @@ "default": true } ], + "namespace": "ortoo_qra", "sfdcLoginUrl": "https://login.salesforce.com", "sourceApiVersion": "52.0" }