Added basic coverage results building and combination
parent
d6f31010f5
commit
3407decdfb
|
@ -24,6 +24,14 @@ inputs:
|
|||
required: false
|
||||
default: 'false'
|
||||
description: 'Should code coverage results be collected for the test run.'
|
||||
coverageAssemblyFilters:
|
||||
required: false
|
||||
default: ''
|
||||
description: 'Optional coverage assembly filters when collecting code coverage.'
|
||||
coverageResultsPath:
|
||||
required: false
|
||||
default: ''
|
||||
description: 'Path to write coverage results to when collecting code coverage.'
|
||||
artifactsPath:
|
||||
required: false
|
||||
default: 'artifacts'
|
||||
|
|
|
@ -42,7 +42,7 @@ function run() {
|
|||
try {
|
||||
model_1.Action.checkCompatibility();
|
||||
const { workspace, actionFolder } = model_1.Action;
|
||||
const { editorVersion, customImage, projectPath, customParameters, testMode, enableCodeCoverage, artifactsPath, useHostNetwork, sshAgent, gitPrivateToken, githubToken, checkName, } = model_1.Input.getFromUser();
|
||||
const { editorVersion, customImage, projectPath, customParameters, testMode, enableCodeCoverage, coverageAssemblyFilters, coverageResultsPath, 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 {
|
||||
|
@ -54,6 +54,8 @@ function run() {
|
|||
customParameters,
|
||||
testMode,
|
||||
enableCodeCoverage,
|
||||
coverageAssemblyFilters,
|
||||
coverageResultsPath,
|
||||
artifactsPath,
|
||||
useHostNetwork,
|
||||
sshAgent,
|
||||
|
@ -153,7 +155,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, enableCodeCoverage, artifactsPath, useHostNetwork, sshAgent, gitPrivateToken, githubToken, runnerTemporaryPath, } = parameters;
|
||||
const { actionFolder, editorVersion, workspace, projectPath, customParameters, testMode, enableCodeCoverage, coverageAssemblyFilters, coverageResultsPath, 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);
|
||||
|
@ -173,6 +175,8 @@ const Docker = {
|
|||
--env CUSTOM_PARAMETERS="${customParameters}" \
|
||||
--env TEST_MODE="${testMode}" \
|
||||
--env ENABLE_CODE_COVERAGE="${enableCodeCoverage}" \
|
||||
--env COVERAGE_ASSEMBLY_FILTERS="${coverageAssemblyFilters}" \
|
||||
--env COVERAGE_RESULTS_PATH="${coverageResultsPath}" \
|
||||
--env ARTIFACTS_PATH="${artifactsPath}" \
|
||||
--env GITHUB_REF \
|
||||
--env GITHUB_SHA \
|
||||
|
@ -387,7 +391,9 @@ 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 rawEnableCodeCoverage = (0, core_1.getInput)('enableCodeCoverage') || 'false';
|
||||
const coverageAssemblyFilters = (0, core_1.getInput)('coverageAssemblyFilters') || '';
|
||||
const rawCoverageResultsPath = (0, core_1.getInput)('coverageResultsPath') || '';
|
||||
const rawArtifactsPath = (0, core_1.getInput)('artifactsPath') || 'artifacts';
|
||||
const rawUseHostNetwork = (0, core_1.getInput)('useHostNetwork') || 'false';
|
||||
const sshAgent = (0, core_1.getInput)('sshAgent') || '';
|
||||
|
@ -398,8 +404,23 @@ 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 (rawEnableCodeCoverage !== 'true' && rawEnableCodeCoverage !== 'false') {
|
||||
throw new Error(`Invalid enableCodeCoverage "${rawEnableCodeCoverage}"`);
|
||||
}
|
||||
if (rawEnableCodeCoverage !== 'true' && rawEnableCodeCoverage !== 'false') {
|
||||
throw new Error(`Invalid enableCodeCoverage "${rawEnableCodeCoverage}"`);
|
||||
}
|
||||
if (rawEnableCodeCoverage !== 'true' && coverageAssemblyFilters !== '') {
|
||||
throw new Error(`coverageAssemblyFilters should not be set if enableCodeCoverage is not enabled.`);
|
||||
}
|
||||
if (coverageAssemblyFilters !== '') {
|
||||
throw new Error(`coverageAssemblyFilters should not be set if enableCodeCoverage is not enabled.`);
|
||||
}
|
||||
if (rawEnableCodeCoverage !== 'true' && rawCoverageResultsPath !== '') {
|
||||
throw new Error(`coverageResultsPath should not be set if enableCodeCoverage is not enabled.`);
|
||||
}
|
||||
if (!this.isValidFolderName(rawCoverageResultsPath)) {
|
||||
throw new Error(`Invalid coverageResultsPath "${rawCoverageResultsPath}"`);
|
||||
}
|
||||
if (!this.isValidFolderName(rawProjectPath)) {
|
||||
throw new Error(`Invalid projectPath "${rawProjectPath}"`);
|
||||
|
@ -414,6 +435,8 @@ const Input = {
|
|||
const projectPath = rawProjectPath.replace(/\/$/, '');
|
||||
const artifactsPath = rawArtifactsPath.replace(/\/$/, '');
|
||||
const useHostNetwork = rawUseHostNetwork === 'true';
|
||||
const enableCodeCoverage = rawEnableCodeCoverage === 'true';
|
||||
const coverageResultsPath = rawCoverageResultsPath.replace(/\/$/, '');
|
||||
const editorVersion = unityVersion === 'auto' ? unity_version_parser_1.default.read(projectPath) : unityVersion;
|
||||
// Return sanitised input
|
||||
return {
|
||||
|
@ -423,6 +446,8 @@ const Input = {
|
|||
customParameters,
|
||||
testMode,
|
||||
enableCodeCoverage,
|
||||
coverageAssemblyFilters,
|
||||
coverageResultsPath,
|
||||
artifactsPath,
|
||||
useHostNetwork,
|
||||
sshAgent,
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -36,6 +36,38 @@ case $TEST_MODE in
|
|||
;;
|
||||
esac
|
||||
|
||||
#
|
||||
# Build code coverage parameters
|
||||
#
|
||||
CODE_COVERAGE_PARAMETERS=""
|
||||
if [ "$ENABLE_CODE_COVERAGE" = "true" ]; then
|
||||
# Configure code coverage options
|
||||
COVERAGE_OPTIONS=""
|
||||
ASSEMBLY_FILTER_OPTIONS=""
|
||||
COVERAGE_RESULTS_OPTIONS=""
|
||||
|
||||
# Setup assembly filters if provided
|
||||
if [ -n "$COVERAGE_ASSEMBLY_FILTERS" ]; then
|
||||
ASSEMBLY_FILTER_OPTIONS=";assemblyFilters:$COVERAGE_ASSEMBLY_FILTERS"
|
||||
fi
|
||||
|
||||
# Setup coverage results path if provided
|
||||
if [ -n "$COVERAGE_RESULTS_PATH" ]; then
|
||||
COVERAGE_RESULTS_OPTIONS="-coverageResultsPath $COVERAGE_RESULTS_PATH"
|
||||
fi
|
||||
|
||||
# Options to combine both playmode and editmode results
|
||||
if [ "$EDIT_MODE" = "true" ] && [ "$PLAY_MODE" = "true" ]; then
|
||||
COVERAGE_OPTIONS="enableCyclomaticComplexity$ASSEMBLY_FILTER_OPTIONS"
|
||||
else
|
||||
COVERAGE_OPTIONS="enableCyclomaticComplexity;generateHtmlReport;generateBadgeReport$ASSEMBLY_FILTER_OPTIONS"
|
||||
fi
|
||||
|
||||
# Set parameters for code coverage
|
||||
CODE_COVERAGE_PARAMETERS="-debugCodeOptimization -enableCodeCoverage -coverageOptions $COVERAGE_OPTIONS $COVERAGE_RESULTS_OPTIONS"
|
||||
fi
|
||||
echo "Using code coverage parameters $CODE_COVERAGE_PARAMETERS."
|
||||
|
||||
# The following tests are 2019 mode (requires Unity 2019.2.11f1 or later)
|
||||
# Reference: https://docs.unity3d.com/2019.3/Documentation/Manual/CommandLineArguments.html
|
||||
|
||||
|
@ -81,7 +113,8 @@ if [ "$EDIT_MODE" = "true" ]; then
|
|||
-runTests \
|
||||
-testPlatform editmode \
|
||||
-testResults "$FULL_ARTIFACTS_PATH/editmode-results.xml" \
|
||||
$CUSTOM_PARAMETERS
|
||||
$CUSTOM_PARAMETERS \
|
||||
$CODE_COVERAGE_PARAMETERS
|
||||
|
||||
# Catch exit code
|
||||
EDIT_MODE_EXIT_CODE=$?
|
||||
|
@ -118,7 +151,8 @@ if [ "$PLAY_MODE" = "true" ]; then
|
|||
-runTests \
|
||||
-testPlatform playmode \
|
||||
-testResults "$FULL_ARTIFACTS_PATH/playmode-results.xml" \
|
||||
$CUSTOM_PARAMETERS
|
||||
$CUSTOM_PARAMETERS \
|
||||
$CODE_COVERAGE_PARAMETERS
|
||||
|
||||
# Catch exit code
|
||||
PLAY_MODE_EXIT_CODE=$?
|
||||
|
@ -169,6 +203,32 @@ if [ "$PLAY_MODE" = "true" ]; then
|
|||
cat "$FULL_ARTIFACTS_PATH/playmode-results.xml" | grep test-run | grep Passed
|
||||
fi
|
||||
|
||||
#
|
||||
# Combine test results if needed
|
||||
#
|
||||
if [ "$EDIT_MODE" = "true" ] && [ "$PLAY_MODE" = "true" ] && [ "$ENABLE_CODE_COVERAGE" = "true" ]; then
|
||||
# Setup coverage results path if provided
|
||||
COVERAGE_RESULTS_OPTIONS=""
|
||||
if [ -n "$COVERAGE_RESULTS_PATH" ]; then
|
||||
COVERAGE_RESULTS_OPTIONS="-coverageResultsPath $COVERAGE_RESULTS_PATH"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "##############################"
|
||||
echo "# Combining Coverage Results #"
|
||||
echo "##############################"
|
||||
echo ""
|
||||
unity-editor \
|
||||
-batchmode \
|
||||
-debugCodeOptimization \
|
||||
-enableCodeCoverage \
|
||||
-logFile "$FULL_ARTIFACTS_PATH/coverage_combination.log" \
|
||||
-projectPath "$UNITY_PROJECT_PATH" \
|
||||
$COVERAGE_RESULTS_OPTIONS \
|
||||
-coverageOptions generateHtmlReport;generateBadgeReport \
|
||||
-quit
|
||||
fi
|
||||
|
||||
#
|
||||
# Exit
|
||||
#
|
||||
|
|
|
@ -13,6 +13,8 @@ async function run() {
|
|||
customParameters,
|
||||
testMode,
|
||||
enableCodeCoverage,
|
||||
coverageAssemblyFilters,
|
||||
coverageResultsPath,
|
||||
artifactsPath,
|
||||
useHostNetwork,
|
||||
sshAgent,
|
||||
|
@ -32,6 +34,8 @@ async function run() {
|
|||
customParameters,
|
||||
testMode,
|
||||
enableCodeCoverage,
|
||||
coverageAssemblyFilters,
|
||||
coverageResultsPath,
|
||||
artifactsPath,
|
||||
useHostNetwork,
|
||||
sshAgent,
|
||||
|
|
|
@ -12,6 +12,8 @@ const Docker = {
|
|||
customParameters,
|
||||
testMode,
|
||||
enableCodeCoverage,
|
||||
coverageAssemblyFilters,
|
||||
coverageResultsPath,
|
||||
artifactsPath,
|
||||
useHostNetwork,
|
||||
sshAgent,
|
||||
|
@ -38,6 +40,8 @@ const Docker = {
|
|||
--env CUSTOM_PARAMETERS="${customParameters}" \
|
||||
--env TEST_MODE="${testMode}" \
|
||||
--env ENABLE_CODE_COVERAGE="${enableCodeCoverage}" \
|
||||
--env COVERAGE_ASSEMBLY_FILTERS="${coverageAssemblyFilters}" \
|
||||
--env COVERAGE_RESULTS_PATH="${coverageResultsPath}" \
|
||||
--env ARTIFACTS_PATH="${artifactsPath}" \
|
||||
--env GITHUB_REF \
|
||||
--env GITHUB_SHA \
|
||||
|
|
|
@ -19,7 +19,9 @@ const Input = {
|
|||
const rawProjectPath = getInput('projectPath') || '.';
|
||||
const customParameters = getInput('customParameters') || '';
|
||||
const testMode = (getInput('testMode') || 'all').toLowerCase();
|
||||
const enableCodeCoverage = getInput('enableCodeCoverage') || 'false';
|
||||
const rawEnableCodeCoverage = getInput('enableCodeCoverage') || 'false';
|
||||
const coverageAssemblyFilters = getInput('coverageAssemblyFilters') || '';
|
||||
const rawCoverageResultsPath = getInput('coverageResultsPath') || '';
|
||||
const rawArtifactsPath = getInput('artifactsPath') || 'artifacts';
|
||||
const rawUseHostNetwork = getInput('useHostNetwork') || 'false';
|
||||
const sshAgent = getInput('sshAgent') || '';
|
||||
|
@ -32,8 +34,34 @@ const Input = {
|
|||
throw new Error(`Invalid testMode ${testMode}`);
|
||||
}
|
||||
|
||||
if (enableCodeCoverage !== 'true' && enableCodeCoverage !== 'false') {
|
||||
throw new Error(`Invalid enableCodeCoverage "${enableCodeCoverage}"`);
|
||||
if (rawEnableCodeCoverage !== 'true' && rawEnableCodeCoverage !== 'false') {
|
||||
throw new Error(`Invalid enableCodeCoverage "${rawEnableCodeCoverage}"`);
|
||||
}
|
||||
|
||||
if (rawEnableCodeCoverage !== 'true' && rawEnableCodeCoverage !== 'false') {
|
||||
throw new Error(`Invalid enableCodeCoverage "${rawEnableCodeCoverage}"`);
|
||||
}
|
||||
|
||||
if (rawEnableCodeCoverage !== 'true' && coverageAssemblyFilters !== '') {
|
||||
throw new Error(
|
||||
`coverageAssemblyFilters should not be set if enableCodeCoverage is not enabled.`,
|
||||
);
|
||||
}
|
||||
|
||||
if (coverageAssemblyFilters !== '') {
|
||||
throw new Error(
|
||||
`coverageAssemblyFilters should not be set if enableCodeCoverage is not enabled.`,
|
||||
);
|
||||
}
|
||||
|
||||
if (rawEnableCodeCoverage !== 'true' && rawCoverageResultsPath !== '') {
|
||||
throw new Error(
|
||||
`coverageResultsPath should not be set if enableCodeCoverage is not enabled.`,
|
||||
);
|
||||
}
|
||||
|
||||
if (!this.isValidFolderName(rawCoverageResultsPath)) {
|
||||
throw new Error(`Invalid coverageResultsPath "${rawCoverageResultsPath}"`);
|
||||
}
|
||||
|
||||
if (!this.isValidFolderName(rawProjectPath)) {
|
||||
|
@ -52,6 +80,8 @@ const Input = {
|
|||
const projectPath = rawProjectPath.replace(/\/$/, '');
|
||||
const artifactsPath = rawArtifactsPath.replace(/\/$/, '');
|
||||
const useHostNetwork = rawUseHostNetwork === 'true';
|
||||
const enableCodeCoverage = rawEnableCodeCoverage === 'true';
|
||||
const coverageResultsPath = rawCoverageResultsPath.replace(/\/$/, '');
|
||||
const editorVersion =
|
||||
unityVersion === 'auto' ? UnityVersionParser.read(projectPath) : unityVersion;
|
||||
|
||||
|
@ -63,6 +93,8 @@ const Input = {
|
|||
customParameters,
|
||||
testMode,
|
||||
enableCodeCoverage,
|
||||
coverageAssemblyFilters,
|
||||
coverageResultsPath,
|
||||
artifactsPath,
|
||||
useHostNetwork,
|
||||
sshAgent,
|
||||
|
|
Loading…
Reference in New Issue