Changed structure of docker.js to match new standard

pull/184/head
maishiroma 2022-05-23 09:46:24 -07:00
parent ccedbb68b5
commit 10bbe05d2e
4 changed files with 254 additions and 183 deletions

129
dist/index.js generated vendored
View File

@ -154,6 +154,21 @@ const path_1 = __importDefault(__nccwpck_require__(1017));
const Docker = {
run(image, parameters, silent = false) {
return __awaiter(this, void 0, void 0, function* () {
let runCommand = '';
switch (process.platform) {
case 'linux':
runCommand = this.getLinuxCommand(image, parameters);
break;
case 'win32':
runCommand = this.getWindowsCommand(image, parameters);
break;
default:
throw new Error(`Operation system, ${process.platform}, is not supported yet.`);
}
yield (0, exec_1.exec)(runCommand, undefined, { silent });
});
},
getLinuxCommand(image, parameters) {
const { actionFolder, editorVersion, workspace, projectPath, customParameters, testMode, coverageOptions, artifactsPath, useHostNetwork, sshAgent, gitPrivateToken, githubToken, runnerTemporaryPath, } = parameters;
const githubHome = path_1.default.join(runnerTemporaryPath, '_github_home');
if (!(0, fs_1.existsSync)(githubHome))
@ -162,44 +177,7 @@ const Docker = {
if (!(0, fs_1.existsSync)(githubWorkflow))
(0, fs_1.mkdirSync)(githubWorkflow);
const testPlatforms = (testMode === 'all' ? ['playmode', 'editmode', 'COMBINE_RESULTS'] : [testMode]).join(';');
const dockerPaths = new Map([
[
'linux',
new Map([
['shellCommand', '/bin/bash /dist/entrypoint.sh'],
['sshAgent', '/ssh-agent'],
['githubHome', '/root'],
['githubWorkflow', '/github/workflow'],
['githubWorkspace', '/github/workspace'],
['stepsPathParent', `${actionFolder}/steps`],
['stepsPathContainer', '/steps'],
['entrypointPathParent', `${actionFolder}/`],
['entrypointPathContainer', '/dist'],
['knownHostsParent', ' /home/runner/.ssh/known_hosts'],
['knownHostsContainer', '/root/.ssh/known_hosts'],
]),
],
[
'win32',
new Map([
['shellCommand', 'powershell C:\\dist\\entrypoint.ps1'],
['sshAgent', 'C:\\ssh-agent'],
['githubHome', 'C:\\root'],
['githubWorkflow', 'C:\\github\\workflow'],
['githubWorkspace', 'C:\\github\\workspace'],
['stepsPathParent', `${actionFolder}\\steps`],
['stepsPathContainer', 'C:\\steps'],
['entrypointPathParent', `${actionFolder}\\`],
['entrypointPathContainer', 'C:\\dist'],
['knownHostsParent', 'C:\\Users\\Administrator\\.ssh\\known_hosts'],
['knownHostsContainer', 'C:\\root\\.ssh\\known_hosts'],
]),
],
]);
const currentDockerPath = dockerPaths.get(process.platform);
const bindMountZ = process.platform === 'linux' ? ':z' : '';
const bindMountRO = process.platform === 'linux' ? ':ro' : '';
const command = `docker run \
return `docker run \
--workdir /github/workspace \
--rm \
--env UNITY_LICENSE \
@ -222,7 +200,7 @@ const Docker = {
--env GITHUB_HEAD_REF \
--env GITHUB_BASE_REF \
--env GITHUB_EVENT_NAME \
--env GITHUB_WORKSPACE="${currentDockerPath === null || currentDockerPath === void 0 ? void 0 : currentDockerPath.get('githubWorkspace')}" \
--env GITHUB_WORKSPACE="/github/workspace" \
--env GITHUB_ACTION \
--env GITHUB_EVENT_PATH \
--env RUNNER_OS \
@ -230,22 +208,73 @@ const Docker = {
--env RUNNER_TEMP \
--env RUNNER_WORKSPACE \
--env GIT_PRIVATE_TOKEN="${gitPrivateToken}" \
${sshAgent ? `--env SSH_AUTH_SOCK=${currentDockerPath === null || currentDockerPath === void 0 ? void 0 : currentDockerPath.get('sshAgent')}` : ''} \
--volume "${githubHome}:${currentDockerPath === null || currentDockerPath === void 0 ? void 0 : currentDockerPath.get('githubHome')}${bindMountZ}" \
--volume "${githubWorkflow}:${currentDockerPath === null || currentDockerPath === void 0 ? void 0 : currentDockerPath.get('githubWorkflow')}${bindMountZ}" \
--volume "${workspace}:${currentDockerPath === null || currentDockerPath === void 0 ? void 0 : currentDockerPath.get('githubWorkspace')}${bindMountZ}" \
--volume "${currentDockerPath === null || currentDockerPath === void 0 ? void 0 : currentDockerPath.get('stepsPathParent')}:${currentDockerPath === null || currentDockerPath === void 0 ? void 0 : currentDockerPath.get('stepsPathContainer')}${bindMountZ}" \
--volume "${currentDockerPath === null || currentDockerPath === void 0 ? void 0 : currentDockerPath.get('entrypointPathParent')}:${currentDockerPath === null || currentDockerPath === void 0 ? void 0 : currentDockerPath.get('entrypointPathContainer')}${bindMountZ}" \
${sshAgent ? `--volume ${sshAgent}:${currentDockerPath === null || currentDockerPath === void 0 ? void 0 : currentDockerPath.get('sshAgent')}` : ''} \
${sshAgent ? '--env SSH_AUTH_SOCK=/ssh-agent' : ''} \
--volume "${githubHome}:/root:z" \
--volume "${githubWorkflow}:/github/workflow:z" \
--volume "${workspace}:/github/workspace:z" \
--volume "${actionFolder}/steps:/steps:z" \
--volume "${actionFolder}/entrypoint.sh:/entrypoint.sh:z" \
${sshAgent ? `--volume ${sshAgent}:/ssh-agent` : ''} \
${sshAgent ? `--volume /home/runner/.ssh/known_hosts:/root/.ssh/known_hosts: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, gitPrivateToken, githubToken, runnerTemporaryPath, } = parameters;
const githubHome = path_1.default.join(runnerTemporaryPath, '_github_home');
if (!(0, fs_1.existsSync)(githubHome))
(0, fs_1.mkdirSync)(githubHome);
const githubWorkflow = path_1.default.join(runnerTemporaryPath, '_github_workflow');
if (!(0, fs_1.existsSync)(githubWorkflow))
(0, fs_1.mkdirSync)(githubWorkflow);
const testPlatforms = (testMode === 'all' ? ['playmode', 'editmode', 'COMBINE_RESULTS'] : [testMode]).join(';');
return `docker run \
--workdir /github/workspace \
--rm \
--env UNITY_LICENSE \
--env UNITY_LICENSE_FILE \
--env UNITY_EMAIL \
--env UNITY_PASSWORD \
--env UNITY_SERIAL \
--env UNITY_VERSION="${editorVersion}" \
--env PROJECT_PATH="${projectPath}" \
--env CUSTOM_PARAMETERS="${customParameters}" \
--env TEST_PLATFORMS="${testPlatforms}" \
--env COVERAGE_OPTIONS="${coverageOptions}" \
--env COVERAGE_RESULTS_PATH="CodeCoverage" \
--env ARTIFACTS_PATH="${artifactsPath}" \
--env GITHUB_REF \
--env GITHUB_SHA \
--env GITHUB_REPOSITORY \
--env GITHUB_ACTOR \
--env GITHUB_WORKFLOW \
--env GITHUB_HEAD_REF \
--env GITHUB_BASE_REF \
--env GITHUB_EVENT_NAME \
--env GITHUB_WORKSPACE="/github/workspace" \
--env GITHUB_ACTION \
--env GITHUB_EVENT_PATH \
--env RUNNER_OS \
--env RUNNER_TOOL_CACHE \
--env RUNNER_TEMP \
--env RUNNER_WORKSPACE \
--env GIT_PRIVATE_TOKEN="${gitPrivateToken}" \
${sshAgent ? '--env SSH_AUTH_SOCK=c:/ssh-agent' : ''} \
--volume "${githubHome}":"c:/root" \
--volume "${githubWorkflow}":"c:/github/workflow" \
--volume "${workspace}":"c:/github/workspace" \
--volume "${actionFolder}/steps":"c:/steps" \
--volume "${actionFolder}":"c:/dist" \
${sshAgent ? `--volume ${sshAgent}:c:/ssh-agent` : ''} \
${sshAgent
? `--volume ${currentDockerPath === null || currentDockerPath === void 0 ? void 0 : currentDockerPath.get('knownHostParent')}${currentDockerPath === null || currentDockerPath === void 0 ? void 0 : currentDockerPath.get('knownHostContainer')}${bindMountRO}`
? `--volume c:/Users/Administrator/.ssh/known_hosts:c:/root/.ssh/known_hosts`
: ''} \
${useHostNetwork ? '--net=host' : ''} \
${githubToken ? '--env USE_EXIT_CODE=false' : '--env USE_EXIT_CODE=true'} \
${image} \
${currentDockerPath === null || currentDockerPath === void 0 ? void 0 : currentDockerPath.get('shellCommand')}`;
yield (0, exec_1.exec)(command, undefined, { silent });
});
powershell c:/dist/entrypoint.ps1`;
},
};
exports["default"] = Docker;

2
dist/index.js.map generated vendored

File diff suppressed because one or more lines are too long

View File

@ -30,6 +30,7 @@ if ( ($null -ne ${env:UNITY_LICENSE}) -or ($null -ne ${env:UNITY_LICENSE_FILE})
}
$convert = (Get-Content -Raw $FILE_PATH) -replace "`r`n","`n"
[io.file]::WriteAllText($FILE_PATH, $convert)
Get-ChildItem -Path $FILE_PATH
# Activate license
$ACTIVATION_OUTPUT = Start-Process -NoNewWindow -Wait -PassThru "C:\Program Files\Unity\Hub\Editor\${env:UNITY_VERSION}\editor\Unity.exe" -ArgumentList "-batchmode -nographics -logFile $ACTIVATE_LICENSE_PATH\activate.log -quit -manualLicenseFile $FILE_PATH"

View File

@ -4,6 +4,21 @@ import path from 'path';
const Docker = {
async run(image, parameters, silent = false) {
let runCommand = '';
switch (process.platform) {
case 'linux':
runCommand = this.getLinuxCommand(image, parameters);
break;
case 'win32':
runCommand = this.getWindowsCommand(image, parameters);
break;
default:
throw new Error(`Operation system, ${process.platform}, is not supported yet.`);
}
await exec(runCommand, undefined, { silent });
},
getLinuxCommand(image, parameters): string {
const {
actionFolder,
editorVersion,
@ -28,45 +43,7 @@ const Docker = {
testMode === 'all' ? ['playmode', 'editmode', 'COMBINE_RESULTS'] : [testMode]
).join(';');
const dockerPaths = new Map([
[
'linux',
new Map([
['shellCommand', '/bin/bash /dist/entrypoint.sh'],
['sshAgent', '/ssh-agent'],
['githubHome', '/root'],
['githubWorkflow', '/github/workflow'],
['githubWorkspace', '/github/workspace'],
['stepsPathParent', `${actionFolder}/steps`],
['stepsPathContainer', '/steps'],
['entrypointPathParent', `${actionFolder}/`],
['entrypointPathContainer', '/dist'],
['knownHostsParent', ' /home/runner/.ssh/known_hosts'],
['knownHostsContainer', '/root/.ssh/known_hosts'],
]),
],
[
'win32',
new Map([
['shellCommand', 'powershell C:\\dist\\entrypoint.ps1'],
['sshAgent', 'C:\\ssh-agent'],
['githubHome', 'C:\\root'],
['githubWorkflow', 'C:\\github\\workflow'],
['githubWorkspace', 'C:\\github\\workspace'],
['stepsPathParent', `${actionFolder}\\steps`],
['stepsPathContainer', 'C:\\steps'],
['entrypointPathParent', `${actionFolder}\\`],
['entrypointPathContainer', 'C:\\dist'],
['knownHostsParent', 'C:\\Users\\Administrator\\.ssh\\known_hosts'],
['knownHostsContainer', 'C:\\root\\.ssh\\known_hosts'],
]),
],
]);
const currentDockerPath = dockerPaths.get(process.platform);
const bindMountZ = process.platform === 'linux' ? ':z' : '';
const bindMountRO = process.platform === 'linux' ? ':ro' : '';
const command = `docker run \
return `docker run \
--workdir /github/workspace \
--rm \
--env UNITY_LICENSE \
@ -89,7 +66,7 @@ const Docker = {
--env GITHUB_HEAD_REF \
--env GITHUB_BASE_REF \
--env GITHUB_EVENT_NAME \
--env GITHUB_WORKSPACE="${currentDockerPath?.get('githubWorkspace')}" \
--env GITHUB_WORKSPACE="/github/workspace" \
--env GITHUB_ACTION \
--env GITHUB_EVENT_PATH \
--env RUNNER_OS \
@ -97,30 +74,94 @@ const Docker = {
--env RUNNER_TEMP \
--env RUNNER_WORKSPACE \
--env GIT_PRIVATE_TOKEN="${gitPrivateToken}" \
${sshAgent ? `--env SSH_AUTH_SOCK=${currentDockerPath?.get('sshAgent')}` : ''} \
--volume "${githubHome}:${currentDockerPath?.get('githubHome')}${bindMountZ}" \
--volume "${githubWorkflow}:${currentDockerPath?.get('githubWorkflow')}${bindMountZ}" \
--volume "${workspace}:${currentDockerPath?.get('githubWorkspace')}${bindMountZ}" \
--volume "${currentDockerPath?.get('stepsPathParent')}:${currentDockerPath?.get(
'stepsPathContainer',
)}${bindMountZ}" \
--volume "${currentDockerPath?.get('entrypointPathParent')}:${currentDockerPath?.get(
'entrypointPathContainer',
)}${bindMountZ}" \
${sshAgent ? `--volume ${sshAgent}:${currentDockerPath?.get('sshAgent')}` : ''} \
${sshAgent ? '--env SSH_AUTH_SOCK=/ssh-agent' : ''} \
--volume "${githubHome}:/root:z" \
--volume "${githubWorkflow}:/github/workflow:z" \
--volume "${workspace}:/github/workspace:z" \
--volume "${actionFolder}/steps:/steps:z" \
--volume "${actionFolder}/entrypoint.sh:/entrypoint.sh:z" \
${sshAgent ? `--volume ${sshAgent}:/ssh-agent` : ''} \
${
sshAgent ? `--volume /home/runner/.ssh/known_hosts:/root/.ssh/known_hosts:ro` : ''
} \
${useHostNetwork ? '--net=host' : ''} \
${githubToken ? '--env USE_EXIT_CODE=false' : '--env USE_EXIT_CODE=true'} \
${image} \
/bin/bash -c /entrypoint.sh`;
},
getWindowsCommand(image, parameters): string {
const {
actionFolder,
editorVersion,
workspace,
projectPath,
customParameters,
testMode,
coverageOptions,
artifactsPath,
useHostNetwork,
sshAgent,
gitPrivateToken,
githubToken,
runnerTemporaryPath,
} = parameters;
const githubHome = path.join(runnerTemporaryPath, '_github_home');
if (!existsSync(githubHome)) mkdirSync(githubHome);
const githubWorkflow = path.join(runnerTemporaryPath, '_github_workflow');
if (!existsSync(githubWorkflow)) mkdirSync(githubWorkflow);
const testPlatforms = (
testMode === 'all' ? ['playmode', 'editmode', 'COMBINE_RESULTS'] : [testMode]
).join(';');
return `docker run \
--workdir /github/workspace \
--rm \
--env UNITY_LICENSE \
--env UNITY_LICENSE_FILE \
--env UNITY_EMAIL \
--env UNITY_PASSWORD \
--env UNITY_SERIAL \
--env UNITY_VERSION="${editorVersion}" \
--env PROJECT_PATH="${projectPath}" \
--env CUSTOM_PARAMETERS="${customParameters}" \
--env TEST_PLATFORMS="${testPlatforms}" \
--env COVERAGE_OPTIONS="${coverageOptions}" \
--env COVERAGE_RESULTS_PATH="CodeCoverage" \
--env ARTIFACTS_PATH="${artifactsPath}" \
--env GITHUB_REF \
--env GITHUB_SHA \
--env GITHUB_REPOSITORY \
--env GITHUB_ACTOR \
--env GITHUB_WORKFLOW \
--env GITHUB_HEAD_REF \
--env GITHUB_BASE_REF \
--env GITHUB_EVENT_NAME \
--env GITHUB_WORKSPACE="/github/workspace" \
--env GITHUB_ACTION \
--env GITHUB_EVENT_PATH \
--env RUNNER_OS \
--env RUNNER_TOOL_CACHE \
--env RUNNER_TEMP \
--env RUNNER_WORKSPACE \
--env GIT_PRIVATE_TOKEN="${gitPrivateToken}" \
${sshAgent ? '--env SSH_AUTH_SOCK=c:/ssh-agent' : ''} \
--volume "${githubHome}":"c:/root" \
--volume "${githubWorkflow}":"c:/github/workflow" \
--volume "${workspace}":"c:/github/workspace" \
--volume "${actionFolder}/steps":"c:/steps" \
--volume "${actionFolder}":"c:/dist" \
${sshAgent ? `--volume ${sshAgent}:c:/ssh-agent` : ''} \
${
sshAgent
? `--volume ${currentDockerPath?.get('knownHostParent')}${currentDockerPath?.get(
'knownHostContainer',
)}${bindMountRO}`
? `--volume c:/Users/Administrator/.ssh/known_hosts:c:/root/.ssh/known_hosts`
: ''
} \
${useHostNetwork ? '--net=host' : ''} \
${githubToken ? '--env USE_EXIT_CODE=false' : '--env USE_EXIT_CODE=true'} \
${image} \
${currentDockerPath?.get('shellCommand')}`;
await exec(command, undefined, { silent });
powershell c:/dist/entrypoint.ps1`;
},
};