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.pull/25/head v0.8
parent
a84535fc04
commit
1d1f81c0bb
|
@ -127,10 +127,10 @@ _**required:** `true`_
|
||||||
|
|
||||||
#### buildName
|
#### buildName
|
||||||
|
|
||||||
Name of the build.
|
Name of the build. Also the folder in which the build will be stored within `buildsPath`.
|
||||||
|
|
||||||
_**required:** `false`_
|
_**required:** `false`_
|
||||||
_**default:** `testBuild`_
|
_**default:** `<build_target>`_
|
||||||
|
|
||||||
#### buildsPath
|
#### buildsPath
|
||||||
|
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -4,53 +4,28 @@
|
||||||
# Set project path
|
# Set project path
|
||||||
#
|
#
|
||||||
|
|
||||||
UNITY_PROJECT_PATH=$GITHUB_WORKSPACE/$PROJECT_PATH
|
UNITY_PROJECT_PATH="$GITHUB_WORKSPACE/$PROJECT_PATH"
|
||||||
echo "Using project path \"$UNITY_PROJECT_PATH\"."
|
echo "Using project path \"$UNITY_PROJECT_PATH\"."
|
||||||
|
|
||||||
#
|
#
|
||||||
# Set the name for the build
|
# Display the name for the build, doubles as the output name
|
||||||
#
|
#
|
||||||
|
|
||||||
if [ -z "$BUILD_NAME" ]; then
|
|
||||||
BUILD_NAME="build-$(date '+%F-%H%M')"
|
|
||||||
fi
|
|
||||||
echo "Using build name \"$BUILD_NAME\"."
|
echo "Using build name \"$BUILD_NAME\"."
|
||||||
|
|
||||||
#
|
#
|
||||||
# Set the builds target platform;
|
# Display the build's target platform;
|
||||||
#
|
|
||||||
# Web: WebGL
|
|
||||||
# Desktop: StandaloneOSX, StandaloneWindows, StandaloneWindows64, StandaloneLinux64
|
|
||||||
# Console: PS4, XboxOne, Switch
|
|
||||||
# Mobile: Android, iOS
|
|
||||||
# Other: tvOS, Lumin, BJM, WSAPlayer
|
|
||||||
#
|
|
||||||
# Default to WebGL (no particular reason)
|
|
||||||
#
|
#
|
||||||
|
|
||||||
if [ -z "$BUILD_TARGET" ]; then
|
|
||||||
BUILD_TARGET=WebGL
|
|
||||||
fi
|
|
||||||
echo "Using build target \"$BUILD_TARGET\"."
|
echo "Using build target \"$BUILD_TARGET\"."
|
||||||
|
|
||||||
#
|
#
|
||||||
# Set builds path
|
# Display build path and file
|
||||||
#
|
#
|
||||||
|
|
||||||
if [ -z "$BUILDS_PATH" ]; then
|
echo "Using build path \"$BUILD_PATH\" to save file \"$BUILD_FILE\"."
|
||||||
BUILDS_PATH=build
|
BUILD_PATH_FULL="$GITHUB_WORKSPACE/$BUILD_PATH"
|
||||||
fi
|
CUSTOM_BUILD_PATH="$BUILD_PATH_FULL/$BUILD_FILE"
|
||||||
BUILDS_FULL_PATH=$GITHUB_WORKSPACE/$BUILDS_PATH
|
|
||||||
|
|
||||||
# TODO - Cleanup
|
|
||||||
BUILD_FOLDER=$BUILD_TARGET-$UNITY_VERSION
|
|
||||||
CURRENT_BUILD_PATH=$BUILDS_PATH/$BUILD_FOLDER
|
|
||||||
CURRENT_BUILD_FULL_PATH=$BUILDS_FULL_PATH/$BUILD_FOLDER
|
|
||||||
|
|
||||||
# TODO - Determine the file or folder based on BUILD_TARGET
|
|
||||||
CUSTOM_BUILD_PATH=$BUILDS_FULL_PATH/$BUILD_FOLDER/$BUILD_TARGET
|
|
||||||
|
|
||||||
echo "Using build path \"$CURRENT_BUILD_PATH\"."
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Set the build method, must reference one of:
|
# Set the build method, must reference one of:
|
||||||
|
@ -71,13 +46,13 @@ if [ -z "$BUILD_METHOD" ]; then
|
||||||
#
|
#
|
||||||
echo "Using built-in build method."
|
echo "Using built-in build method."
|
||||||
# Create Editor directory if it does not exist
|
# Create Editor directory if it does not exist
|
||||||
mkdir -p $UNITY_PROJECT_PATH/Assets/Editor/
|
mkdir -p "$UNITY_PROJECT_PATH/Assets/Editor/"
|
||||||
# Copy the build script of Unity Builder action
|
# Copy the build script of Unity Builder action
|
||||||
cp -r /UnityBuilderAction/Assets/Editor $UNITY_PROJECT_PATH/Assets/Editor/
|
cp -r "/UnityBuilderAction/Assets/Editor" "$UNITY_PROJECT_PATH/Assets/Editor/"
|
||||||
# Set the Build method to that of UnityBuilder Action
|
# Set the Build method to that of UnityBuilder Action
|
||||||
BUILD_METHOD="UnityBuilderAction.Builder.BuildProject"
|
BUILD_METHOD="UnityBuilderAction.Builder.BuildProject"
|
||||||
# Verify recursive paths
|
# Verify recursive paths
|
||||||
ls -Ralph $UNITY_PROJECT_PATH/Assets/Editor/
|
ls -Ralph "$UNITY_PROJECT_PATH/Assets/Editor/"
|
||||||
#
|
#
|
||||||
else
|
else
|
||||||
# User has provided their own build method.
|
# User has provided their own build method.
|
||||||
|
@ -98,25 +73,15 @@ EXECUTE_BUILD_METHOD="-executeMethod $BUILD_METHOD"
|
||||||
# Build info
|
# Build info
|
||||||
#
|
#
|
||||||
|
|
||||||
echo ""
|
|
||||||
echo "###########################"
|
|
||||||
echo "# All builds dir #"
|
|
||||||
echo "###########################"
|
|
||||||
echo ""
|
|
||||||
|
|
||||||
echo "Creating \"$BUILDS_FULL_PATH\" if it does not exist."
|
|
||||||
mkdir -p $BUILDS_FULL_PATH
|
|
||||||
ls -alh $BUILDS_FULL_PATH
|
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
echo "###########################"
|
echo "###########################"
|
||||||
echo "# Current build dir #"
|
echo "# Current build dir #"
|
||||||
echo "###########################"
|
echo "###########################"
|
||||||
echo ""
|
echo ""
|
||||||
|
|
||||||
echo "Creating \"$CURRENT_BUILD_FULL_PATH\" if it does not exist."exist."
|
echo "Creating \"$BUILD_PATH_FULL\" if it does not exist."
|
||||||
mkdir -p $CURRENT_BUILD_FULL_PATH
|
mkdir -p "$BUILD_PATH_FULL"
|
||||||
ls -alh $CURRENT_BUILD_FULL_PATH
|
ls -alh "$BUILD_PATH_FULL"
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
echo "###########################"
|
echo "###########################"
|
||||||
|
@ -164,4 +129,4 @@ echo "# Build directory #"
|
||||||
echo "###########################"
|
echo "###########################"
|
||||||
echo ""
|
echo ""
|
||||||
|
|
||||||
ls -alh $CURRENT_BUILD_FULL_PATH
|
ls -alh "$BUILD_PATH_FULL"
|
||||||
|
|
|
@ -2,6 +2,7 @@ import Action from './model/action';
|
||||||
import Docker from './model/docker';
|
import Docker from './model/docker';
|
||||||
import ImageTag from './model/image-tag';
|
import ImageTag from './model/image-tag';
|
||||||
import Input from './model/input';
|
import Input from './model/input';
|
||||||
|
import BuildParameters from './model/build-parameters';
|
||||||
|
|
||||||
const core = require('@actions/core');
|
const core = require('@actions/core');
|
||||||
|
|
||||||
|
@ -9,12 +10,14 @@ async function action() {
|
||||||
Action.checkCompatibility();
|
Action.checkCompatibility();
|
||||||
|
|
||||||
const { dockerfile, workspace, builderFolder } = Action;
|
const { dockerfile, workspace, builderFolder } = Action;
|
||||||
const { version, platform, projectPath, buildName, buildsPath, method } = Input.getFromUser();
|
const buildParameters = BuildParameters.create(Input.getFromUser());
|
||||||
|
const baseImage = new ImageTag(buildParameters);
|
||||||
|
|
||||||
const baseImage = new ImageTag({ version, platform });
|
// Build docker image
|
||||||
const builtImage = await Docker.build({ path: builderFolder, dockerfile, baseImage });
|
const builtImage = await Docker.build({ path: builderFolder, dockerfile, baseImage });
|
||||||
|
|
||||||
await Docker.run(builtImage, { workspace, platform, projectPath, buildName, buildsPath, method });
|
// Run docker image
|
||||||
|
await Docker.run(builtImage, { workspace, ...buildParameters });
|
||||||
}
|
}
|
||||||
|
|
||||||
action().catch(error => {
|
action().catch(error => {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
|
|
||||||
export default class Action {
|
class Action {
|
||||||
static get supportedPlatforms() {
|
static get supportedPlatforms() {
|
||||||
return ['linux'];
|
return ['linux'];
|
||||||
}
|
}
|
||||||
|
@ -44,3 +44,5 @@ export default class Action {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export default Action;
|
||||||
|
|
|
@ -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;
|
|
@ -1,7 +1,7 @@
|
||||||
import { exec } from '@actions/exec';
|
import { exec } from '@actions/exec';
|
||||||
import ImageTag from './image-tag';
|
import ImageTag from './image-tag';
|
||||||
|
|
||||||
export default class Docker {
|
class Docker {
|
||||||
static async build(buildParameters, silent = false) {
|
static async build(buildParameters, silent = false) {
|
||||||
const { path, dockerfile, baseImage } = buildParameters;
|
const { path, dockerfile, baseImage } = buildParameters;
|
||||||
const { version, platform } = baseImage;
|
const { version, platform } = baseImage;
|
||||||
|
@ -18,8 +18,16 @@ export default class Docker {
|
||||||
}
|
}
|
||||||
|
|
||||||
static async run(image, parameters, silent = false) {
|
static async run(image, parameters, silent = false) {
|
||||||
const { workspace, platform, projectPath, buildName, buildsPath, method } = parameters;
|
const {
|
||||||
const { version } = image;
|
version,
|
||||||
|
workspace,
|
||||||
|
platform,
|
||||||
|
projectPath,
|
||||||
|
buildName,
|
||||||
|
buildPath,
|
||||||
|
buildFile,
|
||||||
|
buildMethod,
|
||||||
|
} = parameters;
|
||||||
|
|
||||||
const command = `docker run \
|
const command = `docker run \
|
||||||
--workdir /github/workspace \
|
--workdir /github/workspace \
|
||||||
|
@ -32,8 +40,9 @@ export default class Docker {
|
||||||
--env PROJECT_PATH=${projectPath} \
|
--env PROJECT_PATH=${projectPath} \
|
||||||
--env BUILD_TARGET=${platform} \
|
--env BUILD_TARGET=${platform} \
|
||||||
--env BUILD_NAME=${buildName} \
|
--env BUILD_NAME=${buildName} \
|
||||||
--env BUILDS_PATH=${buildsPath} \
|
--env BUILD_PATH=${buildPath} \
|
||||||
--env BUILD_METHOD=${method} \
|
--env BUILD_FILE=${buildFile} \
|
||||||
|
--env BUILD_METHOD=${buildMethod} \
|
||||||
--env HOME=/github/home \
|
--env HOME=/github/home \
|
||||||
--env GITHUB_REF \
|
--env GITHUB_REF \
|
||||||
--env GITHUB_SHA \
|
--env GITHUB_SHA \
|
||||||
|
@ -59,3 +68,5 @@ export default class Docker {
|
||||||
await exec(command, null, { silent });
|
await exec(command, null, { silent });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export default Docker;
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import { has, get, trimEnd, trimStart } from 'lodash-es';
|
import { has, get, trimEnd, trimStart } from 'lodash-es';
|
||||||
|
import Platform from './platform';
|
||||||
|
|
||||||
export default class ImageTag {
|
class ImageTag {
|
||||||
constructor(imageProperties) {
|
constructor(imageProperties) {
|
||||||
const {
|
const {
|
||||||
repository = 'gableroux',
|
repository = 'gableroux',
|
||||||
|
@ -13,14 +14,14 @@ export default class ImageTag {
|
||||||
throw new Error(`Invalid version "${version}".`);
|
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.`);
|
throw new Error(`Platform "${platform}" is currently not supported.`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const builderPlatform = get(
|
const builderPlatform = get(
|
||||||
ImageTag.targetPlatformToBuilderPlatformMap,
|
ImageTag.targetPlatformToImageSuffixMap,
|
||||||
platform,
|
platform,
|
||||||
ImageTag.builderPlatforms.generic,
|
ImageTag.imageSuffixes.generic,
|
||||||
);
|
);
|
||||||
|
|
||||||
Object.assign(this, { repository, name, version, platform, builderPlatform });
|
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$/;
|
return /^20\d{2}\.\d\.\w{3,4}|3$/;
|
||||||
}
|
}
|
||||||
|
|
||||||
static get builderPlatforms() {
|
static get imageSuffixes() {
|
||||||
return {
|
return {
|
||||||
generic: '',
|
generic: '',
|
||||||
webgl: 'webgl',
|
webgl: 'webgl',
|
||||||
|
@ -42,31 +43,31 @@ export default class ImageTag {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
static get targetPlatformToBuilderPlatformMap() {
|
static get targetPlatformToImageSuffixMap() {
|
||||||
const { generic, webgl, mac, windows, android, ios, facebook } = ImageTag.builderPlatforms;
|
const { generic, webgl, mac, windows, android, ios, facebook } = ImageTag.imageSuffixes;
|
||||||
|
|
||||||
// @see: https://docs.unity3d.com/ScriptReference/BuildTarget.html
|
// @see: https://docs.unity3d.com/ScriptReference/BuildTarget.html
|
||||||
return {
|
return {
|
||||||
StandaloneOSX: mac,
|
[Platform.types.StandaloneOSX]: mac,
|
||||||
StandaloneWindows: windows,
|
[Platform.types.StandaloneWindows]: windows,
|
||||||
StandaloneWindows64: windows,
|
[Platform.types.StandaloneWindows64]: windows,
|
||||||
StandaloneLinux64: windows,
|
[Platform.types.StandaloneLinux64]: windows,
|
||||||
iOS: ios,
|
[Platform.types.iOS]: ios,
|
||||||
Android: android,
|
[Platform.types.Android]: android,
|
||||||
WebGL: webgl,
|
[Platform.types.WebGL]: webgl,
|
||||||
WSAPlayer: windows,
|
[Platform.types.WSAPlayer]: windows,
|
||||||
PS4: windows,
|
[Platform.types.PS4]: windows,
|
||||||
XboxOne: windows,
|
[Platform.types.XboxOne]: windows,
|
||||||
tvOS: windows,
|
[Platform.types.tvOS]: windows,
|
||||||
Switch: windows,
|
[Platform.types.Switch]: windows,
|
||||||
// Unsupported
|
// Unsupported
|
||||||
Lumin: windows,
|
[Platform.types.Lumin]: windows,
|
||||||
BJM: windows,
|
[Platform.types.BJM]: windows,
|
||||||
Stadia: windows,
|
[Platform.types.Stadia]: windows,
|
||||||
Facebook: facebook,
|
[Platform.types.Facebook]: facebook,
|
||||||
NoTarget: generic,
|
[Platform.types.NoTarget]: generic,
|
||||||
// Test specific
|
// Test specific
|
||||||
Test: generic,
|
[Platform.types.Test]: generic,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,3 +85,5 @@ export default class ImageTag {
|
||||||
return `${image}:${tag}`;
|
return `${image}:${tag}`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export default ImageTag;
|
||||||
|
|
|
@ -1,22 +1,26 @@
|
||||||
|
import Platform from './platform';
|
||||||
|
|
||||||
const core = require('@actions/core');
|
const core = require('@actions/core');
|
||||||
|
|
||||||
export default class Input {
|
class Input {
|
||||||
static getFromUser() {
|
static getFromUser() {
|
||||||
// Input variables specified in workflows using "with" prop.
|
// Input variables specified in workflows using "with" prop.
|
||||||
const version = core.getInput('unityVersion');
|
const unityVersion = core.getInput('unityVersion');
|
||||||
const platform = core.getInput('targetPlatform');
|
const targetPlatform = core.getInput('targetPlatform') || Platform.default;
|
||||||
const projectPath = core.getInput('projectPath');
|
const projectPath = core.getInput('projectPath');
|
||||||
const buildName = core.getInput('buildName');
|
const buildName = core.getInput('buildName') || targetPlatform;
|
||||||
const buildsPath = core.getInput('buildsPath');
|
const buildsPath = core.getInput('buildsPath') || 'build';
|
||||||
const buildMethod = core.getInput('buildMethod');
|
const buildMethod = core.getInput('buildMethod'); // processed in docker file
|
||||||
|
|
||||||
return {
|
return {
|
||||||
version,
|
unityVersion,
|
||||||
platform,
|
targetPlatform,
|
||||||
projectPath,
|
projectPath,
|
||||||
buildName,
|
buildName,
|
||||||
buildsPath,
|
buildsPath,
|
||||||
method: buildMethod,
|
buildMethod,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export default Input;
|
||||||
|
|
|
@ -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;
|
Loading…
Reference in New Issue