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

View File

@ -3,7 +3,7 @@ import { BuildParameters } from '..';
class ValidateWindows {
public static validate(buildParameters: BuildParameters) {
ValidateWindows.validateWindowsPlatformRequirements(buildParameters.platform)
ValidateWindows.validateWindowsPlatformRequirements(buildParameters.platform);
if (!(process.env.UNITY_EMAIL && process.env.UNITY_PASSWORD)) {
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
@ -33,7 +33,8 @@ class ValidateWindows {
private static checkForWin10SDK() {
//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
the runner has a Windows 10 SDK installed in the default
location.`);
@ -42,13 +43,15 @@ class ValidateWindows {
private static checkForVisualStudio() {
//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') &&
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
default location`);
}
const visualStudioInstallPathExists = fs.existsSync('C:/Program Files (x86)/Microsoft Visual Studio');
const visualStudioDataPathExists = fs.existsSync('C:/ProgramData/Microsoft/VisualStudio');
if (!visualStudioInstallPathExists || !visualStudioDataPathExists) {
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;