diff --git a/.github/workflows/create-org-and-deploy.yaml b/.github/workflows/DeployAndRunUnitTests.yaml similarity index 87% rename from .github/workflows/create-org-and-deploy.yaml rename to .github/workflows/DeployAndRunUnitTests.yaml index 36353591e48..89f085319ff 100644 --- a/.github/workflows/create-org-and-deploy.yaml +++ b/.github/workflows/DeployAndRunUnitTests.yaml @@ -67,8 +67,15 @@ jobs: # Run Apex Unit Tests - - name: Run Apex Unit Tests - run: sfdx force:apex:test:run -r human -u "${{env.ORG_ALIAS_PREFIX}}${{github.run_number}}" --wait 20 | grep -v ' Pass '; test ${PIPESTATUS[0]} -eq 0 + - name: Run All Unit Tests + run: ./scripts/std_batch/RunApexUnitTests.sh "${{env.ORG_ALIAS_PREFIX}}${{github.run_number}}" + shell: bash + + # Get Apex Code Coverage Numbers + + - name: Get Apex Code Coverage + run: ./scripts/std_batch/GetApexCodeCoverage.sh "${{env.ORG_ALIAS_PREFIX}}${{github.run_number}}" + shell: sh # Prepare Jest Modules diff --git a/scripts/std_batch/GetApexCodeCoverage.sh b/scripts/std_batch/GetApexCodeCoverage.sh new file mode 100755 index 00000000000..f74c25d05c7 --- /dev/null +++ b/scripts/std_batch/GetApexCodeCoverage.sh @@ -0,0 +1,18 @@ +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 + exit 1 +fi + +sfdx force:data:soql:query -u "$ORG_ALIAS" -t -q "SELECT SUM(NumLinesUncovered), SUM(NumLinesCovered) FROM ApexCodeCoverageAggregate" | grep -o -E '[0-9]+' | xargs | while read -r uncovered covered remainder ; do + totallines=$(expr $covered + $uncovered) + coveredtimeshundred=$(expr $covered \* 100) + percentage=$(expr $coveredtimeshundred / $totallines) + echo "Uncovered: $uncovered, Covered: $covered, Percentage: $percentage%" +done \ No newline at end of file diff --git a/scripts/std_batch/RunApexUnitTests.sh b/scripts/std_batch/RunApexUnitTests.sh new file mode 100755 index 00000000000..9791aa3803d --- /dev/null +++ b/scripts/std_batch/RunApexUnitTests.sh @@ -0,0 +1,14 @@ +#!/bin/bash +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 + exit 1 +fi + +( set -o pipefail; SFDX_IMPROVED_CODE_COVERAGE='true' SFDX_MAX_QUERY_LIMIT=200000 sfdx force:apex:test:run -u "$ORG_ALIAS" -r human --codecoverage --wait 30 | grep -v ' Pass ' | grep -v '^[a-zA-Z0-9]\{18\}\s\s' | grep -v 'UNCOVERED' | grep -v 'Apex Code Coverage' | grep -v ' ─────── ───────────────' | grep -v '─────────────────────────────────────────────────────────────────────────────────────────────────────────────' ) \ No newline at end of file