Fix lint issues and make paths more understandable

pull/305/head
Andrew Kahr 2022-01-24 15:39:14 -08:00
parent b16eb09671
commit 3b3ea8c574
4 changed files with 154 additions and 149 deletions

278
dist/index.js vendored
View File

@ -116,9 +116,9 @@ class Action {
static get dockerfile() { static get dockerfile() {
const currentPlatform = process.platform; const currentPlatform = process.platform;
switch (currentPlatform) { switch (currentPlatform) {
case "linux": case 'linux':
return `${Action.actionFolder}/platforms/ubuntu/Dockerfile`; return `${Action.actionFolder}/platforms/ubuntu/Dockerfile`;
case "win32": case 'win32':
return `${Action.actionFolder}/platforms/windows/Dockerfile`; return `${Action.actionFolder}/platforms/windows/Dockerfile`;
default: default:
throw new Error(`No Dockerfile for currently unsupported platform: ${currentPlatform}`); throw new Error(`No Dockerfile for currently unsupported platform: ${currentPlatform}`);
@ -257,9 +257,9 @@ class BuildParameters {
if (!process.env.UNITY_SERIAL) { if (!process.env.UNITY_SERIAL) {
//No serial was present so it is a personal license that we need to convert //No serial was present so it is a personal license that we need to convert
if (!process.env.UNITY_LICENSE) { if (!process.env.UNITY_LICENSE) {
throw new Error(`Missing Unity License File and no Serial was found. If this throw new Error(`Missing Unity License File and no Serial was found. If this
is a personal license, make sure to follow the activation is a personal license, make sure to follow the activation
steps and set the UNITY_LICENSE GitHub secret or enter a Unity steps and set the UNITY_LICENSE GitHub secret or enter a Unity
serial number inside the UNITY_SERIAL GitHub secret.`); serial number inside the UNITY_SERIAL GitHub secret.`);
} }
unitySerial = this.getSerialFromLicenseFile(process.env.UNITY_LICENSE); unitySerial = this.getSerialFromLicenseFile(process.env.UNITY_LICENSE);
@ -371,10 +371,10 @@ class Cache {
if (action_1.default.isRunningLocally) { if (action_1.default.isRunningLocally) {
return; return;
} }
core.warning(` core.warning(`
Library folder does not exist. Library folder does not exist.
Consider setting up caching to speed up your workflow, Consider setting up caching to speed up your workflow,
if this is not your first build. if this is not your first build.
`); `);
} }
} }
@ -589,7 +589,7 @@ class ImageTag {
return windowsIl2cpp; return windowsIl2cpp;
} }
else { else {
throw new Error(`Windows-based builds are only supported on 2019.3.X+ versions of Unity. throw new Error(`Windows-based builds are only supported on 2019.3.X+ versions of Unity.
If you are trying to build for windows-mono, please use a Linux based OS.`); If you are trying to build for windows-mono, please use a Linux based OS.`);
} }
} }
@ -638,8 +638,8 @@ class ImageTag {
case platform_1.default.types.Test: case platform_1.default.types.Test:
return generic; return generic;
default: default:
throw new Error(` throw new Error(`
Platform must be one of the ones described in the documentation. Platform must be one of the ones described in the documentation.
"${platform}" is currently not supported.`); "${platform}" is currently not supported.`);
} }
} }
@ -977,14 +977,14 @@ class Kubernetes {
command: [ command: [
'/bin/sh', '/bin/sh',
'-c', '-c',
`apk update; `apk update;
apk add git-lfs; apk add git-lfs;
export GITHUB_TOKEN=$(cat /credentials/GITHUB_TOKEN); export GITHUB_TOKEN=$(cat /credentials/GITHUB_TOKEN);
cd /data; cd /data;
git clone https://github.com/${process.env.GITHUB_REPOSITORY}.git repo; git clone https://github.com/${process.env.GITHUB_REPOSITORY}.git repo;
git clone https://github.com/webbertakken/unity-builder.git builder; git clone https://github.com/webbertakken/unity-builder.git builder;
cd repo; cd repo;
git checkout $GITHUB_SHA; git checkout $GITHUB_SHA;
ls`, ls`,
], ],
volumeMounts: [ volumeMounts: [
@ -1013,13 +1013,13 @@ class Kubernetes {
command: [ command: [
'bin/bash', 'bin/bash',
'-c', '-c',
`for f in ./credentials/*; do export $(basename $f)="$(cat $f)"; done `for f in ./credentials/*; do export $(basename $f)="$(cat $f)"; done
cp -r /data/builder/action/default-build-script /UnityBuilderAction cp -r /data/builder/action/default-build-script /UnityBuilderAction
cp -r /data/builder/action/entrypoint.sh /entrypoint.sh cp -r /data/builder/action/entrypoint.sh /entrypoint.sh
cp -r /data/builder/action/steps /steps cp -r /data/builder/action/steps /steps
chmod -R +x /entrypoint.sh; chmod -R +x /entrypoint.sh;
chmod -R +x /steps; chmod -R +x /steps;
/entrypoint.sh; /entrypoint.sh;
`, `,
], ],
resources: { resources: {
@ -1095,8 +1095,8 @@ class Kubernetes {
command: [ command: [
'bin/bash', 'bin/bash',
'-c', '-c',
`cd /data/builder/action/steps; `cd /data/builder/action/steps;
chmod +x /return_license.sh; chmod +x /return_license.sh;
/return_license.sh;`, /return_license.sh;`,
], ],
}, },
@ -1325,8 +1325,8 @@ class ValidateWindows {
static validate(buildParameters) { static validate(buildParameters) {
ValidateWindows.validateWindowsPlatformRequirements(buildParameters.platform); ValidateWindows.validateWindowsPlatformRequirements(buildParameters.platform);
if (!(process.env.UNITY_EMAIL && process.env.UNITY_PASSWORD)) { if (!(process.env.UNITY_EMAIL && process.env.UNITY_PASSWORD)) {
throw new Error(`Unity email and password must be set for Windows based builds to throw new Error(`Unity email and password must be set for Windows based builds to
authenticate the license. Make sure to set them inside UNITY_EMAIL authenticate the license. Make sure to set them inside UNITY_EMAIL
and UNITY_PASSWORD in Github Secrets and pass them into the environment.`); and UNITY_PASSWORD in Github Secrets and pass them into the environment.`);
} }
} }
@ -1351,19 +1351,21 @@ class ValidateWindows {
} }
static checkForWin10SDK() { static checkForWin10SDK() {
//Check for Windows 10 SDK on runner //Check for Windows 10 SDK on runner
if (!fs_1.default.existsSync('C:/Program Files (x86)/Windows Kits')) { const windows10SDKPathExists = fs_1.default.existsSync('C:/Program Files (x86)/Windows Kits');
throw new Error(`Windows 10 SDK not found in default location. Make sure if (!windows10SDKPathExists) {
the runner has a Windows 10 SDK installed in the default throw new Error(`Windows 10 SDK not found in default location. Make sure
the runner has a Windows 10 SDK installed in the default
location.`); location.`);
} }
} }
static checkForVisualStudio() { static checkForVisualStudio() {
//Note: When upgrading to Server 2022, we will need to move to just "program files" since VS will be 64-bit //Note: When upgrading to Server 2022, we will need to move to just "program files" since VS will be 64-bit
if (!(fs_1.default.existsSync('C:/Program Files (x86)/Microsoft Visual Studio') && const visualStudioInstallPathExists = fs_1.default.existsSync('C:/Program Files (x86)/Microsoft Visual Studio');
fs_1.default.existsSync('C:/ProgramData/Microsoft/VisualStudio'))) { const visualStudioDataPathExists = fs_1.default.existsSync('C:/ProgramData/Microsoft/VisualStudio');
throw new Error(`Visual Studio not found at the default location. if (!visualStudioInstallPathExists || !visualStudioDataPathExists) {
Make sure the runner has Visual Studio installed in the throw new Error(`Visual Studio not found at the default location.
default location`); Make sure the runner has Visual Studio installed in the
default location`);
} }
} }
} }
@ -1521,25 +1523,25 @@ class AWSBuildEnvironment {
// throw new Error('Method not implemented.'); // throw new Error('Method not implemented.');
// } // }
static getParameterTemplate(p1) { static getParameterTemplate(p1) {
return ` return `
${p1}: ${p1}:
Type: String Type: String
Default: '' Default: ''
`; `;
} }
static getSecretTemplate(p1) { static getSecretTemplate(p1) {
return ` return `
${p1}Secret: ${p1}Secret:
Type: AWS::SecretsManager::Secret Type: AWS::SecretsManager::Secret
Properties: Properties:
Name: !Join [ "", [ '${p1}', !Ref BUILDID ] ] Name: !Join [ "", [ '${p1}', !Ref BUILDID ] ]
SecretString: !Ref ${p1} SecretString: !Ref ${p1}
`; `;
} }
static getSecretDefinitionTemplate(p1, p2) { static getSecretDefinitionTemplate(p1, p2) {
return ` return `
- Name: '${p1}' - Name: '${p1}'
ValueFrom: !Ref ${p2}Secret ValueFrom: !Ref ${p2}Secret
`; `;
} }
static insertAtTemplate(template, insertionKey, insertion) { static insertAtTemplate(template, insertionKey, insertion) {
@ -1550,8 +1552,8 @@ class AWSBuildEnvironment {
static setupCloudFormations(CF, buildUid, stackName, image, entrypoint, commands, mountdir, workingdir, secrets) { static setupCloudFormations(CF, buildUid, stackName, image, entrypoint, commands, mountdir, workingdir, secrets) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
const logid = nanoid_1.customAlphabet(remote_builder_constants_1.default.alphabet, 9)(); const logid = nanoid_1.customAlphabet(remote_builder_constants_1.default.alphabet, 9)();
commands[1] += ` commands[1] += `
echo "${logid}" echo "${logid}"
`; `;
const taskDefStackName = `${stackName}-${buildUid}`; const taskDefStackName = `${stackName}-${buildUid}`;
let taskDefCloudFormation = this.readTaskCloudFormationTemplate(); let taskDefCloudFormation = this.readTaskCloudFormationTemplate();
@ -1962,60 +1964,60 @@ class RemoteBuilder {
core.info('Starting step 1/4 clone and restore cache)'); core.info('Starting step 1/4 clone and restore cache)');
yield aws_build_platform_1.default.runBuild(buildUid, buildParameters.awsStackName, 'alpine/git', [ yield aws_build_platform_1.default.runBuild(buildUid, buildParameters.awsStackName, 'alpine/git', [
'-c', '-c',
`apk update; `apk update;
apk add unzip; apk add unzip;
apk add git-lfs; apk add git-lfs;
apk add jq; apk add jq;
# Get source repo for project to be built and game-ci repo for utilties # Get source repo for project to be built and game-ci repo for utilties
git clone https://${buildParameters.githubToken}@github.com/${process.env.GITHUB_REPOSITORY}.git ${buildUid}/${repositoryDirectoryName} -q git clone https://${buildParameters.githubToken}@github.com/${process.env.GITHUB_REPOSITORY}.git ${buildUid}/${repositoryDirectoryName} -q
git clone https://${buildParameters.githubToken}@github.com/game-ci/unity-builder.git ${buildUid}/builder -q git clone https://${buildParameters.githubToken}@github.com/game-ci/unity-builder.git ${buildUid}/builder -q
git clone https://${buildParameters.githubToken}@github.com/game-ci/steam-deploy.git ${buildUid}/steam -q git clone https://${buildParameters.githubToken}@github.com/game-ci/steam-deploy.git ${buildUid}/steam -q
cd /${efsDirectoryName}/${buildUid}/${repositoryDirectoryName}/ cd /${efsDirectoryName}/${buildUid}/${repositoryDirectoryName}/
git checkout $GITHUB_SHA git checkout $GITHUB_SHA
cd /${efsDirectoryName}/ cd /${efsDirectoryName}/
# Look for usable cache # Look for usable cache
if [ ! -d ${cacheDirectoryName} ]; then if [ ! -d ${cacheDirectoryName} ]; then
mkdir ${cacheDirectoryName} mkdir ${cacheDirectoryName}
fi fi
cd ${cacheDirectoryName} cd ${cacheDirectoryName}
if [ ! -d "${branchName}" ]; then if [ ! -d "${branchName}" ]; then
mkdir "${branchName}" mkdir "${branchName}"
fi fi
cd "${branchName}" cd "${branchName}"
echo '' echo ''
echo "Cached Libraries for ${branchName} from previous builds:" echo "Cached Libraries for ${branchName} from previous builds:"
ls ls
echo '' echo ''
ls "/${efsDirectoryName}/${buildUid}/${repositoryDirectoryName}/${buildParameters.projectPath}" ls "/${efsDirectoryName}/${buildUid}/${repositoryDirectoryName}/${buildParameters.projectPath}"
libDir="/${efsDirectoryName}/${buildUid}/${repositoryDirectoryName}/${buildParameters.projectPath}/Library" libDir="/${efsDirectoryName}/${buildUid}/${repositoryDirectoryName}/${buildParameters.projectPath}/Library"
if [ -d "$libDir" ]; then if [ -d "$libDir" ]; then
rm -r "$libDir" rm -r "$libDir"
echo "Setup .gitignore to ignore Library folder and remove it from builds" echo "Setup .gitignore to ignore Library folder and remove it from builds"
fi fi
echo 'Checking cache' echo 'Checking cache'
# Restore cache # Restore cache
latest=$(ls -t | head -1) latest=$(ls -t | head -1)
if [ ! -z "$latest" ]; then if [ ! -z "$latest" ]; then
echo "Library cache exists from build $latest from ${branchName}" echo "Library cache exists from build $latest from ${branchName}"
echo 'Creating empty Library folder for cache' echo 'Creating empty Library folder for cache'
mkdir $libDir mkdir $libDir
unzip -q $latest -d $libDir unzip -q $latest -d $libDir
# purge cache # purge cache
${process.env.PURGE_REMOTE_BUILDER_CACHE === undefined ? '#' : ''} rm -r $libDir ${process.env.PURGE_REMOTE_BUILDER_CACHE === undefined ? '#' : ''} rm -r $libDir
else else
echo 'Cache does not exist' echo 'Cache does not exist'
fi fi
# Print out important directories # Print out important directories
echo '' echo ''
echo 'Repo:' echo 'Repo:'
ls /${efsDirectoryName}/${buildUid}/${repositoryDirectoryName}/ ls /${efsDirectoryName}/${buildUid}/${repositoryDirectoryName}/
echo '' echo ''
echo 'Project:' echo 'Project:'
ls /${efsDirectoryName}/${buildUid}/${repositoryDirectoryName}/${buildParameters.projectPath} ls /${efsDirectoryName}/${buildUid}/${repositoryDirectoryName}/${buildParameters.projectPath}
echo '' echo ''
echo 'Library:' echo 'Library:'
ls /${efsDirectoryName}/${buildUid}/${repositoryDirectoryName}/${buildParameters.projectPath}/Library/ ls /${efsDirectoryName}/${buildUid}/${repositoryDirectoryName}/${buildParameters.projectPath}/Library/
echo '' echo ''
`, `,
], `/${efsDirectoryName}`, `/${efsDirectoryName}/`, [ ], `/${efsDirectoryName}`, `/${efsDirectoryName}/`, [
{ {
@ -2074,13 +2076,13 @@ class RemoteBuilder {
core.info('Starting part 2/4 (build unity project)'); core.info('Starting part 2/4 (build unity project)');
yield aws_build_platform_1.default.runBuild(buildUid, buildParameters.awsStackName, baseImage.toString(), [ yield aws_build_platform_1.default.runBuild(buildUid, buildParameters.awsStackName, baseImage.toString(), [
'-c', '-c',
` `
cp -r /${efsDirectoryName}/${buildUid}/builder/dist/default-build-script/ /UnityBuilderAction; cp -r /${efsDirectoryName}/${buildUid}/builder/dist/default-build-script/ /UnityBuilderAction;
cp -r /${efsDirectoryName}/${buildUid}/builder/dist/entrypoint.sh /entrypoint.sh; cp -r /${efsDirectoryName}/${buildUid}/builder/dist/entrypoint.sh /entrypoint.sh;
cp -r /${efsDirectoryName}/${buildUid}/builder/dist/steps/ /steps; cp -r /${efsDirectoryName}/${buildUid}/builder/dist/steps/ /steps;
chmod -R +x /entrypoint.sh; chmod -R +x /entrypoint.sh;
chmod -R +x /steps; chmod -R +x /steps;
/entrypoint.sh; /entrypoint.sh;
`, `,
], `/${efsDirectoryName}`, `/${efsDirectoryName}/${buildUid}/${repositoryDirectoryName}/`, [ ], `/${efsDirectoryName}`, `/${efsDirectoryName}/${buildUid}/${repositoryDirectoryName}/`, [
{ {
@ -2144,15 +2146,15 @@ class RemoteBuilder {
// Cleanup // Cleanup
yield aws_build_platform_1.default.runBuild(buildUid, buildParameters.awsStackName, 'alpine', [ yield aws_build_platform_1.default.runBuild(buildUid, buildParameters.awsStackName, 'alpine', [
'-c', '-c',
` `
apk update apk update
apk add zip apk add zip
cd Library cd Library
zip -r lib-${buildUid}.zip .* zip -r lib-${buildUid}.zip .*
mv lib-${buildUid}.zip /${efsDirectoryName}/${cacheDirectoryName}/${branchName}/lib-${buildUid}.zip mv lib-${buildUid}.zip /${efsDirectoryName}/${cacheDirectoryName}/${branchName}/lib-${buildUid}.zip
cd ../../ cd ../../
zip -r build-${buildUid}.zip ${buildParameters.buildPath}/* zip -r build-${buildUid}.zip ${buildParameters.buildPath}/*
mv build-${buildUid}.zip /${efsDirectoryName}/${buildUid}/build-${buildUid}.zip mv build-${buildUid}.zip /${efsDirectoryName}/${buildUid}/build-${buildUid}.zip
`, `,
], `/${efsDirectoryName}`, `/${efsDirectoryName}/${buildUid}/${repositoryDirectoryName}/${buildParameters.projectPath}`, [ ], `/${efsDirectoryName}`, `/${efsDirectoryName}/${buildUid}/${repositoryDirectoryName}/${buildParameters.projectPath}`, [
{ {
@ -2168,11 +2170,11 @@ class RemoteBuilder {
core.info('Starting step 4/4 upload build to s3'); core.info('Starting step 4/4 upload build to s3');
yield aws_build_platform_1.default.runBuild(buildUid, buildParameters.awsStackName, 'amazon/aws-cli', [ yield aws_build_platform_1.default.runBuild(buildUid, buildParameters.awsStackName, 'amazon/aws-cli', [
'-c', '-c',
` `
aws s3 cp ${buildUid}/build-${buildUid}.zip s3://game-ci-storage/ aws s3 cp ${buildUid}/build-${buildUid}.zip s3://game-ci-storage/
# no need to upload Library cache for now # no need to upload Library cache for now
# aws s3 cp /${efsDirectoryName}/${cacheDirectoryName}/${branchName}/lib-${buildUid}.zip s3://game-ci-storage/ # aws s3 cp /${efsDirectoryName}/${cacheDirectoryName}/${branchName}/lib-${buildUid}.zip s3://game-ci-storage/
${this.SteamDeploy ? '#' : ''} rm -r ${buildUid} ${this.SteamDeploy ? '#' : ''} rm -r ${buildUid}
`, `,
], `/${efsDirectoryName}`, `/${efsDirectoryName}/`, [ ], `/${efsDirectoryName}`, `/${efsDirectoryName}/`, [
{ {
@ -2203,15 +2205,15 @@ class RemoteBuilder {
core.info('Starting steam deployment'); core.info('Starting steam deployment');
yield aws_build_platform_1.default.runBuild(buildUid, buildParameters.awsStackName, 'cm2network/steamcmd:root', [ yield aws_build_platform_1.default.runBuild(buildUid, buildParameters.awsStackName, 'cm2network/steamcmd:root', [
'-c', '-c',
` `
ls ls
ls / ls /
cp -r /${efsDirectoryName}/${buildUid}/steam/action/entrypoint.sh /entrypoint.sh; cp -r /${efsDirectoryName}/${buildUid}/steam/action/entrypoint.sh /entrypoint.sh;
cp -r /${efsDirectoryName}/${buildUid}/steam/action/steps/ /steps; cp -r /${efsDirectoryName}/${buildUid}/steam/action/steps/ /steps;
chmod -R +x /entrypoint.sh; chmod -R +x /entrypoint.sh;
chmod -R +x /steps; chmod -R +x /steps;
/entrypoint.sh; /entrypoint.sh;
rm -r /${efsDirectoryName}/${buildUid} rm -r /${efsDirectoryName}/${buildUid}
`, `,
], `/${efsDirectoryName}`, `/${efsDirectoryName}/${buildUid}/steam/action/`, [ ], `/${efsDirectoryName}`, `/${efsDirectoryName}/${buildUid}/steam/action/`, [
{ {

2
dist/index.js.map vendored

File diff suppressed because one or more lines are too long

View File

@ -32,9 +32,9 @@ class Action {
static get dockerfile() { static get dockerfile() {
const currentPlatform = process.platform; const currentPlatform = process.platform;
switch (currentPlatform) { switch (currentPlatform) {
case "linux": case 'linux':
return `${Action.actionFolder}/platforms/ubuntu/Dockerfile`; return `${Action.actionFolder}/platforms/ubuntu/Dockerfile`;
case "win32": case 'win32':
return `${Action.actionFolder}/platforms/windows/Dockerfile`; return `${Action.actionFolder}/platforms/windows/Dockerfile`;
default: default:
throw new Error(`No Dockerfile for currently unsupported platform: ${currentPlatform}`); throw new Error(`No Dockerfile for currently unsupported platform: ${currentPlatform}`);

View File

@ -3,7 +3,7 @@ import { BuildParameters } from '..';
class ValidateWindows { class ValidateWindows {
public static validate(buildParameters: BuildParameters) { public static validate(buildParameters: BuildParameters) {
ValidateWindows.validateWindowsPlatformRequirements(buildParameters.platform) ValidateWindows.validateWindowsPlatformRequirements(buildParameters.platform);
if (!(process.env.UNITY_EMAIL && process.env.UNITY_PASSWORD)) { if (!(process.env.UNITY_EMAIL && process.env.UNITY_PASSWORD)) {
throw new Error(`Unity email and password must be set for Windows based builds to throw new Error(`Unity email and password must be set for Windows based builds to
authenticate the license. Make sure to set them inside UNITY_EMAIL authenticate the license. Make sure to set them inside UNITY_EMAIL
@ -33,7 +33,8 @@ class ValidateWindows {
private static checkForWin10SDK() { private static checkForWin10SDK() {
//Check for Windows 10 SDK on runner //Check for Windows 10 SDK on runner
if (!fs.existsSync('C:/Program Files (x86)/Windows Kits')) { const windows10SDKPathExists = fs.existsSync('C:/Program Files (x86)/Windows Kits');
if (!windows10SDKPathExists) {
throw new Error(`Windows 10 SDK not found in default location. Make sure throw new Error(`Windows 10 SDK not found in default location. Make sure
the runner has a Windows 10 SDK installed in the default the runner has a Windows 10 SDK installed in the default
location.`); location.`);
@ -42,13 +43,15 @@ class ValidateWindows {
private static checkForVisualStudio() { private static checkForVisualStudio() {
//Note: When upgrading to Server 2022, we will need to move to just "program files" since VS will be 64-bit //Note: When upgrading to Server 2022, we will need to move to just "program files" since VS will be 64-bit
if (!(fs.existsSync('C:/Program Files (x86)/Microsoft Visual Studio') && const visualStudioInstallPathExists = fs.existsSync('C:/Program Files (x86)/Microsoft Visual Studio');
fs.existsSync('C:/ProgramData/Microsoft/VisualStudio'))) { const visualStudioDataPathExists = fs.existsSync('C:/ProgramData/Microsoft/VisualStudio');
throw new Error(`Visual Studio not found at the default location.
Make sure the runner has Visual Studio installed in the if (!visualStudioInstallPathExists || !visualStudioDataPathExists) {
default location`); throw new Error(`Visual Studio not found at the default location.
} Make sure the runner has Visual Studio installed in the
default location`);
} }
}
} }
export default ValidateWindows; export default ValidateWindows;