Skip to content

Commit

Permalink
Standardised the build - particularly running apex and getting the co…
Browse files Browse the repository at this point in the history
…de coverage numbers
  • Loading branch information
rob-baillie-ortoo committed Apr 25, 2022
1 parent 4938a08 commit e76cf0f
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
18 changes: 18 additions & 0 deletions scripts/std_batch/GetApexCodeCoverage.sh
Original file line number Diff line number Diff line change
@@ -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
14 changes: 14 additions & 0 deletions scripts/std_batch/RunApexUnitTests.sh
Original file line number Diff line number Diff line change
@@ -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 '─────────────────────────────────────────────────────────────────────────────────────────────────────────────' )

0 comments on commit e76cf0f

Please sign in to comment.