mirror of
https://github.com/game-ci/unity-builder.git
synced 2025-07-07 20:35:33 -04:00

- Add missing unityLicenseServer input (Fix #480) - Use HEAD when calculating semantic version number. This is a riskier change as this has always used `github.sha` on the runner. However, when pulling in other repos and running the action, it may not be referencing the correct commit on the repo. After testing, though, nothing appears to be broken so this in theory should work fine. (Fix #417) - Setup private token rewrites on Windows images (Fix #428) - Allow setting a custom workspace path within docker container with `dockerWorkspacePath`. (Fix #433) - [Breaking Change] Remove `androidAppBundle` parameter in favor of `androidExportType`.
98 lines
4.5 KiB
TypeScript
98 lines
4.5 KiB
TypeScript
import { execWithErrorCheck } from './exec-with-error-check';
|
|
import ImageEnvironmentFactory from './image-environment-factory';
|
|
import { existsSync, mkdirSync } from 'node:fs';
|
|
import path from 'node:path';
|
|
import { ExecOptions } from '@actions/exec';
|
|
import { DockerParameters, StringKeyValuePair } from './shared-types';
|
|
|
|
class Docker {
|
|
static async run(
|
|
image: string,
|
|
parameters: DockerParameters,
|
|
silent: boolean = false,
|
|
overrideCommands: string = '',
|
|
additionalVariables: StringKeyValuePair[] = [],
|
|
// eslint-disable-next-line unicorn/no-useless-undefined
|
|
options: ExecOptions | undefined = undefined,
|
|
entrypointBash: boolean = false,
|
|
errorWhenMissingUnityBuildResults: boolean = true,
|
|
) {
|
|
let runCommand = '';
|
|
switch (process.platform) {
|
|
case 'linux':
|
|
runCommand = this.getLinuxCommand(image, parameters, overrideCommands, additionalVariables, entrypointBash);
|
|
break;
|
|
case 'win32':
|
|
runCommand = this.getWindowsCommand(image, parameters);
|
|
}
|
|
if (options) {
|
|
options.silent = silent;
|
|
await execWithErrorCheck(runCommand, undefined, options, errorWhenMissingUnityBuildResults);
|
|
} else {
|
|
await execWithErrorCheck(runCommand, undefined, { silent }, errorWhenMissingUnityBuildResults);
|
|
}
|
|
}
|
|
|
|
static getLinuxCommand(
|
|
image: string,
|
|
parameters: DockerParameters,
|
|
overrideCommands: string = '',
|
|
additionalVariables: StringKeyValuePair[] = [],
|
|
entrypointBash: boolean = false,
|
|
): string {
|
|
const { workspace, actionFolder, runnerTempPath, sshAgent, gitPrivateToken, dockerWorkspacePath } = parameters;
|
|
|
|
const githubHome = path.join(runnerTempPath, '_github_home');
|
|
if (!existsSync(githubHome)) mkdirSync(githubHome);
|
|
const githubWorkflow = path.join(runnerTempPath, '_github_workflow');
|
|
if (!existsSync(githubWorkflow)) mkdirSync(githubWorkflow);
|
|
const commandPrefix = image === `alpine` ? `/bin/sh` : `/bin/bash`;
|
|
|
|
return `docker run \
|
|
--workdir ${dockerWorkspacePath} \
|
|
--rm \
|
|
${ImageEnvironmentFactory.getEnvVarString(parameters, additionalVariables)} \
|
|
--env UNITY_SERIAL \
|
|
--env GITHUB_WORKSPACE=${dockerWorkspacePath} \
|
|
${gitPrivateToken ? `--env GIT_PRIVATE_TOKEN="${gitPrivateToken}"` : ''} \
|
|
${sshAgent ? '--env SSH_AUTH_SOCK=/ssh-agent' : ''} \
|
|
--volume "${githubHome}":"/root:z" \
|
|
--volume "${githubWorkflow}":"/github/workflow:z" \
|
|
--volume "${workspace}":"${dockerWorkspacePath}:z" \
|
|
--volume "${actionFolder}/default-build-script:/UnityBuilderAction:z" \
|
|
--volume "${actionFolder}/platforms/ubuntu/steps:/steps:z" \
|
|
--volume "${actionFolder}/platforms/ubuntu/entrypoint.sh:/entrypoint.sh:z" \
|
|
--volume "${actionFolder}/unity-config:/usr/share/unity3d/config/:z" \
|
|
${sshAgent ? `--volume ${sshAgent}:/ssh-agent` : ''} \
|
|
${sshAgent ? '--volume /home/runner/.ssh/known_hosts:/root/.ssh/known_hosts:ro' : ''} \
|
|
${entrypointBash ? `--entrypoint ${commandPrefix}` : ``} \
|
|
${image} \
|
|
${entrypointBash ? `-c` : `${commandPrefix} -c`} \
|
|
"${overrideCommands !== '' ? overrideCommands : `/entrypoint.sh`}"`;
|
|
}
|
|
|
|
static getWindowsCommand(image: string, parameters: DockerParameters): string {
|
|
const { workspace, actionFolder, unitySerial, gitPrivateToken, dockerWorkspacePath } = parameters;
|
|
|
|
return `docker run \
|
|
--workdir c:${dockerWorkspacePath} \
|
|
--rm \
|
|
${ImageEnvironmentFactory.getEnvVarString(parameters)} \
|
|
--env UNITY_SERIAL="${unitySerial}" \
|
|
--env GITHUB_WORKSPACE=c:${dockerWorkspacePath} \
|
|
${gitPrivateToken ? `--env GIT_PRIVATE_TOKEN="${gitPrivateToken}"` : ''} \
|
|
--volume "${workspace}":"c:${dockerWorkspacePath}" \
|
|
--volume "c:/regkeys":"c:/regkeys" \
|
|
--volume "C:/Program Files (x86)/Microsoft Visual Studio":"C:/Program Files (x86)/Microsoft Visual Studio" \
|
|
--volume "C:/Program Files (x86)/Windows Kits":"C:/Program Files (x86)/Windows Kits" \
|
|
--volume "C:/ProgramData/Microsoft/VisualStudio":"C:/ProgramData/Microsoft/VisualStudio" \
|
|
--volume "${actionFolder}/default-build-script":"c:/UnityBuilderAction" \
|
|
--volume "${actionFolder}/platforms/windows":"c:/steps" \
|
|
--volume "${actionFolder}/BlankProject":"c:/BlankProject" \
|
|
${image} \
|
|
powershell c:/steps/entrypoint.ps1`;
|
|
}
|
|
}
|
|
|
|
export default Docker;
|