Refactor models to allow for build parameters...

Build parameters have to be parsed because they can no longer be implicitly passed, as they need to be interpreted for detecting extensions.
This commit is contained in:
Webber
2020-01-21 00:06:14 +01:00
committed by Webber Takken
parent a84535fc04
commit 1d1f81c0bb
10 changed files with 172 additions and 95 deletions

View File

@@ -1,6 +1,6 @@
import path from 'path';
export default class Action {
class Action {
static get supportedPlatforms() {
return ['linux'];
}
@@ -44,3 +44,5 @@ export default class Action {
}
}
}
export default Action;

View File

@@ -0,0 +1,38 @@
import Platform from './platform';
class BuildParameters {
static create(parameters) {
const {
unityVersion,
targetPlatform,
projectPath,
buildName,
buildsPath,
buildMethod,
} = parameters;
return {
version: unityVersion,
platform: targetPlatform,
projectPath,
buildName,
buildPath: `${buildsPath}/${targetPlatform}`,
buildFile: this.parseBuildFile(buildName, targetPlatform),
buildMethod,
};
}
static parseBuildFile(filename, platform) {
if (Platform.isWindows(platform)) {
return `${filename}.exe`;
}
if (Platform.isAndroid(platform)) {
return `${filename}.apk`;
}
return filename;
}
}
export default BuildParameters;

View File

@@ -1,7 +1,7 @@
import { exec } from '@actions/exec';
import ImageTag from './image-tag';
export default class Docker {
class Docker {
static async build(buildParameters, silent = false) {
const { path, dockerfile, baseImage } = buildParameters;
const { version, platform } = baseImage;
@@ -18,8 +18,16 @@ export default class Docker {
}
static async run(image, parameters, silent = false) {
const { workspace, platform, projectPath, buildName, buildsPath, method } = parameters;
const { version } = image;
const {
version,
workspace,
platform,
projectPath,
buildName,
buildPath,
buildFile,
buildMethod,
} = parameters;
const command = `docker run \
--workdir /github/workspace \
@@ -32,8 +40,9 @@ export default class Docker {
--env PROJECT_PATH=${projectPath} \
--env BUILD_TARGET=${platform} \
--env BUILD_NAME=${buildName} \
--env BUILDS_PATH=${buildsPath} \
--env BUILD_METHOD=${method} \
--env BUILD_PATH=${buildPath} \
--env BUILD_FILE=${buildFile} \
--env BUILD_METHOD=${buildMethod} \
--env HOME=/github/home \
--env GITHUB_REF \
--env GITHUB_SHA \
@@ -59,3 +68,5 @@ export default class Docker {
await exec(command, null, { silent });
}
}
export default Docker;

View File

@@ -1,6 +1,7 @@
import { has, get, trimEnd, trimStart } from 'lodash-es';
import Platform from './platform';
export default class ImageTag {
class ImageTag {
constructor(imageProperties) {
const {
repository = 'gableroux',
@@ -13,14 +14,14 @@ export default class ImageTag {
throw new Error(`Invalid version "${version}".`);
}
if (!has(ImageTag.targetPlatformToBuilderPlatformMap, platform)) {
if (!has(ImageTag.targetPlatformToImageSuffixMap, platform)) {
throw new Error(`Platform "${platform}" is currently not supported.`);
}
const builderPlatform = get(
ImageTag.targetPlatformToBuilderPlatformMap,
ImageTag.targetPlatformToImageSuffixMap,
platform,
ImageTag.builderPlatforms.generic,
ImageTag.imageSuffixes.generic,
);
Object.assign(this, { repository, name, version, platform, builderPlatform });
@@ -30,7 +31,7 @@ export default class ImageTag {
return /^20\d{2}\.\d\.\w{3,4}|3$/;
}
static get builderPlatforms() {
static get imageSuffixes() {
return {
generic: '',
webgl: 'webgl',
@@ -42,31 +43,31 @@ export default class ImageTag {
};
}
static get targetPlatformToBuilderPlatformMap() {
const { generic, webgl, mac, windows, android, ios, facebook } = ImageTag.builderPlatforms;
static get targetPlatformToImageSuffixMap() {
const { generic, webgl, mac, windows, android, ios, facebook } = ImageTag.imageSuffixes;
// @see: https://docs.unity3d.com/ScriptReference/BuildTarget.html
return {
StandaloneOSX: mac,
StandaloneWindows: windows,
StandaloneWindows64: windows,
StandaloneLinux64: windows,
iOS: ios,
Android: android,
WebGL: webgl,
WSAPlayer: windows,
PS4: windows,
XboxOne: windows,
tvOS: windows,
Switch: windows,
[Platform.types.StandaloneOSX]: mac,
[Platform.types.StandaloneWindows]: windows,
[Platform.types.StandaloneWindows64]: windows,
[Platform.types.StandaloneLinux64]: windows,
[Platform.types.iOS]: ios,
[Platform.types.Android]: android,
[Platform.types.WebGL]: webgl,
[Platform.types.WSAPlayer]: windows,
[Platform.types.PS4]: windows,
[Platform.types.XboxOne]: windows,
[Platform.types.tvOS]: windows,
[Platform.types.Switch]: windows,
// Unsupported
Lumin: windows,
BJM: windows,
Stadia: windows,
Facebook: facebook,
NoTarget: generic,
[Platform.types.Lumin]: windows,
[Platform.types.BJM]: windows,
[Platform.types.Stadia]: windows,
[Platform.types.Facebook]: facebook,
[Platform.types.NoTarget]: generic,
// Test specific
Test: generic,
[Platform.types.Test]: generic,
};
}
@@ -84,3 +85,5 @@ export default class ImageTag {
return `${image}:${tag}`;
}
}
export default ImageTag;

View File

@@ -1,22 +1,26 @@
import Platform from './platform';
const core = require('@actions/core');
export default class Input {
class Input {
static getFromUser() {
// Input variables specified in workflows using "with" prop.
const version = core.getInput('unityVersion');
const platform = core.getInput('targetPlatform');
const unityVersion = core.getInput('unityVersion');
const targetPlatform = core.getInput('targetPlatform') || Platform.default;
const projectPath = core.getInput('projectPath');
const buildName = core.getInput('buildName');
const buildsPath = core.getInput('buildsPath');
const buildMethod = core.getInput('buildMethod');
const buildName = core.getInput('buildName') || targetPlatform;
const buildsPath = core.getInput('buildsPath') || 'build';
const buildMethod = core.getInput('buildMethod'); // processed in docker file
return {
version,
platform,
unityVersion,
targetPlatform,
projectPath,
buildName,
buildsPath,
method: buildMethod,
buildMethod,
};
}
}
export default Input;

51
src/model/platform.js Normal file
View File

@@ -0,0 +1,51 @@
class Platform {
static get default() {
return Platform.types.StandaloneWindows64;
}
static get types() {
return {
StandaloneOSX: 'StandaloneOSX',
StandaloneWindows: 'StandaloneWindows',
StandaloneWindows64: 'StandaloneWindows64',
StandaloneLinux64: 'StandaloneLinux64',
iOS: 'iOS',
Android: 'Android',
WebGL: 'WebGL',
WSAPlayer: 'WSAPlayer',
PS4: 'PS4',
XboxOne: 'XboxOne',
tvOS: 'tvOS',
Switch: 'Switch',
// Unsupported
Lumin: 'Lumin',
BJM: 'BJM',
Stadia: 'Stadia',
Facebook: 'Facebook',
NoTarget: 'NoTarget',
// Test specific
Test: 'Test',
};
}
static isWindows(platform) {
switch (platform) {
case Platform.types.StandaloneWindows:
case Platform.types.StandaloneWindows64:
return true;
default:
return false;
}
}
static isAndroid(platform) {
switch (platform) {
case Platform.types.Android:
return true;
default:
return false;
}
}
}
export default Platform;