diff --git a/action.yml b/action.yml index 17b93a8..a03f5fe 100644 --- a/action.yml +++ b/action.yml @@ -20,6 +20,10 @@ inputs: required: false default: 'all' description: 'The type of tests to be run by the test runner.' + coverageReport: + required: false + default: false + description: 'Whether to generate a coverage report.' artifactsPath: required: false default: 'artifacts' diff --git a/dist/steps/run_tests.sh b/dist/steps/run_tests.sh index f0646ef..f46c56d 100755 --- a/dist/steps/run_tests.sh +++ b/dist/steps/run_tests.sh @@ -14,6 +14,12 @@ echo "Using project path \"$UNITY_PROJECT_PATH\"." echo "Using artifacts path \"$ARTIFACTS_PATH\" to save test results." FULL_ARTIFACTS_PATH=$GITHUB_WORKSPACE/$ARTIFACTS_PATH +COVERAGE="" +if [ "$GENERATE_COVERAGE_REPORT" == "true" ]; then + echo "Generating code coverage report." + COVERAGE="-enableCodeCoverage" +fi + # # Display custom parameters # @@ -81,6 +87,8 @@ if [ "$EDIT_MODE" = "true" ]; then -runTests \ -testPlatform editmode \ -testResults "$FULL_ARTIFACTS_PATH/editmode-results.xml" \ + -coverageResultsPath "$FULL_ARTIFACTS_PATH" \ + $COVERAGE \ $CUSTOM_PARAMETERS # Catch exit code @@ -118,6 +126,8 @@ if [ "$PLAY_MODE" = "true" ]; then -runTests \ -testPlatform playmode \ -testResults "$FULL_ARTIFACTS_PATH/playmode-results.xml" \ + -coverageResultsPath "$FULL_ARTIFACTS_PATH" \ + $COVERAGE \ $CUSTOM_PARAMETERS # Catch exit code diff --git a/src/index.ts b/src/index.ts index d6c3a76..7b6aed8 100644 --- a/src/index.ts +++ b/src/index.ts @@ -12,6 +12,7 @@ async function run() { projectPath, customParameters, testMode, + generateCoverageReport, artifactsPath, useHostNetwork, sshAgent, @@ -33,6 +34,7 @@ async function run() { projectPath, customParameters, testMode, + generateCoverageReport, artifactsPath, useHostNetwork, sshAgent, diff --git a/src/model/docker.ts b/src/model/docker.ts index b6b661e..a52095f 100644 --- a/src/model/docker.ts +++ b/src/model/docker.ts @@ -26,6 +26,7 @@ const Docker = { projectPath, customParameters, testMode, + generateCoverageReport, artifactsPath, useHostNetwork, sshAgent, @@ -51,6 +52,7 @@ const Docker = { --env PROJECT_PATH="${projectPath}" \ --env CUSTOM_PARAMETERS="${customParameters}" \ --env TEST_MODE="${testMode}" \ + --env GENERATE_COVERAGE_REPORT="${generateCoverageReport}" \ --env ARTIFACTS_PATH="${artifactsPath}" \ --env GITHUB_REF \ --env GITHUB_SHA \ diff --git a/src/model/input.ts b/src/model/input.ts index 6a84e1f..a32697d 100644 --- a/src/model/input.ts +++ b/src/model/input.ts @@ -19,6 +19,7 @@ const Input = { const rawProjectPath = getInput('projectPath') || '.'; const customParameters = getInput('customParameters') || ''; const testMode = (getInput('testMode') || 'all').toLowerCase(); + const coverageReport = getInput('coverageReport') || 'false'; const rawArtifactsPath = getInput('artifactsPath') || 'artifacts'; const rawUseHostNetwork = getInput('useHostNetwork') || 'false'; const sshAgent = getInput('sshAgent') || ''; @@ -31,6 +32,10 @@ const Input = { throw new Error(`Invalid testMode ${testMode}`); } + if (coverageReport !== 'true' && coverageReport !== 'false') { + throw new Error(`Invalid coverageReport "${coverageReport}"`); + } + if (!this.isValidFolderName(rawProjectPath)) { throw new Error(`Invalid projectPath "${rawProjectPath}"`); } @@ -44,6 +49,7 @@ const Input = { } // Sanitise input + const generateCoverageReport = coverageReport === 'true'; const projectPath = rawProjectPath.replace(/\/$/, ''); const artifactsPath = rawArtifactsPath.replace(/\/$/, ''); const useHostNetwork = rawUseHostNetwork === 'true'; @@ -57,6 +63,7 @@ const Input = { projectPath, customParameters, testMode, + generateCoverageReport, artifactsPath, useHostNetwork, sshAgent,