Compare commits

..

11 Commits
v0.7 ... v0.9

Author SHA1 Message Date
Webber
6bff9d7c68 Update readme for 0.9 (custom parameters) 2020-01-27 20:42:52 +01:00
Webber
7d51d12262 Allow custom parameters 2020-01-27 20:42:52 +01:00
Webber
b382ae9023 Remove duplicate restore key 2020-01-26 01:34:34 +01:00
Webber
4c8f96d75c Add caching step in workflow 2020-01-26 01:34:34 +01:00
Webber
afddcfa5fd Move static tests to main workflow 2020-01-26 01:34:34 +01:00
Webber
ca2bcea3ad Minor cleanup 2020-01-26 01:34:34 +01:00
Webber
d5552eaa01 Further simplify activation and complete feedback to user 2020-01-21 21:59:49 +01:00
Webber
32081adc59 Remove debugging, switch -ne to -eq 2020-01-21 21:59:49 +01:00
Webber
ad034dd2a5 Simplify and fail faster for activation process 2020-01-21 21:59:49 +01:00
Webber
cad4a8a0e5 Simplify build-method implementation 2020-01-21 21:59:49 +01:00
Webber
1d1f81c0bb 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.
2020-01-21 00:28:05 +01:00
15 changed files with 270 additions and 153 deletions

View File

@@ -14,5 +14,8 @@ trim_trailing_whitespace = true
max_line_length = off max_line_length = off
trim_trailing_whitespace = false trim_trailing_whitespace = false
[*.{yml,yaml}]
max_line_length = off
[COMMIT_EDITMSG] [COMMIT_EDITMSG]
max_line_length = 0 max_line_length = off

View File

@@ -8,6 +8,20 @@ env:
UNITY_LICENSE: "<?xml version=\"1.0\" encoding=\"UTF-8\"?><root>\n <License id=\"Terms\">\n <MachineBindings>\n <Binding Key=\"1\" Value=\"d39b8e2f4d364b2e98b06afa0c6e08c5\"/>\n <Binding Key=\"2\" Value=\"d39b8e2f4d364b2e98b06afa0c6e08c5\"/>\n </MachineBindings>\n <MachineID Value=\"Xxo1ZKbdPu/IATrc0mPBYANJFF0=\"/>\n <SerialHash Value=\"1efd68fa935192b6090ac03c77d289a9f588c55a\"/>\n <Features>\n <Feature Value=\"33\"/>\n <Feature Value=\"1\"/>\n <Feature Value=\"12\"/>\n <Feature Value=\"2\"/>\n <Feature Value=\"24\"/>\n <Feature Value=\"3\"/>\n <Feature Value=\"36\"/>\n <Feature Value=\"17\"/>\n <Feature Value=\"19\"/>\n <Feature Value=\"62\"/>\n </Features>\n <DeveloperData Value=\"AQAAAEY0LUg2WFMtUE00NS1SM0M4LUUyWlotWkdWOA==\"/>\n <SerialMasked Value=\"F4-H6XS-PM45-R3C8-E2ZZ-XXXX\"/>\n <StartDate Value=\"2018-05-02T00:00:00\"/>\n <UpdateDate Value=\"2019-11-25T18:23:38\"/>\n <InitialActivationDate Value=\"2018-05-02T14:21:28\"/>\n <LicenseVersion Value=\"6.x\"/>\n <ClientProvidedVersion Value=\"2019.2.11f1\"/>\n <AlwaysOnline Value=\"false\"/>\n <Entitlements>\n <Entitlement Ns=\"unity_editor\" Tag=\"UnityPersonal\" Type=\"EDITOR\" ValidTo=\"9999-12-31T00:00:00\"/>\n </Entitlements>\n </License>\n<Signature xmlns=\"http://www.w3.org/2000/09/xmldsig#\"><SignedInfo><CanonicalizationMethod Algorithm=\"http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments\"/><SignatureMethod Algorithm=\"http://www.w3.org/2000/09/xmldsig#rsa-sha1\"/><Reference URI=\"#Terms\"><Transforms><Transform Algorithm=\"http://www.w3.org/2000/09/xmldsig#enveloped-signature\"/></Transforms><DigestMethod Algorithm=\"http://www.w3.org/2000/09/xmldsig#sha1\"/><DigestValue>JHdOBFmBNq2H8BrGFzir/StLoYo=</DigestValue></Reference></SignedInfo><SignatureValue>aENLHd37a51RtP2/g7YU0Pexf5mx0/ENXYGtrPzqwZ8NQt2AsSdxGnl0CUB45/GuNXfJVDt2HWot\ncNYZB2OylVBn1WHQbKZlPmm8gEAMz0MYbr4Isb5i5buryBrZlmbEOjnRI+pEg1CBwlgMo6xdtjjE\n/d7cC293QIUO91kdzRXftYou1dNaUyuPL9ZH65vdB2pDXGRNxgUVD+GnnqZA7b5L2HXqNQclcWAK\n5Yd1BeF3VzR1iLw9G/SmH5oOhnpXSmqbL4qk7LVP2/mgXpFk5kP4X8VC3z47obNhBIGq40dwWyEe\nUYk5/nRAOkZawDT+tcu96e06gPC9Cxk5PdbRbA==</SignatureValue></Signature></root>" UNITY_LICENSE: "<?xml version=\"1.0\" encoding=\"UTF-8\"?><root>\n <License id=\"Terms\">\n <MachineBindings>\n <Binding Key=\"1\" Value=\"d39b8e2f4d364b2e98b06afa0c6e08c5\"/>\n <Binding Key=\"2\" Value=\"d39b8e2f4d364b2e98b06afa0c6e08c5\"/>\n </MachineBindings>\n <MachineID Value=\"Xxo1ZKbdPu/IATrc0mPBYANJFF0=\"/>\n <SerialHash Value=\"1efd68fa935192b6090ac03c77d289a9f588c55a\"/>\n <Features>\n <Feature Value=\"33\"/>\n <Feature Value=\"1\"/>\n <Feature Value=\"12\"/>\n <Feature Value=\"2\"/>\n <Feature Value=\"24\"/>\n <Feature Value=\"3\"/>\n <Feature Value=\"36\"/>\n <Feature Value=\"17\"/>\n <Feature Value=\"19\"/>\n <Feature Value=\"62\"/>\n </Features>\n <DeveloperData Value=\"AQAAAEY0LUg2WFMtUE00NS1SM0M4LUUyWlotWkdWOA==\"/>\n <SerialMasked Value=\"F4-H6XS-PM45-R3C8-E2ZZ-XXXX\"/>\n <StartDate Value=\"2018-05-02T00:00:00\"/>\n <UpdateDate Value=\"2019-11-25T18:23:38\"/>\n <InitialActivationDate Value=\"2018-05-02T14:21:28\"/>\n <LicenseVersion Value=\"6.x\"/>\n <ClientProvidedVersion Value=\"2019.2.11f1\"/>\n <AlwaysOnline Value=\"false\"/>\n <Entitlements>\n <Entitlement Ns=\"unity_editor\" Tag=\"UnityPersonal\" Type=\"EDITOR\" ValidTo=\"9999-12-31T00:00:00\"/>\n </Entitlements>\n </License>\n<Signature xmlns=\"http://www.w3.org/2000/09/xmldsig#\"><SignedInfo><CanonicalizationMethod Algorithm=\"http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments\"/><SignatureMethod Algorithm=\"http://www.w3.org/2000/09/xmldsig#rsa-sha1\"/><Reference URI=\"#Terms\"><Transforms><Transform Algorithm=\"http://www.w3.org/2000/09/xmldsig#enveloped-signature\"/></Transforms><DigestMethod Algorithm=\"http://www.w3.org/2000/09/xmldsig#sha1\"/><DigestValue>JHdOBFmBNq2H8BrGFzir/StLoYo=</DigestValue></Reference></SignedInfo><SignatureValue>aENLHd37a51RtP2/g7YU0Pexf5mx0/ENXYGtrPzqwZ8NQt2AsSdxGnl0CUB45/GuNXfJVDt2HWot\ncNYZB2OylVBn1WHQbKZlPmm8gEAMz0MYbr4Isb5i5buryBrZlmbEOjnRI+pEg1CBwlgMo6xdtjjE\n/d7cC293QIUO91kdzRXftYou1dNaUyuPL9ZH65vdB2pDXGRNxgUVD+GnnqZA7b5L2HXqNQclcWAK\n5Yd1BeF3VzR1iLw9G/SmH5oOhnpXSmqbL4qk7LVP2/mgXpFk5kP4X8VC3z47obNhBIGq40dwWyEe\nUYk5/nRAOkZawDT+tcu96e06gPC9Cxk5PdbRbA==</SignatureValue></Signature></root>"
jobs: jobs:
tests:
name: Tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
with:
node-version: 12.x
- run: yarn
- run: yarn lint
- run: yarn test
- run: yarn build || { echo "build command should always succeed" ; exit 61; }
- run: yarn build --quiet && git diff --quiet builder || { echo "builder should be auto generated" ; exit 62; }
buildForAllPlatforms: buildForAllPlatforms:
name: Build for ${{ matrix.targetPlatform }} on version ${{ matrix.unityVersion }} name: Build for ${{ matrix.targetPlatform }} on version ${{ matrix.unityVersion }}
runs-on: ubuntu-latest runs-on: ubuntu-latest
@@ -35,6 +49,13 @@ jobs:
steps: steps:
- uses: actions/checkout@v1 - uses: actions/checkout@v1
- uses: actions/cache@v1.1.0
with:
path: ${{ matrix.projectPath }}/Library
key: Library-${{ matrix.projectPath }}-${{ matrix.targetPlatform }}
restore-keys: |
Library-${{ matrix.projectPath }}-
Library-
- uses: ./ - uses: ./
with: with:
projectPath: ${{ matrix.projectPath }} projectPath: ${{ matrix.projectPath }}

View File

@@ -1,19 +0,0 @@
name: Test Action
on:
pull_request: {}
push: { branches: [master] }
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
with:
node-version: 12.x
- run: yarn
- run: yarn lint
- run: yarn test
- run: yarn build || { echo "build command should always succeed" ; exit 61; }
- run: yarn build --quiet && git diff --quiet builder || { echo "builder should be auto generated" ; exit 62; }

View File

@@ -34,7 +34,7 @@ collection repository for workflow documentation and reference implementation.
Create or edit the file called `.github/workflows/main.yml` and add a job to it. Create or edit the file called `.github/workflows/main.yml` and add a job to it.
```yaml ```yaml
- uses: webbertakken/unity-builder@v0.5 - uses: webbertakken/unity-builder@v0.9
env: env:
UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }} UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }}
with: with:
@@ -82,7 +82,7 @@ jobs:
- Switch # Build a Nintendo Switch player. - Switch # Build a Nintendo Switch player.
steps: steps:
- uses: actions/checkout@v1 - uses: actions/checkout@v1
- uses: webbertakken/unity-builder@v0.5 - uses: webbertakken/unity-builder@v0.9
with: with:
projectPath: ${{ matrix.projectPath }} projectPath: ${{ matrix.projectPath }}
unityVersion: ${{ matrix.unityVersion }} unityVersion: ${{ matrix.unityVersion }}
@@ -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
@@ -161,6 +161,25 @@ _**example:**_
_**required:** `false`_ _**required:** `false`_
_**default:** Built-in script that will run a build out of the box._ _**default:** Built-in script that will run a build out of the box._
#### customParameters
Custom parameters to configure the build.
Parameters must start with a hyphen (`-`) and may be followed by a value (without hyphen).
Parameters without a value will be considered booleans (with a value of true).
_**example:**_
```yaml
- uses: webbertakken/unity-builder@master
with:
customParameters: -profile SomeProfile -someBoolean -someValue exampleValue
```
_**required:** `false`_
_**default:** ""_
## More actions ## More actions
Visit Visit

File diff suppressed because one or more lines are too long

View File

@@ -6,11 +6,11 @@ if [[ -n "$UNITY_LICENSE" ]]; then
# #
# This will activate Unity, using a license file # This will activate Unity, using a license file
# #
# Note that this is the ONLY WAY for PERSONAL LICENSES in 2019. # Note that this is the ONLY WAY for PERSONAL LICENSES in 2020.
# * See for more details: https://gitlab.com/gableroux/unity3d-gitlab-ci-example/issues/5#note_72815478 # * See for more details: https://gitlab.com/gableroux/unity3d-gitlab-ci-example/issues/5#note_72815478
# #
# The license file can be acquired using `webbertakken/request-manual-activation-file` action. # The license file can be acquired using `webbertakken/request-manual-activation-file` action.
LICENSE_MODE="personal" echo "Requesting activation (personal license)"
# Set the license file path # Set the license file path
FILE_PATH=UnityLicenseFile.ulf FILE_PATH=UnityLicenseFile.ulf
@@ -18,12 +18,7 @@ if [[ -n "$UNITY_LICENSE" ]]; then
# Copy license file from Github variables # Copy license file from Github variables
echo "$UNITY_LICENSE" | tr -d '\r' > $FILE_PATH echo "$UNITY_LICENSE" | tr -d '\r' > $FILE_PATH
#
# Activate license # Activate license
#
# This is expected to always exit with code 1 (both success and failure).
#
echo "Requesting activation"
ACTIVATION_OUTPUT=$(xvfb-run --auto-servernum --server-args='-screen 0 640x480x24' \ ACTIVATION_OUTPUT=$(xvfb-run --auto-servernum --server-args='-screen 0 640x480x24' \
/opt/Unity/Editor/Unity \ /opt/Unity/Editor/Unity \
-batchmode \ -batchmode \
@@ -31,17 +26,23 @@ if [[ -n "$UNITY_LICENSE" ]]; then
-logFile /dev/stdout \ -logFile /dev/stdout \
-quit \ -quit \
-manualLicenseFile $FILE_PATH) -manualLicenseFile $FILE_PATH)
# Convert to exit code 0 by echoing the current exit code.
echo $?
# Exit code is now 0
# TODO - remove debugging # Store the exit code from the verify command
echo $ACTIVATION_OUTPUT UNITY_EXIT_CODE=$?
echo $ACTIVATION_OUTPUT | grep 'config is NOT valid, switching to default'
echo $ACTIVATION_OUTPUT | grep 'config is NOT valid, switching to default' | wc -l
# TODO - Derive exit code by grepping success statement # The exit code for personal activation is always 1;
UNITY_EXIT_CODE=$(echo $ACTIVATION_OUTPUT | grep 'config is NOT valid, switching to default' | wc -l) # Determine whether activation was successful.
#
# Successful output should include the following:
#
# "LICENSE SYSTEM [2020120 18:51:20] Next license update check is after 2019-11-25T18:23:38"
#
ACTIVATION_SUCCESSFUL=$(echo $ACTIVATION_OUTPUT | grep 'Next license update check is after' | wc -l)
# Set exit code to 0 if activation was successful
if [[ $ACTIVATION_SUCCESSFUL -eq 1 ]]; then
UNITY_EXIT_CODE=0
fi;
# Remove license file # Remove license file
rm -f $FILE_PATH rm -f $FILE_PATH
@@ -54,8 +55,9 @@ elif [[ -n "$UNITY_SERIAL" && -n "$UNITY_EMAIL" && -n "$UNITY_PASSWORD" ]]; then
# #
# Note: This is the preferred way for PROFESSIONAL LICENSES. # Note: This is the preferred way for PROFESSIONAL LICENSES.
# #
LICENSE_MODE="professional" echo "Requesting activation (professional license)"
# Activate license
xvfb-run --auto-servernum --server-args='-screen 0 640x480x24' \ xvfb-run --auto-servernum --server-args='-screen 0 640x480x24' \
/opt/Unity/Editor/Unity \ /opt/Unity/Editor/Unity \
-batchmode \ -batchmode \
@@ -71,16 +73,18 @@ elif [[ -n "$UNITY_SERIAL" && -n "$UNITY_EMAIL" && -n "$UNITY_PASSWORD" ]]; then
else else
# #
# LICENSE ACTIVATION FAILED # NO LICENSE ACTIVATION STRATEGY MATCHED
# #
# This will exit since both personal and professional activation modes failed # This will exit since no activation strategies could be matched.
# #
echo "No personal or professional licenses provided!" echo "License activation strategy could not be determined."
echo "Please ensure you have setup one of these licensing methods:" echo ""
echo " - Personal: Set the UNITY_LICENSE environment variable." echo "Visit https://github.com/webbertakken/unity-builder#usage for more"
echo " - Professional: Set the UNITY_EMAIL, UNITY_PASSWORD and UNITY_SERIAL environment variables." echo "details on how to set up one of the possible activation strategies."
echo "See https://github.com/webbertakken/unity-builder#usage for details."
# Immediately exit as no UNITY_EXIT_CODE can be derrived.
exit 1; exit 1;
fi fi
# #
@@ -88,10 +92,10 @@ fi
# #
if [ $UNITY_EXIT_CODE -eq 0 ]; then if [ $UNITY_EXIT_CODE -eq 0 ]; then
# Activation was a success # Activation was a success
echo "Activation ($LICENSE_MODE) complete." echo "Activation complete."
else else
# Activation failed so exit with the code from the license verification step # Activation failed so exit with the code from the license verification step
echo "Unclassified error occured while trying to activate ($LICENSE_MODE) license." echo "Unclassified error occured while trying to activate license."
echo "Exit code was: $UNITY_EXIT_CODE" echo "Exit code was: $UNITY_EXIT_CODE"
exit $UNITY_EXIT_CODE exit $UNITY_EXIT_CODE
fi fi

View File

@@ -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,25 +46,26 @@ 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.
# Assume they also bring their own script. # Assume they also bring their own script.
# #
echo "User set build method to $BUILD_METHOD." echo "Using build method \"$BUILD_METHOD\"."
# #
fi fi
# Set build method to execute as flag + argument #
EXECUTE_BUILD_METHOD="-executeMethod $BUILD_METHOD" # Display custom parameters
#
echo "Using custom parameters \"$CUSTOM_PARAMETERS\"."
# The build specification below may require Unity 2019.2.11f1 or later (not tested below). # The build specification below may require Unity 2019.2.11f1 or later (not tested below).
# Reference: https://docs.unity3d.com/2019.3/Documentation/Manual/CommandLineArguments.html # Reference: https://docs.unity3d.com/2019.3/Documentation/Manual/CommandLineArguments.html
@@ -98,25 +74,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 "###########################"
@@ -142,7 +108,8 @@ xvfb-run --auto-servernum --server-args='-screen 0 640x480x24' \
-buildTarget "$BUILD_TARGET" \ -buildTarget "$BUILD_TARGET" \
-customBuildTarget "$BUILD_TARGET" \ -customBuildTarget "$BUILD_TARGET" \
-customBuildPath "$CUSTOM_BUILD_PATH" \ -customBuildPath "$CUSTOM_BUILD_PATH" \
$EXECUTE_BUILD_METHOD -executeMethod "$BUILD_METHOD" \
"$CUSTOM_PARAMETERS"
# Catch exit code # Catch exit code
BUILD_EXIT_CODE=$? BUILD_EXIT_CODE=$?
@@ -164,4 +131,4 @@ echo "# Build directory #"
echo "###########################" echo "###########################"
echo "" echo ""
ls -alh $CURRENT_BUILD_FULL_PATH ls -alh "$BUILD_PATH_FULL"

View File

@@ -1,7 +1,4 @@
import Action from './model/action'; import { Action, Docker, Input, ImageTag, BuildParameters } from './model';
import Docker from './model/docker';
import ImageTag from './model/image-tag';
import Input from './model/input';
const core = require('@actions/core'); const core = require('@actions/core');
@@ -9,12 +6,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 => {

View File

@@ -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;

View File

@@ -0,0 +1,40 @@
import Platform from './platform';
class BuildParameters {
static create(parameters) {
const {
unityVersion,
targetPlatform,
projectPath,
buildName,
buildsPath,
buildMethod,
customParameters,
} = parameters;
return {
version: unityVersion,
platform: targetPlatform,
projectPath,
buildName,
buildPath: `${buildsPath}/${targetPlatform}`,
buildFile: this.parseBuildFile(buildName, targetPlatform),
buildMethod,
customParameters,
};
}
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 { 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,17 @@ 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,
customParameters,
} = parameters;
const command = `docker run \ const command = `docker run \
--workdir /github/workspace \ --workdir /github/workspace \
@@ -32,8 +41,10 @@ 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 CUSTOM_PARAMETERS=${customParameters} \
--env HOME=/github/home \ --env HOME=/github/home \
--env GITHUB_REF \ --env GITHUB_REF \
--env GITHUB_SHA \ --env GITHUB_SHA \
@@ -59,3 +70,5 @@ export default class Docker {
await exec(command, null, { silent }); await exec(command, null, { silent });
} }
} }
export default Docker;

View File

@@ -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;

8
src/model/index.js Normal file
View File

@@ -0,0 +1,8 @@
import Action from './action';
import BuildParameters from './build-parameters';
import Docker from './docker';
import Input from './input';
import ImageTag from './image-tag';
import Platform from './platform';
export { Action, BuildParameters, Docker, Input, ImageTag, Platform };

View File

@@ -1,22 +1,28 @@
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
const customParameters = core.getInput('customParameters') || '';
return { return {
version, unityVersion,
platform, targetPlatform,
projectPath, projectPath,
buildName, buildName,
buildsPath, buildsPath,
method: buildMethod, buildMethod,
customParameters,
}; };
} }
} }
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;