mirror of
https://github.com/game-ci/unity-test-runner.git
synced 2026-01-28 21:59:06 +08:00
Add Feature to test Unity Packages (#164)
* (should fail) add jq install to docker image * (might fail) remove rm rf call * move things around to try to fix test * Revert "(might fail) remove rm rf call" This reverts commit22f74ebca7. * remove silent setting from docker test * Fix failing test's Docker image * Add new input and basic test * Add test package; start using jq cli * Use test package in test workflow * Create temporary Unity Project and run tests * Test removing jq install from Dockerfile * Revert "Test removing jq install from Dockerfile" This reverts commit6aa7a6f443. * Remove mkdir call * remove duplicate command * add packageMode option back in * build changes * check for apt-get before installing jq * change apt-get version check message * spelling and documentation fixes * add working example unity package with tests * add temp pwd call to help figure out absolute pathing * fix workflow package location * add jq to add package to temp project packages * try fixing jq calls * clean up jq calls, fix variable expansion * try renaming jq args * try using different arg syntax for jq * try wrapping args in parentheses * try using double quotes only * try changing up quoting * try properly using string interpolation * try removing colon * add string interpolation to key * omit double quotes from jq call to retrieve package name * clean up logging * add rest of workflow tests * Revert "add rest of workflow tests" This reverts commitc0bb008b2c. * add play mode test without cache * add package mode all mode workflow step * add consecutive ppackage mode workflow step * add package mode "like in the readme" test * fix workflow syntax error * try to fix syntax error again * use correct folder * *hopefully actually* use correct package path * try adding caching to "readme" test * remove caching/mentions of caching from package mode tests * fix artifacts paths * fix artifacts pathing and names * fix combined artifacts for package mode * clean up documentation and exit code * clarify allowed docker images for packageMode * update README to mention Unity packages * move package name validation to TS part of action * improve logging for temp project creation failure * make husky hook executable * add error for missing tests folder * update docs to reflect unsupported packages * remove jq install * Revert "remove jq install" This reverts commitbd35ac8f6f. * TEMP log image in use * Revert "TEMP log image in use" This reverts commit95722dcab4. * Revert "Revert "remove jq install"" This reverts commite3bac048b1. * TEMP list installed packages * Revert "TEMP list installed packages" This reverts commitdb9c07da38. * TEMP log project's manifest * add code coverage package to generated project * remove temp project manifest log * add coverage to package mode tests * update name of package coverage steps * add codecoverage dependency to test package * Revert "add codecoverage dependency to test package" This reverts commit4b2c03069d. * add assembly filters for coverage * TEMP console log project folder * Revert "TEMP console log project folder" This reverts commit411ec51817. * add logic to copy package to folder without activation file * fix false positive activation file detection * fix improper bash "if" formatting * TEMP remove conditional for package copying * Revert "TEMP remove conditional for package copying" This reverts commit4f12d83889. * Revert "fix improper bash "if" formatting" This reverts commitacb975bcea. * Revert "fix false positive activation file detection" This reverts commit580c9c14a0. * Revert "add logic to copy package to folder without activation file" This reverts commitb20d994b5d. * run yarn build * move package mode check lower in the file * throw error if unity version is auto in package mode * fix unity version error wording * try deleting activate license file * try logging hidden package files * try deleting all non-package files * fix license activation files deletion * scrap file removals and print dir permissions * log permissions for package folder * Add packageMode inputs to main * fix fs mocks and run yarn build * fix documentation and add error message for missing jq * add clarification on package mode caveats * fix line endings problem (?) * Revert "fix line endings problem (?)" This reverts commit1cba302bc4. * Revert "add clarification on package mode caveats" This reverts commitfb62d36ba1. * Revert "fix documentation and add error message for missing jq" This reverts commit0df3ab6b88. * Redo the input docs fixes * Redo the jq presence test * update readme to indicate package mode caveats * fix wording on coverageOptions * one more wording fix on coverageOptions * move sample package to example.com domain --------- Co-authored-by: Aaron Trudeau <120415438+trudeaua-vividream-software@users.noreply.github.com>
This commit is contained in:
68
dist/index.js
generated
vendored
68
dist/index.js
generated
vendored
@@ -98,7 +98,7 @@ function run() {
|
||||
try {
|
||||
model_1.Action.checkCompatibility();
|
||||
const { workspace, actionFolder } = model_1.Action;
|
||||
const { editorVersion, customImage, projectPath, customParameters, testMode, coverageOptions, artifactsPath, useHostNetwork, sshAgent, gitPrivateToken, githubToken, checkName, chownFilesTo, unityLicensingServer, } = model_1.Input.getFromUser();
|
||||
const { editorVersion, customImage, projectPath, customParameters, testMode, coverageOptions, artifactsPath, useHostNetwork, sshAgent, gitPrivateToken, githubToken, checkName, packageMode, packageName, chownFilesTo, unityLicensingServer, } = model_1.Input.getFromUser();
|
||||
const baseImage = new model_1.ImageTag({ editorVersion, customImage });
|
||||
const runnerContext = model_1.Action.runnerContext();
|
||||
try {
|
||||
@@ -112,6 +112,8 @@ function run() {
|
||||
artifactsPath,
|
||||
useHostNetwork,
|
||||
sshAgent,
|
||||
packageMode,
|
||||
packageName,
|
||||
gitPrivateToken,
|
||||
githubToken,
|
||||
chownFilesTo,
|
||||
@@ -260,7 +262,7 @@ const Docker = {
|
||||
});
|
||||
},
|
||||
getLinuxCommand(image, parameters) {
|
||||
const { actionFolder, editorVersion, workspace, projectPath, customParameters, testMode, coverageOptions, artifactsPath, useHostNetwork, sshAgent, gitPrivateToken, githubToken, runnerTemporaryPath, chownFilesTo, unityLicensingServer, } = parameters;
|
||||
const { actionFolder, editorVersion, workspace, projectPath, customParameters, testMode, coverageOptions, artifactsPath, useHostNetwork, sshAgent, packageMode, packageName, gitPrivateToken, githubToken, runnerTemporaryPath, chownFilesTo, unityLicensingServer, } = parameters;
|
||||
const githubHome = path_1.default.join(runnerTemporaryPath, '_github_home');
|
||||
if (!(0, fs_1.existsSync)(githubHome))
|
||||
(0, fs_1.mkdirSync)(githubHome);
|
||||
@@ -286,6 +288,8 @@ const Docker = {
|
||||
--env COVERAGE_OPTIONS="${coverageOptions}" \
|
||||
--env COVERAGE_RESULTS_PATH="CodeCoverage" \
|
||||
--env ARTIFACTS_PATH="${artifactsPath}" \
|
||||
--env PACKAGE_MODE="${packageMode}" \
|
||||
--env PACKAGE_NAME="${packageName}" \
|
||||
--env GITHUB_REF \
|
||||
--env GITHUB_SHA \
|
||||
--env GITHUB_REPOSITORY \
|
||||
@@ -319,7 +323,7 @@ const Docker = {
|
||||
/bin/bash -c /entrypoint.sh`;
|
||||
},
|
||||
getWindowsCommand(image, parameters) {
|
||||
const { actionFolder, editorVersion, workspace, projectPath, customParameters, testMode, coverageOptions, artifactsPath, useHostNetwork, sshAgent, gitPrivateToken, githubToken, runnerTemporaryPath, chownFilesTo, unityLicensingServer, } = parameters;
|
||||
const { actionFolder, editorVersion, workspace, projectPath, customParameters, testMode, coverageOptions, artifactsPath, useHostNetwork, sshAgent, packageMode, packageName, gitPrivateToken, githubToken, runnerTemporaryPath, chownFilesTo, unityLicensingServer, } = parameters;
|
||||
const githubHome = path_1.default.join(runnerTemporaryPath, '_github_home');
|
||||
if (!(0, fs_1.existsSync)(githubHome))
|
||||
(0, fs_1.mkdirSync)(githubHome);
|
||||
@@ -345,6 +349,8 @@ const Docker = {
|
||||
--env COVERAGE_OPTIONS="${coverageOptions}" \
|
||||
--env COVERAGE_RESULTS_PATH="CodeCoverage" \
|
||||
--env ARTIFACTS_PATH="${artifactsPath}" \
|
||||
--env PACKAGE_MODE="${packageMode}" \
|
||||
--env PACKAGE_NAME="${packageName}" \
|
||||
--env GITHUB_REF \
|
||||
--env GITHUB_SHA \
|
||||
--env GITHUB_REPOSITORY \
|
||||
@@ -556,6 +562,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||
const unity_version_parser_1 = __importDefault(__nccwpck_require__(7049));
|
||||
const fs_1 = __importDefault(__nccwpck_require__(7147));
|
||||
const core_1 = __nccwpck_require__(2186);
|
||||
const Input = {
|
||||
get testModes() {
|
||||
@@ -565,6 +572,41 @@ const Input = {
|
||||
const validFolderName = new RegExp(/^(\.|\.\/)?(\.?[\w~]+([ _-]?[\w~]+)*\/?)*$/);
|
||||
return validFolderName.test(folderName);
|
||||
},
|
||||
/**
|
||||
* When in package mode, we need to scrape the package's name from its package.json file
|
||||
*/
|
||||
getPackageNameFromPackageJson(packagePath) {
|
||||
const packageJsonPath = `${packagePath}/package.json`;
|
||||
if (!fs_1.default.existsSync(packageJsonPath)) {
|
||||
throw new Error(`Invalid projectPath - Cannot find package.json at ${packageJsonPath}`);
|
||||
}
|
||||
let packageJson;
|
||||
try {
|
||||
packageJson = JSON.parse(fs_1.default.readFileSync(packageJsonPath).toString());
|
||||
}
|
||||
catch (error) {
|
||||
if (error instanceof SyntaxError) {
|
||||
throw new SyntaxError(`Unable to parse package.json contents as JSON - ${error.message}`);
|
||||
}
|
||||
throw new Error(`Unable to parse package.json contents as JSON - unknown error ocurred`);
|
||||
}
|
||||
const rawPackageName = packageJson.name;
|
||||
if (typeof rawPackageName !== 'string') {
|
||||
throw new TypeError(`Unable to parse package name from package.json - package name should be string, but was ${typeof rawPackageName}`);
|
||||
}
|
||||
if (rawPackageName.length === 0) {
|
||||
throw new Error(`Package name from package.json is a string, but is empty`);
|
||||
}
|
||||
return rawPackageName;
|
||||
},
|
||||
/**
|
||||
* When in package mode, we need to ensure that the Tests folder is present
|
||||
*/
|
||||
verifyTestsFolderIsPresent(packagePath) {
|
||||
if (!fs_1.default.existsSync(`${packagePath}/Tests`)) {
|
||||
throw new Error(`Invalid projectPath - Cannot find package tests folder at ${packagePath}/Tests`);
|
||||
}
|
||||
},
|
||||
getFromUser() {
|
||||
// Input variables specified in workflow using "with" prop.
|
||||
const unityVersion = (0, core_1.getInput)('unityVersion') || 'auto';
|
||||
@@ -580,6 +622,8 @@ const Input = {
|
||||
const gitPrivateToken = (0, core_1.getInput)('gitPrivateToken') || '';
|
||||
const githubToken = (0, core_1.getInput)('githubToken') || '';
|
||||
const checkName = (0, core_1.getInput)('checkName') || 'Test Results';
|
||||
const rawPackageMode = (0, core_1.getInput)('packageMode') || 'false';
|
||||
let packageName = '';
|
||||
const chownFilesTo = (0, core_1.getInput)('chownFilesTo') || '';
|
||||
// Validate input
|
||||
if (!this.testModes.includes(testMode)) {
|
||||
@@ -594,8 +638,22 @@ const Input = {
|
||||
if (rawUseHostNetwork !== 'true' && rawUseHostNetwork !== 'false') {
|
||||
throw new Error(`Invalid useHostNetwork "${rawUseHostNetwork}"`);
|
||||
}
|
||||
// Sanitise input
|
||||
if (rawPackageMode !== 'true' && rawPackageMode !== 'false') {
|
||||
throw new Error(`Invalid packageMode "${rawPackageMode}"`);
|
||||
}
|
||||
// sanitize packageMode input and projectPath input since they are needed
|
||||
// for input validation
|
||||
const packageMode = rawPackageMode === 'true';
|
||||
const projectPath = rawProjectPath.replace(/\/$/, '');
|
||||
// if in package mode, attempt to get the package's name, and ensure tests are present
|
||||
if (packageMode) {
|
||||
if (unityVersion === 'auto') {
|
||||
throw new Error('Package Mode is enabled, but unityVersion is set to "auto". unityVersion must manually be set in Package Mode.');
|
||||
}
|
||||
packageName = this.getPackageNameFromPackageJson(projectPath);
|
||||
this.verifyTestsFolderIsPresent(projectPath);
|
||||
}
|
||||
// Sanitise other input
|
||||
const artifactsPath = rawArtifactsPath.replace(/\/$/, '');
|
||||
const useHostNetwork = rawUseHostNetwork === 'true';
|
||||
const editorVersion = unityVersion === 'auto' ? unity_version_parser_1.default.read(projectPath) : unityVersion;
|
||||
@@ -613,6 +671,8 @@ const Input = {
|
||||
gitPrivateToken,
|
||||
githubToken,
|
||||
checkName,
|
||||
packageMode,
|
||||
packageName,
|
||||
chownFilesTo,
|
||||
unityLicensingServer,
|
||||
};
|
||||
|
||||
2
dist/index.js.map
generated
vendored
2
dist/index.js.map
generated
vendored
File diff suppressed because one or more lines are too long
70
dist/steps/run_tests.sh
vendored
70
dist/steps/run_tests.sh
vendored
@@ -36,6 +36,76 @@ echo "Using custom parameters $CUSTOM_PARAMETERS."
|
||||
|
||||
echo "Using Unity version \"$UNITY_VERSION\" to test."
|
||||
|
||||
#
|
||||
# Create an empty project for testing if in package mode
|
||||
#
|
||||
|
||||
if [ "$PACKAGE_MODE" = "true" ]; then
|
||||
echo "Running tests on a Unity package rather than a Unity project."
|
||||
|
||||
if ! command -v jq &> /dev/null
|
||||
then
|
||||
echo "jq could not be found. This is required for package mode, and is likely the result of using a custom Docker image. Please use the default image or install jq to your custom image."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "###########################"
|
||||
echo "# Package Folder #"
|
||||
echo "###########################"
|
||||
echo ""
|
||||
|
||||
ls -la "$UNITY_PROJECT_PATH"
|
||||
echo ""
|
||||
|
||||
echo "Creating an empty Unity project to add the package $PACKAGE_NAME to."
|
||||
|
||||
TEMP_PROJECT_PATH="./TempProject"
|
||||
|
||||
unity-editor \
|
||||
-batchmode \
|
||||
-createProject "$TEMP_PROJECT_PATH" \
|
||||
-quit
|
||||
|
||||
# use jq to add the package to the temp project through manually modifying Packages/manifest.json
|
||||
echo "Adding package to the temporary project's dependencies and testables..."
|
||||
echo ""
|
||||
|
||||
PACKAGE_MANIFEST_PATH="$TEMP_PROJECT_PATH/Packages/manifest.json"
|
||||
if [ ! -f "$PACKAGE_MANIFEST_PATH" ]; then
|
||||
echo "Packages/mainfest.json was not created properly. This indicates a problem with the Action, not with your package. Logging directories and aborting..."
|
||||
|
||||
echo ""
|
||||
echo "###########################"
|
||||
echo "# Temp Project Folder #"
|
||||
echo "###########################"
|
||||
echo ""
|
||||
|
||||
ls -a "$TEMP_PROJECT_PATH"
|
||||
|
||||
echo ""
|
||||
echo "################################"
|
||||
echo "# Temp Project Packages Folder #"
|
||||
echo "################################"
|
||||
echo ""
|
||||
|
||||
ls -a "$TEMP_PROJECT_PATH/Packages"
|
||||
|
||||
exit 1
|
||||
fi
|
||||
|
||||
PACKAGE_MANIFEST_JSON=$(cat "$PACKAGE_MANIFEST_PATH")
|
||||
echo "$PACKAGE_MANIFEST_JSON" | \
|
||||
jq \
|
||||
--arg packageName "$PACKAGE_NAME" \
|
||||
--arg projectPath "$UNITY_PROJECT_PATH" \
|
||||
'.dependencies += {"com.unity.testtools.codecoverage": "1.1.1"} | .dependencies += {"\($packageName)": "file:\($projectPath)"} | . += {testables: ["\($packageName)"]}' \
|
||||
> "$PACKAGE_MANIFEST_PATH"
|
||||
|
||||
UNITY_PROJECT_PATH="$TEMP_PROJECT_PATH"
|
||||
fi
|
||||
|
||||
|
||||
#
|
||||
# Overall info
|
||||
#
|
||||
|
||||
Reference in New Issue
Block a user