Updated parameters and added tests

pull/182/head
Nick Maltbie 2022-04-18 19:57:08 -04:00
parent 0fb209bbbf
commit 3297ad7442
9 changed files with 46 additions and 92 deletions

View File

@ -215,14 +215,10 @@ jobs:
strategy:
fail-fast: false
matrix:
enableCodeCoverage:
- true
unityVersion:
- 2019.2.11f1
projectPath:
- unity-project-with-correct-tests
coverageAssemblyFilters:
- '+MyScripts'
testMode:
- playmode
- editmode
@ -248,21 +244,20 @@ jobs:
# Configure test runner
- name: Run tests
id: codecovtests
id: coveragetests
uses: ./
with:
projectPath: ${{ matrix.projectPath }}
unityVersion: ${{ matrix.unityVersion }}
testMode: ${{ matrix.testMode }}
enableCodeCoverage: ${{ matrix.enableCodeCoverage }}
coverageAssemblyFilters: ${{ matrix.coverageAssemblyFilters }}
coverageParameters: 'enableCyclomaticComplexity;generateHtmlReport;generateBadgeReport;assemblyFilters:+MyScripts'
# Upload artifacts
- name: Upload code coverage results
uses: actions/upload-artifact@v3
with:
name: Code coverage results (${{ matrix.testMode }} mode)
path: ${{ steps.codecovtests.outputs.coverageResultsPath }}
path: coverage
retention-days: 7
testEachModeSequentially:
@ -275,8 +270,6 @@ jobs:
- 2019.2.11f1
projectPath:
- unity-project-with-correct-tests
enableCodeCoverage:
- true
steps:
###########################
# Checkout #
@ -304,8 +297,7 @@ jobs:
unityVersion: ${{ matrix.unityVersion }}
testMode: editmode
artifactsPath: artifacts/editmode
enableCodeCoverage: ${{ matrix.enableCodeCoverage }}
coverageResultsPath: CodeCoverage/editmode
coverageResultsPath: coverage/editmode
# Configure second test runner
- name: Tests in playmode 📺
@ -315,8 +307,7 @@ jobs:
unityVersion: ${{ matrix.unityVersion }}
testMode: playmode
artifactsPath: artifacts/playmode
enableCodeCoverage: ${{ matrix.enableCodeCoverage }}
coverageResultsPath: CodeCoverage/playmode
coverageResultsPath: coverage/playmode
# Upload combined artifacts
- name: Upload combined test results

View File

@ -20,17 +20,13 @@ inputs:
required: false
default: 'all'
description: 'The type of tests to be run by the test runner.'
enableCodeCoverage:
coverageParameters:
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.'
default: 'enableCyclomaticComplexity;generateHtmlReport;generateBadgeReport'
description: 'Optional coverage parameters for the -coverageOptions argument.'
coverageResultsPath:
required: false
default: 'CodeCoverage'
default: 'coverage'
description: 'Path to write coverage results to when collecting code coverage.'
artifactsPath:
required: false

20
dist/index.js generated vendored
View File

@ -42,7 +42,7 @@ function run() {
try {
model_1.Action.checkCompatibility();
const { workspace, actionFolder } = model_1.Action;
const { editorVersion, customImage, projectPath, customParameters, testMode, enableCodeCoverage, coverageAssemblyFilters, coverageResultsPath, artifactsPath, useHostNetwork, sshAgent, gitPrivateToken, githubToken, checkName, } = model_1.Input.getFromUser();
const { editorVersion, customImage, projectPath, customParameters, testMode, coverageParameters, 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 {
@ -53,8 +53,7 @@ function run() {
projectPath,
customParameters,
testMode,
enableCodeCoverage,
coverageAssemblyFilters,
coverageParameters,
coverageResultsPath,
artifactsPath,
useHostNetwork,
@ -156,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, coverageAssemblyFilters, coverageResultsPath, artifactsPath, useHostNetwork, sshAgent, gitPrivateToken, githubToken, runnerTemporaryPath, } = parameters;
const { actionFolder, editorVersion, workspace, projectPath, customParameters, testMode, coverageParameters, 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);
@ -175,8 +174,7 @@ const Docker = {
--env PROJECT_PATH="${projectPath}" \
--env CUSTOM_PARAMETERS="${customParameters}" \
--env TEST_MODE="${testMode}" \
--env ENABLE_CODE_COVERAGE="${enableCodeCoverage}" \
--env COVERAGE_ASSEMBLY_FILTERS="${coverageAssemblyFilters}" \
--env COVERAGE_OPTIONS="${coverageParameters}" \
--env COVERAGE_RESULTS_PATH="${coverageResultsPath}" \
--env ARTIFACTS_PATH="${artifactsPath}" \
--env GITHUB_REF \
@ -392,8 +390,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 rawEnableCodeCoverage = (0, core_1.getInput)('enableCodeCoverage') || 'false';
const coverageAssemblyFilters = (0, core_1.getInput)('coverageAssemblyFilters') || '';
const coverageParameters = (0, core_1.getInput)('coverageParameters') || '';
const rawCoverageResultsPath = (0, core_1.getInput)('coverageResultsPath') || 'CodeCoverage';
const rawArtifactsPath = (0, core_1.getInput)('artifactsPath') || 'artifacts';
const rawUseHostNetwork = (0, core_1.getInput)('useHostNetwork') || 'false';
@ -405,9 +402,6 @@ const Input = {
if (!this.testModes.includes(testMode)) {
throw new Error(`Invalid testMode ${testMode}`);
}
if (rawEnableCodeCoverage !== 'true' && rawEnableCodeCoverage !== 'false') {
throw new Error(`Invalid enableCodeCoverage "${rawEnableCodeCoverage}"`);
}
if (!this.isValidFolderName(rawCoverageResultsPath)) {
throw new Error(`Invalid coverageResultsPath "${rawCoverageResultsPath}"`);
}
@ -424,7 +418,6 @@ 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
@ -434,8 +427,7 @@ const Input = {
projectPath,
customParameters,
testMode,
enableCodeCoverage,
coverageAssemblyFilters,
coverageParameters,
coverageResultsPath,
artifactsPath,
useHostNetwork,

2
dist/index.js.map generated vendored

File diff suppressed because one or more lines are too long

View File

@ -24,9 +24,6 @@ echo "Using custom parameters $CUSTOM_PARAMETERS."
# Set and display the coverage results path
#
echo "Using artifacts path \"$COVERAGE_RESULTS_PATH\" to save test coverage results."
FULL_COVERAGE_RESULTS_PATH=$GITHUB_WORKSPACE/$COVERAGE_RESULTS_PATH
# Set the modes for testing
case $TEST_MODE in
editmode)
@ -44,32 +41,6 @@ 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=""
# Setup assembly filters if provided
if [ -n "$COVERAGE_ASSEMBLY_FILTERS" ]; then
ASSEMBLY_FILTER_OPTIONS=";assemblyFilters:$COVERAGE_ASSEMBLY_FILTERS"
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 -coverageResultsPath $FULL_COVERAGE_RESULTS_PATH"
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
@ -115,8 +86,11 @@ if [ "$EDIT_MODE" = "true" ]; then
-runTests \
-testPlatform editmode \
-testResults "$FULL_ARTIFACTS_PATH/editmode-results.xml" \
$CUSTOM_PARAMETERS \
$CODE_COVERAGE_PARAMETERS
-enableCodeCoverage \
-debugCodeOptimization \
-coverageResultsPath "$FULL_COVERAGE_RESULTS_PATH" \
-coverageOptions "$COVERAGE_OPTIONS" \
$CUSTOM_PARAMETERS
# Catch exit code
EDIT_MODE_EXIT_CODE=$?
@ -153,8 +127,11 @@ if [ "$PLAY_MODE" = "true" ]; then
-runTests \
-testPlatform playmode \
-testResults "$FULL_ARTIFACTS_PATH/playmode-results.xml" \
$CUSTOM_PARAMETERS \
$CODE_COVERAGE_PARAMETERS
-enableCodeCoverage \
-debugCodeOptimization \
-coverageResultsPath "$FULL_COVERAGE_RESULTS_PATH" \
-coverageOptions "$COVERAGE_OPTIONS" \
$CUSTOM_PARAMETERS
# Catch exit code
PLAY_MODE_EXIT_CODE=$?
@ -209,7 +186,7 @@ fi
# Combine test results if needed
#
COMBINE_EXIT_CODE=0
if [ "$EDIT_MODE" = "true" ] && [ "$PLAY_MODE" = "true" ] && [ "$ENABLE_CODE_COVERAGE" = "true" ]; then
if [ "$EDIT_MODE" = "true" ] && [ "$PLAY_MODE" = "true" ] && [ "$COVERAGE" = "true" ]; then
echo ""
echo "##############################"
echo "# Combining Coverage Results #"
@ -217,12 +194,11 @@ if [ "$EDIT_MODE" = "true" ] && [ "$PLAY_MODE" = "true" ] && [ "$ENABLE_CODE_COV
echo ""
unity-editor \
-batchmode \
-debugCodeOptimization \
-enableCodeCoverage \
-logFile "$FULL_ARTIFACTS_PATH/combine_coverage.log" \
-projectPath "$UNITY_PROJECT_PATH" \
-enableCodeCoverage \
-debugCodeOptimization \
-coverageResultsPath "$FULL_COVERAGE_RESULTS_PATH" \
-coverageOptions "generateHtmlReport;generateBadgeReport" \
-coverageOptions "$COVERAGE_OPTIONS" \
-quit
# Catch exit code

View File

@ -12,8 +12,7 @@ async function run() {
projectPath,
customParameters,
testMode,
enableCodeCoverage,
coverageAssemblyFilters,
coverageParameters,
coverageResultsPath,
artifactsPath,
useHostNetwork,
@ -33,8 +32,7 @@ async function run() {
projectPath,
customParameters,
testMode,
enableCodeCoverage,
coverageAssemblyFilters,
coverageParameters,
coverageResultsPath,
artifactsPath,
useHostNetwork,

View File

@ -11,8 +11,7 @@ const Docker = {
projectPath,
customParameters,
testMode,
enableCodeCoverage,
coverageAssemblyFilters,
coverageParameters,
coverageResultsPath,
artifactsPath,
useHostNetwork,
@ -39,8 +38,7 @@ const Docker = {
--env PROJECT_PATH="${projectPath}" \
--env CUSTOM_PARAMETERS="${customParameters}" \
--env TEST_MODE="${testMode}" \
--env ENABLE_CODE_COVERAGE="${enableCodeCoverage}" \
--env COVERAGE_ASSEMBLY_FILTERS="${coverageAssemblyFilters}" \
--env COVERAGE_OPTIONS="${coverageParameters}" \
--env COVERAGE_RESULTS_PATH="${coverageResultsPath}" \
--env ARTIFACTS_PATH="${artifactsPath}" \
--env GITHUB_REF \

View File

@ -19,8 +19,7 @@ const Input = {
const rawProjectPath = getInput('projectPath') || '.';
const customParameters = getInput('customParameters') || '';
const testMode = (getInput('testMode') || 'all').toLowerCase();
const rawEnableCodeCoverage = getInput('enableCodeCoverage') || 'false';
const coverageAssemblyFilters = getInput('coverageAssemblyFilters') || '';
const coverageParameters = getInput('coverageParameters') || '';
const rawCoverageResultsPath = getInput('coverageResultsPath') || 'CodeCoverage';
const rawArtifactsPath = getInput('artifactsPath') || 'artifacts';
const rawUseHostNetwork = getInput('useHostNetwork') || 'false';
@ -34,10 +33,6 @@ const Input = {
throw new Error(`Invalid testMode ${testMode}`);
}
if (rawEnableCodeCoverage !== 'true' && rawEnableCodeCoverage !== 'false') {
throw new Error(`Invalid enableCodeCoverage "${rawEnableCodeCoverage}"`);
}
if (!this.isValidFolderName(rawCoverageResultsPath)) {
throw new Error(`Invalid coverageResultsPath "${rawCoverageResultsPath}"`);
}
@ -58,7 +53,6 @@ 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;
@ -70,8 +64,7 @@ const Input = {
projectPath,
customParameters,
testMode,
enableCodeCoverage,
coverageAssemblyFilters,
coverageParameters,
coverageResultsPath,
artifactsPath,
useHostNetwork,

View File

@ -9,6 +9,16 @@ describe('Output', () => {
describe('setCoverageResultsPath', () => {
it('does not throw', async () => {
await expect(Output.setCoverageResultsPath('')).resolves.not.toThrow();
await expect(Output.setCoverageResultsPath('artifacts')).resolves.not.toThrow();
await expect(Output.setCoverageResultsPath('coverage')).resolves.not.toThrow();
await expect(Output.setCoverageResultsPath('CodeCoverage')).resolves.not.toThrow();
await expect(Output.setCoverageResultsPath('./artifacts')).resolves.not.toThrow();
await expect(Output.setCoverageResultsPath('./coverage')).resolves.not.toThrow();
await expect(Output.setCoverageResultsPath('./CodeCoverage')).resolves.not.toThrow();
await expect(Output.setCoverageResultsPath('./artifacts/coverage')).resolves.not.toThrow();
await expect(Output.setCoverageResultsPath('./coverage/')).resolves.not.toThrow();
await expect(Output.setCoverageResultsPath('./CodeCoverage/')).resolves.not.toThrow();
await expect(Output.setCoverageResultsPath('./artifacts/coverage/')).resolves.not.toThrow();
});
});
});