From d6f31010f57b8bd96afe35708d518e50511b4174 Mon Sep 17 00:00:00 2001 From: Nick Maltbie Date: Sat, 16 Apr 2022 19:04:39 -0700 Subject: [PATCH] Added basic framework for enable code coverage --- .github/workflows/main.yml | 4 ++++ action.yml | 4 ++++ dist/index.js | 11 +++++++++-- src/index.ts | 2 ++ src/model/docker.ts | 2 ++ src/model/input.ts | 6 ++++++ 6 files changed, 27 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 8f66245..d3ee211 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -78,6 +78,9 @@ jobs: - unity-project-with-correct-tests unityVersion: - 2019.2.11f1 + enableCodeCovearge: + - true + - false steps: ########################### # Checkout # @@ -104,6 +107,7 @@ jobs: with: projectPath: ${{ matrix.projectPath }} unityVersion: ${{ matrix.unityVersion }} + enableCodeCovearge: ${{ matrix.enableCodeCovearge }} testMode: all # Test implicit artifactsPath, by not setting it diff --git a/action.yml b/action.yml index 17b93a8..059d1a1 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.' + enableCodeCoverage: + required: false + default: 'false' + description: 'Should code coverage results be collected for the test run.' artifactsPath: required: false default: 'artifacts' diff --git a/dist/index.js b/dist/index.js index aa64490..31d5a93 100644 --- a/dist/index.js +++ b/dist/index.js @@ -42,7 +42,7 @@ function run() { try { model_1.Action.checkCompatibility(); const { workspace, actionFolder } = model_1.Action; - const { editorVersion, customImage, projectPath, customParameters, testMode, artifactsPath, useHostNetwork, sshAgent, gitPrivateToken, githubToken, checkName, } = model_1.Input.getFromUser(); + const { editorVersion, customImage, projectPath, customParameters, testMode, enableCodeCoverage, artifactsPath, useHostNetwork, sshAgent, gitPrivateToken, githubToken, checkName, } = model_1.Input.getFromUser(); const baseImage = new model_1.ImageTag({ editorVersion, customImage }); const runnerTemporaryPath = process.env.RUNNER_TEMP; try { @@ -53,6 +53,7 @@ function run() { projectPath, customParameters, testMode, + enableCodeCoverage, artifactsPath, useHostNetwork, sshAgent, @@ -152,7 +153,7 @@ const path_1 = __importDefault(__nccwpck_require__(1017)); const Docker = { run(image, parameters, silent = false) { return __awaiter(this, void 0, void 0, function* () { - const { actionFolder, editorVersion, workspace, projectPath, customParameters, testMode, artifactsPath, useHostNetwork, sshAgent, gitPrivateToken, githubToken, runnerTemporaryPath, } = parameters; + const { actionFolder, editorVersion, workspace, projectPath, customParameters, testMode, enableCodeCoverage, artifactsPath, useHostNetwork, sshAgent, gitPrivateToken, githubToken, runnerTemporaryPath, } = parameters; const githubHome = path_1.default.join(runnerTemporaryPath, '_github_home'); if (!(0, fs_1.existsSync)(githubHome)) (0, fs_1.mkdirSync)(githubHome); @@ -171,6 +172,7 @@ const Docker = { --env PROJECT_PATH="${projectPath}" \ --env CUSTOM_PARAMETERS="${customParameters}" \ --env TEST_MODE="${testMode}" \ + --env ENABLE_CODE_COVERAGE="${enableCodeCoverage}" \ --env ARTIFACTS_PATH="${artifactsPath}" \ --env GITHUB_REF \ --env GITHUB_SHA \ @@ -385,6 +387,7 @@ const Input = { const rawProjectPath = (0, core_1.getInput)('projectPath') || '.'; const customParameters = (0, core_1.getInput)('customParameters') || ''; const testMode = ((0, core_1.getInput)('testMode') || 'all').toLowerCase(); + const enableCodeCoverage = (0, core_1.getInput)('enableCodeCoverage') || 'false'; const rawArtifactsPath = (0, core_1.getInput)('artifactsPath') || 'artifacts'; const rawUseHostNetwork = (0, core_1.getInput)('useHostNetwork') || 'false'; const sshAgent = (0, core_1.getInput)('sshAgent') || ''; @@ -395,6 +398,9 @@ const Input = { if (!this.testModes.includes(testMode)) { throw new Error(`Invalid testMode ${testMode}`); } + if (enableCodeCoverage !== 'true' && enableCodeCoverage !== 'false') { + throw new Error(`Invalid enableCodeCoverage "${enableCodeCoverage}"`); + } if (!this.isValidFolderName(rawProjectPath)) { throw new Error(`Invalid projectPath "${rawProjectPath}"`); } @@ -416,6 +422,7 @@ const Input = { projectPath, customParameters, testMode, + enableCodeCoverage, artifactsPath, useHostNetwork, sshAgent, diff --git a/src/index.ts b/src/index.ts index 2fce0b4..c417d00 100644 --- a/src/index.ts +++ b/src/index.ts @@ -12,6 +12,7 @@ async function run() { projectPath, customParameters, testMode, + enableCodeCoverage, artifactsPath, useHostNetwork, sshAgent, @@ -30,6 +31,7 @@ async function run() { projectPath, customParameters, testMode, + enableCodeCoverage, artifactsPath, useHostNetwork, sshAgent, diff --git a/src/model/docker.ts b/src/model/docker.ts index a3e1d8a..3f3f989 100644 --- a/src/model/docker.ts +++ b/src/model/docker.ts @@ -11,6 +11,7 @@ const Docker = { projectPath, customParameters, testMode, + enableCodeCoverage, artifactsPath, useHostNetwork, sshAgent, @@ -36,6 +37,7 @@ const Docker = { --env PROJECT_PATH="${projectPath}" \ --env CUSTOM_PARAMETERS="${customParameters}" \ --env TEST_MODE="${testMode}" \ + --env ENABLE_CODE_COVERAGE="${enableCodeCoverage}" \ --env ARTIFACTS_PATH="${artifactsPath}" \ --env GITHUB_REF \ --env GITHUB_SHA \ diff --git a/src/model/input.ts b/src/model/input.ts index 91c278c..1bceeea 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 enableCodeCoverage = getInput('enableCodeCoverage') || '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 (enableCodeCoverage !== 'true' && enableCodeCoverage !== 'false') { + throw new Error(`Invalid enableCodeCoverage "${enableCodeCoverage}"`); + } + if (!this.isValidFolderName(rawProjectPath)) { throw new Error(`Invalid projectPath "${rawProjectPath}"`); } @@ -57,6 +62,7 @@ const Input = { projectPath, customParameters, testMode, + enableCodeCoverage, artifactsPath, useHostNetwork, sshAgent,