mirror of
https://github.com/game-ci/unity-test-runner.git
synced 2026-01-29 14:39:33 +08:00
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c80d9094f5 | ||
|
|
8bb2cdbd2c | ||
|
|
7b6d529621 | ||
|
|
cf54cef2d1 | ||
|
|
ca5119b29e | ||
|
|
275df9854c |
28
.github/workflows/main.yml
vendored
28
.github/workflows/main.yml
vendored
@@ -13,8 +13,8 @@ jobs:
|
||||
name: Tests
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/setup-node@v3
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: 18.x
|
||||
- run: yarn
|
||||
@@ -42,7 +42,7 @@ jobs:
|
||||
# Checkout #
|
||||
###########################
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
lfs: true
|
||||
|
||||
@@ -83,7 +83,7 @@ jobs:
|
||||
###########################
|
||||
# Checkout #
|
||||
###########################
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
lfs: true
|
||||
|
||||
@@ -139,7 +139,7 @@ jobs:
|
||||
###########################
|
||||
# Checkout #
|
||||
###########################
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
lfs: true
|
||||
|
||||
@@ -194,7 +194,7 @@ jobs:
|
||||
###########################
|
||||
# Checkout #
|
||||
###########################
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
lfs: true
|
||||
|
||||
@@ -249,7 +249,7 @@ jobs:
|
||||
###########################
|
||||
# Checkout #
|
||||
###########################
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
lfs: true
|
||||
|
||||
@@ -296,7 +296,7 @@ jobs:
|
||||
###########################
|
||||
# Checkout #
|
||||
###########################
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
lfs: true
|
||||
|
||||
@@ -350,7 +350,7 @@ jobs:
|
||||
###########################
|
||||
# Checkout #
|
||||
###########################
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
lfs: true
|
||||
|
||||
@@ -419,7 +419,7 @@ jobs:
|
||||
# Checkout #
|
||||
###########################
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
lfs: true
|
||||
|
||||
@@ -453,7 +453,7 @@ jobs:
|
||||
###########################
|
||||
# Checkout #
|
||||
###########################
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
lfs: true
|
||||
|
||||
@@ -499,7 +499,7 @@ jobs:
|
||||
###########################
|
||||
# Checkout #
|
||||
###########################
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
lfs: true
|
||||
|
||||
@@ -545,7 +545,7 @@ jobs:
|
||||
###########################
|
||||
# Checkout #
|
||||
###########################
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
lfs: true
|
||||
|
||||
@@ -591,7 +591,7 @@ jobs:
|
||||
###########################
|
||||
# Checkout #
|
||||
###########################
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
lfs: true
|
||||
|
||||
|
||||
22
action.yml
22
action.yml
@@ -36,6 +36,10 @@ inputs:
|
||||
required: false
|
||||
default: ''
|
||||
description: 'SSH Agent path to forward to the container.'
|
||||
sshPublicKeysDirectoryPath:
|
||||
required: false
|
||||
default: ''
|
||||
description: 'Path to a directory containing SSH public keys to forward to the container.'
|
||||
gitPrivateToken:
|
||||
required: false
|
||||
default: ''
|
||||
@@ -56,6 +60,24 @@ inputs:
|
||||
required: false
|
||||
default: ''
|
||||
description: 'User and optionally group (user or user:group or uid:gid) to give ownership of the resulting build artifacts'
|
||||
dockerCpuLimit:
|
||||
required: false
|
||||
default: ''
|
||||
description: 'Number of CPU cores to assign the docker container. Defaults to all available cores on all platforms.'
|
||||
dockerMemoryLimit:
|
||||
required: false
|
||||
default: ''
|
||||
description:
|
||||
'Amount of memory to assign the docker container. Defaults to 95% of total system memory rounded down to the
|
||||
nearest megabyte on Linux and 80% on Windows. On unrecognized platforms, defaults to 75% of total system memory.
|
||||
To manually specify a value, use the format <number><unit>, where unit is either m or g. ie: 512m = 512 megabytes'
|
||||
dockerIsolationMode:
|
||||
required: false
|
||||
default: 'default'
|
||||
description:
|
||||
'Isolation mode to use for the docker container. Can be one of process, hyperv, or default. Default will pick the
|
||||
default mode as described by Microsoft where server versions use process and desktop versions use hyperv. Only
|
||||
applicable on Windows'
|
||||
unityLicensingServer:
|
||||
required: false
|
||||
default: ''
|
||||
|
||||
1
dist/entrypoint.sh
vendored
1
dist/entrypoint.sh
vendored
@@ -12,6 +12,7 @@ mkdir -p "$ACTIVATE_LICENSE_PATH"
|
||||
#
|
||||
|
||||
source /steps/activate.sh
|
||||
source /steps/set_extra_git_configs.sh
|
||||
source /steps/set_gitcredential.sh
|
||||
source /steps/run_tests.sh
|
||||
source /steps/return_license.sh
|
||||
|
||||
59
dist/index.js
generated
vendored
59
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, packageMode, packageName, chownFilesTo, unityLicensingServer, } = model_1.Input.getFromUser();
|
||||
const { editorVersion, customImage, projectPath, customParameters, testMode, coverageOptions, artifactsPath, useHostNetwork, sshAgent, sshPublicKeysDirectoryPath, gitPrivateToken, githubToken, checkName, packageMode, packageName, chownFilesTo, dockerCpuLimit, dockerMemoryLimit, dockerIsolationMode, unityLicensingServer, } = model_1.Input.getFromUser();
|
||||
const baseImage = new model_1.ImageTag({ editorVersion, customImage });
|
||||
const runnerContext = model_1.Action.runnerContext();
|
||||
try {
|
||||
@@ -112,11 +112,15 @@ function run() {
|
||||
artifactsPath,
|
||||
useHostNetwork,
|
||||
sshAgent,
|
||||
sshPublicKeysDirectoryPath,
|
||||
packageMode,
|
||||
packageName,
|
||||
gitPrivateToken,
|
||||
githubToken,
|
||||
chownFilesTo,
|
||||
dockerCpuLimit,
|
||||
dockerMemoryLimit,
|
||||
dockerIsolationMode,
|
||||
unityLicensingServer }, runnerContext));
|
||||
}
|
||||
finally {
|
||||
@@ -262,7 +266,7 @@ const Docker = {
|
||||
});
|
||||
},
|
||||
getLinuxCommand(image, parameters) {
|
||||
const { actionFolder, editorVersion, workspace, projectPath, customParameters, testMode, coverageOptions, artifactsPath, useHostNetwork, sshAgent, packageMode, packageName, gitPrivateToken, githubToken, runnerTemporaryPath, chownFilesTo, unityLicensingServer, } = parameters;
|
||||
const { actionFolder, editorVersion, workspace, projectPath, customParameters, testMode, coverageOptions, artifactsPath, useHostNetwork, sshAgent, sshPublicKeysDirectoryPath, packageMode, packageName, gitPrivateToken, githubToken, runnerTemporaryPath, chownFilesTo, dockerCpuLimit, dockerMemoryLimit, unityLicensingServer, } = parameters;
|
||||
const githubHome = path_1.default.join(runnerTemporaryPath, '_github_home');
|
||||
if (!(0, fs_1.existsSync)(githubHome))
|
||||
(0, fs_1.mkdirSync)(githubHome);
|
||||
@@ -307,6 +311,7 @@ const Docker = {
|
||||
--env RUNNER_WORKSPACE \
|
||||
--env GIT_PRIVATE_TOKEN="${gitPrivateToken}" \
|
||||
--env CHOWN_FILES_TO="${chownFilesTo}" \
|
||||
--env GIT_CONFIG_EXTENSIONS \
|
||||
${sshAgent ? '--env SSH_AUTH_SOCK=/ssh-agent' : ''} \
|
||||
--volume "${githubHome}:/root:z" \
|
||||
--volume "${githubWorkflow}:/github/workflow:z" \
|
||||
@@ -315,15 +320,22 @@ const Docker = {
|
||||
--volume "${actionFolder}/steps:/steps:z" \
|
||||
--volume "${actionFolder}/entrypoint.sh:/entrypoint.sh:z" \
|
||||
--volume "${actionFolder}/unity-config:/usr/share/unity3d/config/:z" \
|
||||
--cpus=${dockerCpuLimit} \
|
||||
--memory=${dockerMemoryLimit} \
|
||||
${sshAgent ? `--volume ${sshAgent}:/ssh-agent` : ''} \
|
||||
${sshAgent ? `--volume /home/runner/.ssh/known_hosts:/root/.ssh/known_hosts:ro` : ''} \
|
||||
${sshAgent && !sshPublicKeysDirectoryPath
|
||||
? `--volume /home/runner/.ssh/known_hosts:/root/.ssh/known_hosts:ro`
|
||||
: ''} \
|
||||
${sshPublicKeysDirectoryPath
|
||||
? `--volume ${sshPublicKeysDirectoryPath}:/root/.ssh:ro`
|
||||
: ''} \
|
||||
${useHostNetwork ? '--net=host' : ''} \
|
||||
${githubToken ? '--env USE_EXIT_CODE=false' : '--env USE_EXIT_CODE=true'} \
|
||||
${image} \
|
||||
/bin/bash -c /entrypoint.sh`;
|
||||
},
|
||||
getWindowsCommand(image, parameters) {
|
||||
const { actionFolder, editorVersion, workspace, projectPath, customParameters, testMode, coverageOptions, artifactsPath, useHostNetwork, sshAgent, packageMode, packageName, gitPrivateToken, githubToken, runnerTemporaryPath, chownFilesTo, unityLicensingServer, } = parameters;
|
||||
const { actionFolder, editorVersion, workspace, projectPath, customParameters, testMode, coverageOptions, artifactsPath, useHostNetwork, sshAgent, packageMode, packageName, gitPrivateToken, githubToken, runnerTemporaryPath, chownFilesTo, dockerCpuLimit, dockerMemoryLimit, dockerIsolationMode, unityLicensingServer, } = parameters;
|
||||
const githubHome = path_1.default.join(runnerTemporaryPath, '_github_home');
|
||||
if (!(0, fs_1.existsSync)(githubHome))
|
||||
(0, fs_1.mkdirSync)(githubHome);
|
||||
@@ -379,6 +391,9 @@ const Docker = {
|
||||
${sshAgent
|
||||
? `--volume c:/Users/Administrator/.ssh/known_hosts:c:/root/.ssh/known_hosts`
|
||||
: ''} \
|
||||
--cpus=${dockerCpuLimit} \
|
||||
--memory=${dockerMemoryLimit} \
|
||||
--isolation=${dockerIsolationMode} \
|
||||
${useHostNetwork ? '--net=host' : ''} \
|
||||
${githubToken ? '--env USE_EXIT_CODE=false' : '--env USE_EXIT_CODE=true'} \
|
||||
${image} \
|
||||
@@ -415,7 +430,7 @@ class ImageTag {
|
||||
this.targetPlatform = targetPlatform;
|
||||
this.targetPlatformSuffix = ImageTag.getTargetPlatformSuffix(targetPlatform, editorVersion);
|
||||
this.imagePlatformPrefix = ImageTag.getImagePlatformPrefix(process.platform);
|
||||
this.imageRollingVersion = 2;
|
||||
this.imageRollingVersion = 3;
|
||||
}
|
||||
static get versionPattern() {
|
||||
return /^20\d{2}\.\d\.\w{3,4}|3$/;
|
||||
@@ -564,6 +579,7 @@ 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 os_1 = __importDefault(__nccwpck_require__(2037));
|
||||
const Input = {
|
||||
get testModes() {
|
||||
return ['all', 'playmode', 'editmode', 'standalone'];
|
||||
@@ -572,6 +588,10 @@ const Input = {
|
||||
const validFolderName = new RegExp(/^(\.|\.\/)?(\.?[\w~]+([ _-]?[\w~]+)*\/?)*$/);
|
||||
return validFolderName.test(folderName);
|
||||
},
|
||||
isValidGlobalFolderName(folderName) {
|
||||
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
|
||||
*/
|
||||
@@ -619,12 +639,30 @@ const Input = {
|
||||
const rawArtifactsPath = (0, core_1.getInput)('artifactsPath') || 'artifacts';
|
||||
const rawUseHostNetwork = (0, core_1.getInput)('useHostNetwork') || 'false';
|
||||
const sshAgent = (0, core_1.getInput)('sshAgent') || '';
|
||||
const rawSshPublicKeysDirectoryPath = (0, core_1.getInput)('sshPublicKeysDirectoryPath') || '';
|
||||
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') || '';
|
||||
const dockerCpuLimit = (0, core_1.getInput)('dockerCpuLimit') || os_1.default.cpus().length.toString();
|
||||
const bytesInMegabyte = 1024 * 1024;
|
||||
let memoryMultiplier;
|
||||
switch (os_1.default.platform()) {
|
||||
case 'linux':
|
||||
memoryMultiplier = 0.95;
|
||||
break;
|
||||
case 'win32':
|
||||
memoryMultiplier = 0.8;
|
||||
break;
|
||||
default:
|
||||
memoryMultiplier = 0.75;
|
||||
break;
|
||||
}
|
||||
const dockerMemoryLimit = (0, core_1.getInput)('dockerMemoryLimit') ||
|
||||
`${Math.floor((os_1.default.totalmem() / bytesInMegabyte) * memoryMultiplier)}m`;
|
||||
const dockerIsolationMode = (0, core_1.getInput)('dockerIsolationMode') || 'default';
|
||||
// Validate input
|
||||
if (!this.testModes.includes(testMode)) {
|
||||
throw new Error(`Invalid testMode ${testMode}`);
|
||||
@@ -635,12 +673,18 @@ const Input = {
|
||||
if (!this.isValidFolderName(rawArtifactsPath)) {
|
||||
throw new Error(`Invalid artifactsPath "${rawArtifactsPath}"`);
|
||||
}
|
||||
if (!this.isValidGlobalFolderName(rawSshPublicKeysDirectoryPath)) {
|
||||
throw new Error(`Invalid sshPublicKeysDirectoryPath "${rawSshPublicKeysDirectoryPath}"`);
|
||||
}
|
||||
if (rawUseHostNetwork !== 'true' && rawUseHostNetwork !== 'false') {
|
||||
throw new Error(`Invalid useHostNetwork "${rawUseHostNetwork}"`);
|
||||
}
|
||||
if (rawPackageMode !== 'true' && rawPackageMode !== 'false') {
|
||||
throw new Error(`Invalid packageMode "${rawPackageMode}"`);
|
||||
}
|
||||
if (rawSshPublicKeysDirectoryPath !== '' && sshAgent === '') {
|
||||
throw new Error('sshPublicKeysDirectoryPath is set, but sshAgent is not set. sshPublicKeysDirectoryPath is useful only when using sshAgent.');
|
||||
}
|
||||
// sanitize packageMode input and projectPath input since they are needed
|
||||
// for input validation
|
||||
const packageMode = rawPackageMode === 'true';
|
||||
@@ -655,6 +699,7 @@ const Input = {
|
||||
}
|
||||
// Sanitise other input
|
||||
const artifactsPath = rawArtifactsPath.replace(/\/$/, '');
|
||||
const sshPublicKeysDirectoryPath = rawSshPublicKeysDirectoryPath.replace(/\/$/, '');
|
||||
const useHostNetwork = rawUseHostNetwork === 'true';
|
||||
const editorVersion = unityVersion === 'auto' ? unity_version_parser_1.default.read(projectPath) : unityVersion;
|
||||
// Return sanitised input
|
||||
@@ -668,12 +713,16 @@ const Input = {
|
||||
artifactsPath,
|
||||
useHostNetwork,
|
||||
sshAgent,
|
||||
sshPublicKeysDirectoryPath,
|
||||
gitPrivateToken,
|
||||
githubToken,
|
||||
checkName,
|
||||
packageMode,
|
||||
packageName,
|
||||
chownFilesTo,
|
||||
dockerCpuLimit,
|
||||
dockerMemoryLimit,
|
||||
dockerIsolationMode,
|
||||
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
2
dist/steps/run_tests.ps1
vendored
2
dist/steps/run_tests.ps1
vendored
@@ -51,7 +51,7 @@ Write-Output "###########################"
|
||||
Write-Output "# Project directory #"
|
||||
Write-Output "###########################"
|
||||
Write-Output ""
|
||||
Get-ChildItem -Hidden -Path $UNITY_PROJECT_PATH
|
||||
Get-ChildItem -Hidden -Path "$UNITY_PROJECT_PATH"
|
||||
|
||||
#
|
||||
# Testing for each platform
|
||||
|
||||
2
dist/steps/run_tests.sh
vendored
2
dist/steps/run_tests.sh
vendored
@@ -123,7 +123,7 @@ echo "###########################"
|
||||
echo "# Project directory #"
|
||||
echo "###########################"
|
||||
echo ""
|
||||
ls -alh $UNITY_PROJECT_PATH
|
||||
ls -alh "$UNITY_PROJECT_PATH"
|
||||
|
||||
#
|
||||
# Testing for each platform
|
||||
|
||||
29
dist/steps/set_extra_git_configs.sh
vendored
Normal file
29
dist/steps/set_extra_git_configs.sh
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
if [ -z "${GIT_CONFIG_EXTENSIONS}" ]
|
||||
then
|
||||
echo "GIT_CONFIG_EXTENSIONS unset skipping"
|
||||
else
|
||||
echo "GIT_CONFIG_EXTENSIONS is set. configuring extra git configs"
|
||||
|
||||
IFS=$'\n'
|
||||
for config in $(echo "${GIT_CONFIG_EXTENSIONS}" | sed 's/\(.*\)=\(.*\)/"\1" "\2"/g'); do
|
||||
if [[ $config =~ \"([^\"]+)\"\ \"([^\"]+)\" ]]; then
|
||||
key="${BASH_REMATCH[1]}"
|
||||
value="${BASH_REMATCH[2]}"
|
||||
else
|
||||
echo "Error parsing config: $config"
|
||||
exit 1
|
||||
fi
|
||||
echo "Adding extra git config: \"$key\" = \"$value\""
|
||||
git config --global --add "$key" "$value"
|
||||
done
|
||||
unset IFS
|
||||
|
||||
fi
|
||||
|
||||
echo "---------- git config --list -------------"
|
||||
git config --list
|
||||
|
||||
echo "---------- git config --list --show-origin -------------"
|
||||
git config --list --show-origin
|
||||
@@ -8,4 +8,6 @@ module.exports = {
|
||||
'^.+\\.ts$': 'ts-jest',
|
||||
},
|
||||
verbose: true,
|
||||
modulePathIgnorePatterns: ['<rootDir>/lib/', '<rootDir>/dist/'],
|
||||
setupFilesAfterEnv: ['<rootDir>/src/jest.setup.ts'],
|
||||
};
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "unity-test-runner",
|
||||
"version": "2.0.0",
|
||||
"version": "3.0.0",
|
||||
"description": "Run tests for any Unity project.",
|
||||
"main": "dist/index.js",
|
||||
"repository": "git@github.com:game-ci/unity-test-runner.git",
|
||||
@@ -24,7 +24,7 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/jest": "^26.0.15",
|
||||
"@types/node": "^14.14.9",
|
||||
"@types/node": "^20.8.10",
|
||||
"@types/semver": "^7.3.5",
|
||||
"@typescript-eslint/parser": "^5.9.0",
|
||||
"@vercel/ncc": "^0.33.1",
|
||||
@@ -37,11 +37,14 @@
|
||||
"husky": "^7.0.4",
|
||||
"jest": "^26.6.3",
|
||||
"jest-circus": "^26.6.3",
|
||||
"jest-fail-on-console": "^3.0.2",
|
||||
"js-yaml": "^3.14.0",
|
||||
"lint-staged": "^12.1.2",
|
||||
"prettier": "^2.2.1",
|
||||
"ts-jest": "^26.4.4",
|
||||
"typescript": "^4.1.5"
|
||||
"ts-node": "10.4.0",
|
||||
"typescript": "^4.1.5",
|
||||
"yarn-audit-fix": "^9.3.8"
|
||||
},
|
||||
"lint-staged": {
|
||||
"*.{js,jsx,ts,tsx}": [
|
||||
|
||||
9
src/jest.setup.ts
Normal file
9
src/jest.setup.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import failOnConsole from 'jest-fail-on-console';
|
||||
|
||||
// Fail when console logs something inside a test - use spyOn instead
|
||||
failOnConsole({
|
||||
shouldFailOnWarn: true,
|
||||
shouldFailOnError: true,
|
||||
shouldFailOnLog: true,
|
||||
shouldFailOnAssert: true,
|
||||
});
|
||||
@@ -16,12 +16,16 @@ export async function run() {
|
||||
artifactsPath,
|
||||
useHostNetwork,
|
||||
sshAgent,
|
||||
sshPublicKeysDirectoryPath,
|
||||
gitPrivateToken,
|
||||
githubToken,
|
||||
checkName,
|
||||
packageMode,
|
||||
packageName,
|
||||
chownFilesTo,
|
||||
dockerCpuLimit,
|
||||
dockerMemoryLimit,
|
||||
dockerIsolationMode,
|
||||
unityLicensingServer,
|
||||
} = Input.getFromUser();
|
||||
const baseImage = new ImageTag({ editorVersion, customImage });
|
||||
@@ -39,11 +43,15 @@ export async function run() {
|
||||
artifactsPath,
|
||||
useHostNetwork,
|
||||
sshAgent,
|
||||
sshPublicKeysDirectoryPath,
|
||||
packageMode,
|
||||
packageName,
|
||||
gitPrivateToken,
|
||||
githubToken,
|
||||
chownFilesTo,
|
||||
dockerCpuLimit,
|
||||
dockerMemoryLimit,
|
||||
dockerIsolationMode,
|
||||
unityLicensingServer,
|
||||
...runnerContext,
|
||||
});
|
||||
|
||||
@@ -62,12 +62,15 @@ const Docker = {
|
||||
artifactsPath,
|
||||
useHostNetwork,
|
||||
sshAgent,
|
||||
sshPublicKeysDirectoryPath,
|
||||
packageMode,
|
||||
packageName,
|
||||
gitPrivateToken,
|
||||
githubToken,
|
||||
runnerTemporaryPath,
|
||||
chownFilesTo,
|
||||
dockerCpuLimit,
|
||||
dockerMemoryLimit,
|
||||
unityLicensingServer,
|
||||
} = parameters;
|
||||
|
||||
@@ -116,6 +119,7 @@ const Docker = {
|
||||
--env RUNNER_WORKSPACE \
|
||||
--env GIT_PRIVATE_TOKEN="${gitPrivateToken}" \
|
||||
--env CHOWN_FILES_TO="${chownFilesTo}" \
|
||||
--env GIT_CONFIG_EXTENSIONS \
|
||||
${sshAgent ? '--env SSH_AUTH_SOCK=/ssh-agent' : ''} \
|
||||
--volume "${githubHome}:/root:z" \
|
||||
--volume "${githubWorkflow}:/github/workflow:z" \
|
||||
@@ -124,9 +128,18 @@ const Docker = {
|
||||
--volume "${actionFolder}/steps:/steps:z" \
|
||||
--volume "${actionFolder}/entrypoint.sh:/entrypoint.sh:z" \
|
||||
--volume "${actionFolder}/unity-config:/usr/share/unity3d/config/:z" \
|
||||
--cpus=${dockerCpuLimit} \
|
||||
--memory=${dockerMemoryLimit} \
|
||||
${sshAgent ? `--volume ${sshAgent}:/ssh-agent` : ''} \
|
||||
${
|
||||
sshAgent ? `--volume /home/runner/.ssh/known_hosts:/root/.ssh/known_hosts:ro` : ''
|
||||
sshAgent && !sshPublicKeysDirectoryPath
|
||||
? `--volume /home/runner/.ssh/known_hosts:/root/.ssh/known_hosts:ro`
|
||||
: ''
|
||||
} \
|
||||
${
|
||||
sshPublicKeysDirectoryPath
|
||||
? `--volume ${sshPublicKeysDirectoryPath}:/root/.ssh:ro`
|
||||
: ''
|
||||
} \
|
||||
${useHostNetwork ? '--net=host' : ''} \
|
||||
${githubToken ? '--env USE_EXIT_CODE=false' : '--env USE_EXIT_CODE=true'} \
|
||||
@@ -152,6 +165,9 @@ const Docker = {
|
||||
githubToken,
|
||||
runnerTemporaryPath,
|
||||
chownFilesTo,
|
||||
dockerCpuLimit,
|
||||
dockerMemoryLimit,
|
||||
dockerIsolationMode,
|
||||
unityLicensingServer,
|
||||
} = parameters;
|
||||
|
||||
@@ -213,6 +229,9 @@ const Docker = {
|
||||
? `--volume c:/Users/Administrator/.ssh/known_hosts:c:/root/.ssh/known_hosts`
|
||||
: ''
|
||||
} \
|
||||
--cpus=${dockerCpuLimit} \
|
||||
--memory=${dockerMemoryLimit} \
|
||||
--isolation=${dockerIsolationMode} \
|
||||
${useHostNetwork ? '--net=host' : ''} \
|
||||
${githubToken ? '--env USE_EXIT_CODE=false' : '--env USE_EXIT_CODE=true'} \
|
||||
${image} \
|
||||
|
||||
@@ -50,7 +50,7 @@ describe('ImageTag', () => {
|
||||
targetPlatform: some.targetPlatform,
|
||||
});
|
||||
|
||||
expect(image.toString()).toStrictEqual(`${defaults.image}:ubuntu-2099.1.1111-2`);
|
||||
expect(image.toString()).toStrictEqual(`${defaults.image}:ubuntu-2099.1.1111-3`);
|
||||
});
|
||||
it('returns customImage if given', () => {
|
||||
const image = new ImageTag({
|
||||
@@ -65,13 +65,13 @@ describe('ImageTag', () => {
|
||||
it('returns the specific build platform', () => {
|
||||
const image = new ImageTag({ editorVersion: '2022.3.7f1', targetPlatform: 'WebGL' });
|
||||
|
||||
expect(image.toString()).toStrictEqual(`${defaults.image}:ubuntu-2022.3.7f1-webgl-2`);
|
||||
expect(image.toString()).toStrictEqual(`${defaults.image}:ubuntu-2022.3.7f1-webgl-3`);
|
||||
});
|
||||
|
||||
it('returns no specific build platform for generic targetPlatforms', () => {
|
||||
const image = new ImageTag({ targetPlatform: 'NoTarget' });
|
||||
|
||||
expect(image.toString()).toStrictEqual(`${defaults.image}:ubuntu-2022.3.7f1-2`);
|
||||
expect(image.toString()).toStrictEqual(`${defaults.image}:ubuntu-2022.3.7f1-3`);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -31,7 +31,7 @@ class ImageTag {
|
||||
this.targetPlatform = targetPlatform;
|
||||
this.targetPlatformSuffix = ImageTag.getTargetPlatformSuffix(targetPlatform, editorVersion);
|
||||
this.imagePlatformPrefix = ImageTag.getImagePlatformPrefix(process.platform);
|
||||
this.imageRollingVersion = 2;
|
||||
this.imageRollingVersion = 3;
|
||||
}
|
||||
|
||||
static get versionPattern() {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import UnityVersionParser from './unity-version-parser';
|
||||
import fs from 'fs';
|
||||
import { getInput } from '@actions/core';
|
||||
import os from 'os';
|
||||
|
||||
const Input = {
|
||||
get testModes() {
|
||||
@@ -13,6 +14,12 @@ const Input = {
|
||||
return validFolderName.test(folderName);
|
||||
},
|
||||
|
||||
isValidGlobalFolderName(folderName) {
|
||||
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
|
||||
*/
|
||||
@@ -72,12 +79,31 @@ const Input = {
|
||||
const rawArtifactsPath = getInput('artifactsPath') || 'artifacts';
|
||||
const rawUseHostNetwork = getInput('useHostNetwork') || 'false';
|
||||
const sshAgent = getInput('sshAgent') || '';
|
||||
const rawSshPublicKeysDirectoryPath = getInput('sshPublicKeysDirectoryPath') || '';
|
||||
const gitPrivateToken = getInput('gitPrivateToken') || '';
|
||||
const githubToken = getInput('githubToken') || '';
|
||||
const checkName = getInput('checkName') || 'Test Results';
|
||||
const rawPackageMode = getInput('packageMode') || 'false';
|
||||
let packageName = '';
|
||||
const chownFilesTo = getInput('chownFilesTo') || '';
|
||||
const dockerCpuLimit = getInput('dockerCpuLimit') || os.cpus().length.toString();
|
||||
const bytesInMegabyte = 1024 * 1024;
|
||||
let memoryMultiplier;
|
||||
switch (os.platform()) {
|
||||
case 'linux':
|
||||
memoryMultiplier = 0.95;
|
||||
break;
|
||||
case 'win32':
|
||||
memoryMultiplier = 0.8;
|
||||
break;
|
||||
default:
|
||||
memoryMultiplier = 0.75;
|
||||
break;
|
||||
}
|
||||
const dockerMemoryLimit =
|
||||
getInput('dockerMemoryLimit') ||
|
||||
`${Math.floor((os.totalmem() / bytesInMegabyte) * memoryMultiplier)}m`;
|
||||
const dockerIsolationMode = getInput('dockerIsolationMode') || 'default';
|
||||
|
||||
// Validate input
|
||||
if (!this.testModes.includes(testMode)) {
|
||||
@@ -92,6 +118,10 @@ const Input = {
|
||||
throw new Error(`Invalid artifactsPath "${rawArtifactsPath}"`);
|
||||
}
|
||||
|
||||
if (!this.isValidGlobalFolderName(rawSshPublicKeysDirectoryPath)) {
|
||||
throw new Error(`Invalid sshPublicKeysDirectoryPath "${rawSshPublicKeysDirectoryPath}"`);
|
||||
}
|
||||
|
||||
if (rawUseHostNetwork !== 'true' && rawUseHostNetwork !== 'false') {
|
||||
throw new Error(`Invalid useHostNetwork "${rawUseHostNetwork}"`);
|
||||
}
|
||||
@@ -100,6 +130,12 @@ const Input = {
|
||||
throw new Error(`Invalid packageMode "${rawPackageMode}"`);
|
||||
}
|
||||
|
||||
if (rawSshPublicKeysDirectoryPath !== '' && sshAgent === '') {
|
||||
throw new Error(
|
||||
'sshPublicKeysDirectoryPath is set, but sshAgent is not set. sshPublicKeysDirectoryPath is useful only when using sshAgent.',
|
||||
);
|
||||
}
|
||||
|
||||
// sanitize packageMode input and projectPath input since they are needed
|
||||
// for input validation
|
||||
const packageMode = rawPackageMode === 'true';
|
||||
@@ -119,6 +155,7 @@ const Input = {
|
||||
|
||||
// Sanitise other input
|
||||
const artifactsPath = rawArtifactsPath.replace(/\/$/, '');
|
||||
const sshPublicKeysDirectoryPath = rawSshPublicKeysDirectoryPath.replace(/\/$/, '');
|
||||
const useHostNetwork = rawUseHostNetwork === 'true';
|
||||
const editorVersion =
|
||||
unityVersion === 'auto' ? UnityVersionParser.read(projectPath) : unityVersion;
|
||||
@@ -134,12 +171,16 @@ const Input = {
|
||||
artifactsPath,
|
||||
useHostNetwork,
|
||||
sshAgent,
|
||||
sshPublicKeysDirectoryPath,
|
||||
gitPrivateToken,
|
||||
githubToken,
|
||||
checkName,
|
||||
packageMode,
|
||||
packageName,
|
||||
chownFilesTo,
|
||||
dockerCpuLimit,
|
||||
dockerMemoryLimit,
|
||||
dockerIsolationMode,
|
||||
unityLicensingServer,
|
||||
};
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user