mirror of
https://github.com/game-ci/unity-builder.git
synced 2026-01-30 04:49:08 +08:00
Compare commits
47 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2c1ef01beb | ||
|
|
dfccf539d1 | ||
|
|
c1a7c5f70b | ||
|
|
7e4851cc3a | ||
|
|
bbb5661b43 | ||
|
|
678fb210be | ||
|
|
90af9768a7 | ||
|
|
6ab433b631 | ||
|
|
d5c4c09fc4 | ||
|
|
3e69d63ec4 | ||
|
|
c47d5a4d2e | ||
|
|
9dd75201b0 | ||
|
|
308a9e173d | ||
|
|
f5a61eed4a | ||
|
|
051513bf4a | ||
|
|
d9382df690 | ||
|
|
0df7fa7855 | ||
|
|
d1c1d276e0 | ||
|
|
ad1f47dd3a | ||
|
|
a0d197e1fa | ||
|
|
cc244fa58b | ||
|
|
c70fdac383 | ||
|
|
81487e2140 | ||
|
|
ef06de9255 | ||
|
|
64499d66cc | ||
|
|
59ab903a78 | ||
|
|
2fa5b33111 | ||
|
|
0399609b07 | ||
|
|
1c91a3bf31 | ||
|
|
ae7f659e9f | ||
|
|
b781b891ec | ||
|
|
f3a984165e | ||
|
|
d8896dc4f5 | ||
|
|
4051832dc0 | ||
|
|
fe2311ef4b | ||
|
|
37d5ce498f | ||
|
|
6bff9d7c68 | ||
|
|
7d51d12262 | ||
|
|
b382ae9023 | ||
|
|
4c8f96d75c | ||
|
|
afddcfa5fd | ||
|
|
ca2bcea3ad | ||
|
|
d5552eaa01 | ||
|
|
32081adc59 | ||
|
|
ad034dd2a5 | ||
|
|
cad4a8a0e5 | ||
|
|
1d1f81c0bb |
@@ -2,4 +2,4 @@
|
||||
*
|
||||
|
||||
# Files required for the action
|
||||
!builder/
|
||||
!action/
|
||||
|
||||
@@ -14,5 +14,8 @@ trim_trailing_whitespace = true
|
||||
max_line_length = off
|
||||
trim_trailing_whitespace = false
|
||||
|
||||
[*.{yml,yaml}]
|
||||
max_line_length = off
|
||||
|
||||
[COMMIT_EDITMSG]
|
||||
max_line_length = 0
|
||||
max_line_length = off
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
**/node_modules/**
|
||||
**/builder/**
|
||||
**/action/**
|
||||
|
||||
28
.github/workflows/main.yml
vendored
28
.github/workflows/main.yml
vendored
@@ -6,8 +6,24 @@ on:
|
||||
|
||||
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>"
|
||||
CODECOV_TOKEN: '2f2eb890-30e2-4724-83eb-7633832cf0de'
|
||||
|
||||
jobs:
|
||||
tests:
|
||||
name: Tests
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/setup-node@v1
|
||||
with:
|
||||
node-version: 12.x
|
||||
- run: yarn
|
||||
- run: yarn lint
|
||||
- run: yarn test --coverage
|
||||
- run: bash <(curl -s https://codecov.io/bash)
|
||||
- run: yarn build || { echo "build command should always succeed" ; exit 61; }
|
||||
- run: yarn build --quiet && git diff --quiet action || { echo "action should be auto generated" ; git diff action ; exit 62; }
|
||||
|
||||
buildForAllPlatforms:
|
||||
name: Build for ${{ matrix.targetPlatform }} on version ${{ matrix.unityVersion }}
|
||||
runs-on: ubuntu-latest
|
||||
@@ -34,12 +50,22 @@ jobs:
|
||||
# - Switch # Build a Nintendo Switch player.
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
- uses: actions/checkout@v2
|
||||
with:
|
||||
lfs: true
|
||||
- uses: actions/cache@v1.1.0
|
||||
with:
|
||||
path: ${{ matrix.projectPath }}/Library
|
||||
key: Library-${{ matrix.projectPath }}-${{ matrix.targetPlatform }}
|
||||
restore-keys: |
|
||||
Library-${{ matrix.projectPath }}-
|
||||
Library-
|
||||
- uses: ./
|
||||
with:
|
||||
projectPath: ${{ matrix.projectPath }}
|
||||
unityVersion: ${{ matrix.unityVersion }}
|
||||
targetPlatform: ${{ matrix.targetPlatform }}
|
||||
customParameters: -profile SomeProfile -someBoolean -someValue exampleValue
|
||||
- uses: actions/upload-artifact@v1
|
||||
with:
|
||||
name: Build
|
||||
|
||||
19
.github/workflows/test.yml
vendored
19
.github/workflows/test.yml
vendored
@@ -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; }
|
||||
@@ -1,2 +1,2 @@
|
||||
**/node_modules/**
|
||||
**/dist/**
|
||||
**/action/**
|
||||
|
||||
129
README.md
129
README.md
@@ -1,6 +1,9 @@
|
||||
# Unity - Builder
|
||||
|
||||
[](https://github.com/webbertakken/unity-builder/actions?query=branch%3Amaster+event%3Apush+workflow%3A%22Actions+%F0%9F%98%8E%22)
|
||||
[](https://snyk.io/test/github/webbertakken/unity-builder)
|
||||
[](https://lgtm.com/projects/g/webbertakken/unity-builder/context:javascript)
|
||||
[](https://codecov.io/gh/webbertakken/unity-builder)
|
||||
|
||||
---
|
||||
|
||||
@@ -31,10 +34,24 @@ collection repository for workflow documentation and reference implementation.
|
||||
|
||||
## Usage
|
||||
|
||||
#### Setup builder
|
||||
|
||||
By default the enabled scenes from the project's settings will be built.
|
||||
|
||||
Create or edit the file called `.github/workflows/main.yml` and add a job to it.
|
||||
|
||||
##### Personal License
|
||||
|
||||
Personal licenses require a one-time manual activation step (per unity version).
|
||||
|
||||
Make sure you
|
||||
[acquire and activate](https://github.com/marketplace/actions/unity-request-activation-file)
|
||||
your license file and add it as a secret.
|
||||
|
||||
Then, define the build step as follows:
|
||||
|
||||
```yaml
|
||||
- uses: webbertakken/unity-builder@v0.5
|
||||
- uses: webbertakken/unity-builder@v0.11
|
||||
env:
|
||||
UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }}
|
||||
with:
|
||||
@@ -43,6 +60,75 @@ Create or edit the file called `.github/workflows/main.yml` and add a job to it.
|
||||
targetPlatform: WebGL
|
||||
```
|
||||
|
||||
##### Professional license
|
||||
|
||||
Professional licenses do not need any manual steps.
|
||||
|
||||
Instead, three variables will need to be set.
|
||||
|
||||
- `UNITY_EMAIL` (should contain the email address for your Unity account)
|
||||
- `UNITY_PASSWORD` (the password that you use to login to Unity)
|
||||
- `UNITY_SERIAL` (the serial provided by Unity)
|
||||
|
||||
Define the build step as follows:
|
||||
|
||||
```yaml
|
||||
- uses: webbertakken/unity-builder@v0.11
|
||||
env:
|
||||
UNITY_EMAIL: ${{ secrets.UNITY_EMAIL }}
|
||||
UNITY_PASSWORD: ${{ secrets.UNITY_PASSWORD }}
|
||||
UNITY_SERIAL: ${{ secrets.UNITY_SERIAL }}
|
||||
with:
|
||||
projectPath: path/to/your/project
|
||||
unityVersion: 2020.X.XXXX
|
||||
targetPlatform: WebGL
|
||||
```
|
||||
|
||||
That is all you need to build your project.
|
||||
|
||||
#### Storing the build
|
||||
|
||||
To be able to access your built files,
|
||||
they need to be uploaded as artifacts.
|
||||
To do this it is recommended to use Github Actions official
|
||||
[upload artifact action](https://github.com/marketplace/actions/upload-artifact)
|
||||
after any build action.
|
||||
|
||||
By default, Builder outputs it's builds to a folder named `build`.
|
||||
|
||||
Example:
|
||||
|
||||
```yaml
|
||||
- uses: actions/upload-artifact@v1
|
||||
with:
|
||||
name: Build
|
||||
path: build
|
||||
```
|
||||
|
||||
Builds can now be downloaded as Artifacts in the Actions tab.
|
||||
|
||||
#### Caching
|
||||
|
||||
In order to make builds run faster, you can cache Library files from previous
|
||||
builds. To do so simply add Github Actions official
|
||||
[cache action](https://github.com/marketplace/actions/cache) before any unity steps.
|
||||
|
||||
Example:
|
||||
|
||||
```yaml
|
||||
- uses: actions/cache@v1.1.0
|
||||
with:
|
||||
path: path/to/your/project/Library
|
||||
key: Library-MyProjectName-TargetPlatform
|
||||
restore-keys: |
|
||||
Library-MyProjectName-
|
||||
Library-
|
||||
```
|
||||
|
||||
This simple addition could speed up your build by more than 50%.
|
||||
|
||||
## Complete example
|
||||
|
||||
A complete workflow that builds every available platform could look like this:
|
||||
|
||||
```yaml
|
||||
@@ -81,8 +167,17 @@ jobs:
|
||||
- tvOS # Build to Apple's tvOS platform.
|
||||
- Switch # Build a Nintendo Switch player.
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
- uses: webbertakken/unity-builder@v0.5
|
||||
- uses: actions/checkout@v2
|
||||
with:
|
||||
lfs: true
|
||||
- uses: actions/cache@v1.1.0
|
||||
with:
|
||||
path: ${{ matrix.projectPath }}/Library
|
||||
key: Library-${{ matrix.projectPath }}-${{ matrix.targetPlatform }}
|
||||
restore-keys: |
|
||||
Library-${{ matrix.projectPath }}-
|
||||
Library-
|
||||
- uses: webbertakken/unity-builder@v0.11
|
||||
with:
|
||||
projectPath: ${{ matrix.projectPath }}
|
||||
unityVersion: ${{ matrix.unityVersion }}
|
||||
@@ -93,10 +188,7 @@ jobs:
|
||||
path: build
|
||||
```
|
||||
|
||||
> **Notes:**
|
||||
>
|
||||
> - Don't forget to replace _<test-project>_ with your project name.
|
||||
> - By default the enabled scenes from the project's settings will be built.
|
||||
> **Note:** _Environment variables are set for all jobs in the workflow like this._
|
||||
|
||||
## Configuration options
|
||||
|
||||
@@ -127,10 +219,10 @@ _**required:** `true`_
|
||||
|
||||
#### buildName
|
||||
|
||||
Name of the build.
|
||||
Name of the build. Also the folder in which the build will be stored within `buildsPath`.
|
||||
|
||||
_**required:** `false`_
|
||||
_**default:** `testBuild`_
|
||||
_**default:** `<build_target>`_
|
||||
|
||||
#### buildsPath
|
||||
|
||||
@@ -161,6 +253,25 @@ _**example:**_
|
||||
_**required:** `false`_
|
||||
_**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
|
||||
|
||||
Visit
|
||||
|
||||
@@ -32,4 +32,4 @@ branding:
|
||||
color: 'gray-dark'
|
||||
runs:
|
||||
using: 'node12'
|
||||
main: 'builder/index.js'
|
||||
main: 'action/index.js'
|
||||
|
||||
1
action/index.js
Normal file
1
action/index.js
Normal file
File diff suppressed because one or more lines are too long
@@ -6,11 +6,11 @@ if [[ -n "$UNITY_LICENSE" ]]; then
|
||||
#
|
||||
# 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
|
||||
#
|
||||
# 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
|
||||
FILE_PATH=UnityLicenseFile.ulf
|
||||
@@ -18,12 +18,7 @@ if [[ -n "$UNITY_LICENSE" ]]; then
|
||||
# Copy license file from Github variables
|
||||
echo "$UNITY_LICENSE" | tr -d '\r' > $FILE_PATH
|
||||
|
||||
#
|
||||
# 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' \
|
||||
/opt/Unity/Editor/Unity \
|
||||
-batchmode \
|
||||
@@ -31,17 +26,23 @@ if [[ -n "$UNITY_LICENSE" ]]; then
|
||||
-logFile /dev/stdout \
|
||||
-quit \
|
||||
-manualLicenseFile $FILE_PATH)
|
||||
# Convert to exit code 0 by echoing the current exit code.
|
||||
echo $?
|
||||
# Exit code is now 0
|
||||
|
||||
# TODO - remove debugging
|
||||
echo $ACTIVATION_OUTPUT
|
||||
echo $ACTIVATION_OUTPUT | grep 'config is NOT valid, switching to default'
|
||||
echo $ACTIVATION_OUTPUT | grep 'config is NOT valid, switching to default' | wc -l
|
||||
# Store the exit code from the verify command
|
||||
UNITY_EXIT_CODE=$?
|
||||
|
||||
# TODO - Derive exit code by grepping success statement
|
||||
UNITY_EXIT_CODE=$(echo $ACTIVATION_OUTPUT | grep 'config is NOT valid, switching to default' | wc -l)
|
||||
# The exit code for personal activation is always 1;
|
||||
# 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
|
||||
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.
|
||||
#
|
||||
LICENSE_MODE="professional"
|
||||
echo "Requesting activation (professional license)"
|
||||
|
||||
# Activate license
|
||||
xvfb-run --auto-servernum --server-args='-screen 0 640x480x24' \
|
||||
/opt/Unity/Editor/Unity \
|
||||
-batchmode \
|
||||
@@ -71,16 +73,18 @@ elif [[ -n "$UNITY_SERIAL" && -n "$UNITY_EMAIL" && -n "$UNITY_PASSWORD" ]]; then
|
||||
|
||||
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 "Please ensure you have setup one of these licensing methods:"
|
||||
echo " - Personal: Set the UNITY_LICENSE environment variable."
|
||||
echo " - Professional: Set the UNITY_EMAIL, UNITY_PASSWORD and UNITY_SERIAL environment variables."
|
||||
echo "See https://github.com/webbertakken/unity-builder#usage for details."
|
||||
echo "License activation strategy could not be determined."
|
||||
echo ""
|
||||
echo "Visit https://github.com/webbertakken/unity-builder#usage for more"
|
||||
echo "details on how to set up one of the possible activation strategies."
|
||||
|
||||
# Immediately exit as no UNITY_EXIT_CODE can be derrived.
|
||||
exit 1;
|
||||
|
||||
fi
|
||||
|
||||
#
|
||||
@@ -88,10 +92,10 @@ fi
|
||||
#
|
||||
if [ $UNITY_EXIT_CODE -eq 0 ]; then
|
||||
# Activation was a success
|
||||
echo "Activation ($LICENSE_MODE) complete."
|
||||
echo "Activation complete."
|
||||
else
|
||||
# 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"
|
||||
exit $UNITY_EXIT_CODE
|
||||
fi
|
||||
@@ -4,53 +4,28 @@
|
||||
# Set project path
|
||||
#
|
||||
|
||||
UNITY_PROJECT_PATH=$GITHUB_WORKSPACE/$PROJECT_PATH
|
||||
UNITY_PROJECT_PATH="$GITHUB_WORKSPACE/$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\"."
|
||||
|
||||
#
|
||||
# Set the builds 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)
|
||||
# Display the build's target platform;
|
||||
#
|
||||
|
||||
if [ -z "$BUILD_TARGET" ]; then
|
||||
BUILD_TARGET=WebGL
|
||||
fi
|
||||
echo "Using build target \"$BUILD_TARGET\"."
|
||||
|
||||
#
|
||||
# Set builds path
|
||||
# Display build path and file
|
||||
#
|
||||
|
||||
if [ -z "$BUILDS_PATH" ]; then
|
||||
BUILDS_PATH=build
|
||||
fi
|
||||
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\"."
|
||||
echo "Using build path \"$BUILD_PATH\" to save file \"$BUILD_FILE\"."
|
||||
BUILD_PATH_FULL="$GITHUB_WORKSPACE/$BUILD_PATH"
|
||||
CUSTOM_BUILD_PATH="$BUILD_PATH_FULL/$BUILD_FILE"
|
||||
|
||||
#
|
||||
# Set the build method, must reference one of:
|
||||
@@ -71,25 +46,26 @@ if [ -z "$BUILD_METHOD" ]; then
|
||||
#
|
||||
echo "Using built-in build method."
|
||||
# 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
|
||||
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
|
||||
BUILD_METHOD="UnityBuilderAction.Builder.BuildProject"
|
||||
# Verify recursive paths
|
||||
ls -Ralph $UNITY_PROJECT_PATH/Assets/Editor/
|
||||
ls -Ralph "$UNITY_PROJECT_PATH/Assets/Editor/"
|
||||
#
|
||||
else
|
||||
# User has provided their own build method.
|
||||
# Assume they also bring their own script.
|
||||
#
|
||||
echo "User set build method to $BUILD_METHOD."
|
||||
echo "Using build method \"$BUILD_METHOD\"."
|
||||
#
|
||||
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).
|
||||
# Reference: https://docs.unity3d.com/2019.3/Documentation/Manual/CommandLineArguments.html
|
||||
@@ -98,25 +74,15 @@ EXECUTE_BUILD_METHOD="-executeMethod $BUILD_METHOD"
|
||||
# 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 "# Current build dir #"
|
||||
echo "###########################"
|
||||
echo ""
|
||||
|
||||
echo "Creating \"$CURRENT_BUILD_FULL_PATH\" if it does not exist."exist."
|
||||
mkdir -p $CURRENT_BUILD_FULL_PATH
|
||||
ls -alh $CURRENT_BUILD_FULL_PATH
|
||||
echo "Creating \"$BUILD_PATH_FULL\" if it does not exist."
|
||||
mkdir -p "$BUILD_PATH_FULL"
|
||||
ls -alh "$BUILD_PATH_FULL"
|
||||
|
||||
echo ""
|
||||
echo "###########################"
|
||||
@@ -142,7 +108,8 @@ xvfb-run --auto-servernum --server-args='-screen 0 640x480x24' \
|
||||
-buildTarget "$BUILD_TARGET" \
|
||||
-customBuildTarget "$BUILD_TARGET" \
|
||||
-customBuildPath "$CUSTOM_BUILD_PATH" \
|
||||
$EXECUTE_BUILD_METHOD
|
||||
-executeMethod "$BUILD_METHOD" \
|
||||
$CUSTOM_PARAMETERS
|
||||
|
||||
# Catch exit code
|
||||
BUILD_EXIT_CODE=$?
|
||||
@@ -164,4 +131,4 @@ echo "# Build directory #"
|
||||
echo "###########################"
|
||||
echo ""
|
||||
|
||||
ls -alh $CURRENT_BUILD_FULL_PATH
|
||||
ls -alh "$BUILD_PATH_FULL"
|
||||
File diff suppressed because one or more lines are too long
38
package.json
38
package.json
@@ -2,44 +2,44 @@
|
||||
"name": "unity-builder",
|
||||
"version": "0.5.0",
|
||||
"description": "Build Unity projects for different platforms.",
|
||||
"main": "builder/index.js",
|
||||
"main": "action/index.js",
|
||||
"repository": "git@github.com:webbertakken/unity-builder.git",
|
||||
"author": "Webber <webber@takken.io>",
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"build": "ncc build src --out builder --minify",
|
||||
"build": "ncc build src --out action --minify",
|
||||
"lint": "prettier --check \"src/**/*.js\" && eslint src",
|
||||
"test": "jest"
|
||||
},
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.2.0",
|
||||
"@actions/exec": "1.0.2",
|
||||
"@actions/github": "^2.0.0"
|
||||
"@actions/core": "^1.2.2",
|
||||
"@actions/exec": "1.0.3",
|
||||
"@actions/github": "^2.0.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/cli": "7.7.5",
|
||||
"@babel/core": "7.7.5",
|
||||
"@babel/preset-env": "7.7.7",
|
||||
"@zeit/ncc": "0.20.5",
|
||||
"@babel/cli": "7.8.4",
|
||||
"@babel/core": "7.8.4",
|
||||
"@babel/preset-env": "7.8.4",
|
||||
"@zeit/ncc": "0.21.0",
|
||||
"babel-eslint": "10.0.3",
|
||||
"eslint": "6.7.2",
|
||||
"eslint": "6.8.0",
|
||||
"eslint-config-airbnb": "18.0.1",
|
||||
"eslint-config-prettier": "6.7.0",
|
||||
"eslint-plugin-flowtype": "4.5.2",
|
||||
"eslint-plugin-import": "2.19.1",
|
||||
"eslint-config-prettier": "6.10.0",
|
||||
"eslint-plugin-flowtype": "4.6.0",
|
||||
"eslint-plugin-import": "2.20.1",
|
||||
"eslint-plugin-jsx-a11y": "6.2.3",
|
||||
"eslint-plugin-prettier": "3.1.2",
|
||||
"eslint-plugin-react": "7.17.0",
|
||||
"eslint-plugin-unicorn": "14.0.1",
|
||||
"husky": "4.0.0-beta.5",
|
||||
"jest": "24.9.0",
|
||||
"lint-staged": "9.5.0",
|
||||
"eslint-plugin-react": "7.18.3",
|
||||
"eslint-plugin-unicorn": "16.0.0",
|
||||
"husky": "4.2.1",
|
||||
"jest": "25.1.0",
|
||||
"lint-staged": "10.0.7",
|
||||
"lodash-es": "4.17.15",
|
||||
"prettier": "1.19.1"
|
||||
},
|
||||
"husky": {
|
||||
"hooks": {
|
||||
"pre-commit": "lint-staged && yarn build && git add builder/index.js"
|
||||
"pre-commit": "lint-staged && yarn build && git add action/index.js"
|
||||
}
|
||||
},
|
||||
"lint-staged": {
|
||||
|
||||
18
src/index.js
18
src/index.js
@@ -1,20 +1,20 @@
|
||||
import Action from './model/action';
|
||||
import Docker from './model/docker';
|
||||
import ImageTag from './model/image-tag';
|
||||
import Input from './model/input';
|
||||
import { Action, BuildParameters, Cache, Docker, Input, ImageTag } from './model';
|
||||
|
||||
const core = require('@actions/core');
|
||||
|
||||
async function action() {
|
||||
Action.checkCompatibility();
|
||||
Cache.verify();
|
||||
|
||||
const { dockerfile, workspace, builderFolder } = Action;
|
||||
const { version, platform, projectPath, buildName, buildsPath, method } = Input.getFromUser();
|
||||
const { dockerfile, workspace, actionFolder } = Action;
|
||||
const buildParameters = BuildParameters.create(Input.getFromUser());
|
||||
const baseImage = new ImageTag(buildParameters);
|
||||
|
||||
const baseImage = new ImageTag({ version, platform });
|
||||
const builtImage = await Docker.build({ path: builderFolder, dockerfile, baseImage });
|
||||
// Build docker image
|
||||
const builtImage = await Docker.build({ path: actionFolder, dockerfile, baseImage });
|
||||
|
||||
await Docker.run(builtImage, { workspace, platform, projectPath, buildName, buildsPath, method });
|
||||
// Run docker image
|
||||
await Docker.run(builtImage, { workspace, ...buildParameters });
|
||||
}
|
||||
|
||||
action().catch(error => {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import path from 'path';
|
||||
|
||||
export default class Action {
|
||||
class Action {
|
||||
static get supportedPlatforms() {
|
||||
return ['linux'];
|
||||
}
|
||||
@@ -25,12 +25,12 @@ export default class Action {
|
||||
return path.dirname(path.dirname(__filename));
|
||||
}
|
||||
|
||||
static get builderFolder() {
|
||||
return `${Action.rootFolder}/builder`;
|
||||
static get actionFolder() {
|
||||
return `${Action.rootFolder}/action`;
|
||||
}
|
||||
|
||||
static get dockerfile() {
|
||||
return `${Action.builderFolder}/Dockerfile`;
|
||||
return `${Action.actionFolder}/Dockerfile`;
|
||||
}
|
||||
|
||||
static get workspace() {
|
||||
@@ -44,3 +44,5 @@ export default class Action {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default Action;
|
||||
|
||||
@@ -20,11 +20,11 @@ describe('Action', () => {
|
||||
expect(fs.existsSync(rootFolder)).toStrictEqual(true);
|
||||
});
|
||||
|
||||
it('returns the builder folder', () => {
|
||||
const { builderFolder } = Action;
|
||||
it('returns the action folder', () => {
|
||||
const { actionFolder } = Action;
|
||||
|
||||
expect(path.basename(builderFolder)).toStrictEqual('builder');
|
||||
expect(fs.existsSync(builderFolder)).toStrictEqual(true);
|
||||
expect(path.basename(actionFolder)).toStrictEqual('action');
|
||||
expect(fs.existsSync(actionFolder)).toStrictEqual(true);
|
||||
});
|
||||
|
||||
it('returns the docker file', () => {
|
||||
|
||||
40
src/model/build-parameters.js
Normal file
40
src/model/build-parameters.js
Normal 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;
|
||||
85
src/model/build-parameters.test.js
Normal file
85
src/model/build-parameters.test.js
Normal file
@@ -0,0 +1,85 @@
|
||||
import BuildParameters from './build-parameters';
|
||||
import Platform from './platform';
|
||||
|
||||
describe('BuildParameters', () => {
|
||||
describe('create', () => {
|
||||
const someParameters = {
|
||||
unityVersion: 'someVersion',
|
||||
targetPlatform: 'somePlatform',
|
||||
projectPath: 'path/to/project',
|
||||
buildName: 'someBuildName',
|
||||
buildsPath: 'someBuildsPath',
|
||||
buildMethod: 'Namespace.Class.Method',
|
||||
customParameters: '-someParam someValue',
|
||||
};
|
||||
|
||||
it('does not throw', () => {
|
||||
expect(() => BuildParameters.create(someParameters)).not.toThrow();
|
||||
});
|
||||
|
||||
it('returns the version', () => {
|
||||
expect(BuildParameters.create(someParameters).version).toStrictEqual(
|
||||
someParameters.unityVersion,
|
||||
);
|
||||
});
|
||||
|
||||
it('returns the platform', () => {
|
||||
expect(BuildParameters.create(someParameters).platform).toStrictEqual(
|
||||
someParameters.targetPlatform,
|
||||
);
|
||||
});
|
||||
|
||||
it('returns the project path', () => {
|
||||
expect(BuildParameters.create(someParameters).projectPath).toStrictEqual(
|
||||
someParameters.projectPath,
|
||||
);
|
||||
});
|
||||
|
||||
it('returns the build name', () => {
|
||||
expect(BuildParameters.create(someParameters).buildName).toStrictEqual(
|
||||
someParameters.buildName,
|
||||
);
|
||||
});
|
||||
|
||||
it('returns the build path', () => {
|
||||
expect(BuildParameters.create(someParameters).buildPath).toStrictEqual(
|
||||
`${someParameters.buildsPath}/${someParameters.targetPlatform}`,
|
||||
);
|
||||
});
|
||||
|
||||
describe('build file', () => {
|
||||
it('returns the build file', () => {
|
||||
expect(BuildParameters.create(someParameters).buildFile).toStrictEqual(
|
||||
someParameters.buildName,
|
||||
);
|
||||
});
|
||||
|
||||
test.each([Platform.types.StandaloneWindows, Platform.types.StandaloneWindows64])(
|
||||
'appends exe for %s',
|
||||
targetPlatform => {
|
||||
expect(
|
||||
BuildParameters.create({ ...someParameters, targetPlatform }).buildFile,
|
||||
).toStrictEqual(`${someParameters.buildName}.exe`);
|
||||
},
|
||||
);
|
||||
|
||||
test.each([Platform.types.Android])('appends apk for %s', targetPlatform => {
|
||||
expect(
|
||||
BuildParameters.create({ ...someParameters, targetPlatform }).buildFile,
|
||||
).toStrictEqual(`${someParameters.buildName}.apk`);
|
||||
});
|
||||
});
|
||||
|
||||
it('returns the build method', () => {
|
||||
expect(BuildParameters.create(someParameters).buildMethod).toStrictEqual(
|
||||
someParameters.buildMethod,
|
||||
);
|
||||
});
|
||||
|
||||
it('returns the custom parameters', () => {
|
||||
expect(BuildParameters.create(someParameters).customParameters).toStrictEqual(
|
||||
someParameters.customParameters,
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
25
src/model/cache.js
Normal file
25
src/model/cache.js
Normal file
@@ -0,0 +1,25 @@
|
||||
import fs from 'fs';
|
||||
import Action from './action';
|
||||
import Project from './project';
|
||||
|
||||
class Cache {
|
||||
static verify() {
|
||||
if (!fs.existsSync(Project.libraryFolder)) {
|
||||
this.notifyAboutCachingPossibility();
|
||||
}
|
||||
}
|
||||
|
||||
static notifyAboutCachingPossibility() {
|
||||
if (Action.isRunningLocally) {
|
||||
return;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(`
|
||||
Library folder does not exist.
|
||||
Consider setting up caching to speed up your workflow
|
||||
If this is not your first build.`);
|
||||
}
|
||||
}
|
||||
|
||||
export default Cache;
|
||||
9
src/model/cache.test.js
Normal file
9
src/model/cache.test.js
Normal file
@@ -0,0 +1,9 @@
|
||||
import Cache from './cache';
|
||||
|
||||
describe('Cache', () => {
|
||||
describe('Verification', () => {
|
||||
it('does not throw', () => {
|
||||
expect(() => Cache.verify()).not.toThrow();
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -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,17 @@ 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,
|
||||
customParameters,
|
||||
} = parameters;
|
||||
|
||||
const command = `docker run \
|
||||
--workdir /github/workspace \
|
||||
@@ -28,12 +37,14 @@ export default class Docker {
|
||||
--env UNITY_EMAIL \
|
||||
--env UNITY_PASSWORD \
|
||||
--env UNITY_SERIAL \
|
||||
--env UNITY_VERSION=${version} \
|
||||
--env PROJECT_PATH=${projectPath} \
|
||||
--env BUILD_TARGET=${platform} \
|
||||
--env BUILD_NAME=${buildName} \
|
||||
--env BUILDS_PATH=${buildsPath} \
|
||||
--env BUILD_METHOD=${method} \
|
||||
--env UNITY_VERSION="${version}" \
|
||||
--env PROJECT_PATH="${projectPath}" \
|
||||
--env BUILD_TARGET="${platform}" \
|
||||
--env BUILD_NAME="${buildName}" \
|
||||
--env BUILD_PATH="${buildPath}" \
|
||||
--env BUILD_FILE="${buildFile}" \
|
||||
--env BUILD_METHOD="${buildMethod}" \
|
||||
--env CUSTOM_PARAMETERS="${customParameters}" \
|
||||
--env HOME=/github/home \
|
||||
--env GITHUB_REF \
|
||||
--env GITHUB_SHA \
|
||||
@@ -59,3 +70,5 @@ export default class Docker {
|
||||
await exec(command, null, { silent });
|
||||
}
|
||||
}
|
||||
|
||||
export default Docker;
|
||||
|
||||
@@ -4,7 +4,7 @@ import ImageTag from './image-tag';
|
||||
|
||||
describe('Docker', () => {
|
||||
it('builds', async () => {
|
||||
const path = Action.builderFolder;
|
||||
const path = Action.actionFolder;
|
||||
const dockerfile = `${path}/Dockerfile`;
|
||||
const baseImage = new ImageTag({
|
||||
repository: '',
|
||||
|
||||
@@ -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;
|
||||
|
||||
11
src/model/index.js
Normal file
11
src/model/index.js
Normal file
@@ -0,0 +1,11 @@
|
||||
import Action from './action';
|
||||
import BuildParameters from './build-parameters';
|
||||
import Cache from './cache';
|
||||
import Docker from './docker';
|
||||
import Input from './input';
|
||||
import ImageTag from './image-tag';
|
||||
import Platform from './platform';
|
||||
import Project from './project';
|
||||
import Unity from './unity';
|
||||
|
||||
export { Action, BuildParameters, Cache, Docker, Input, ImageTag, Platform, Project, Unity };
|
||||
17
src/model/index.test.js
Normal file
17
src/model/index.test.js
Normal file
@@ -0,0 +1,17 @@
|
||||
import * as Index from '.';
|
||||
|
||||
describe('Index', () => {
|
||||
test.each([
|
||||
'Action',
|
||||
'BuildParameters',
|
||||
'Cache',
|
||||
'Docker',
|
||||
'Input',
|
||||
'ImageTag',
|
||||
'Platform',
|
||||
'Project',
|
||||
'Unity',
|
||||
])('exports %s', exportedModule => {
|
||||
expect(typeof Index[exportedModule]).toStrictEqual('function');
|
||||
});
|
||||
});
|
||||
@@ -1,22 +1,32 @@
|
||||
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 projectPath = core.getInput('projectPath');
|
||||
const buildName = core.getInput('buildName');
|
||||
const buildsPath = core.getInput('buildsPath');
|
||||
const buildMethod = core.getInput('buildMethod');
|
||||
const unityVersion = core.getInput('unityVersion');
|
||||
const targetPlatform = core.getInput('targetPlatform') || Platform.default;
|
||||
const rawProjectPath = core.getInput('projectPath') || '.';
|
||||
const buildName = core.getInput('buildName') || targetPlatform;
|
||||
const buildsPath = core.getInput('buildsPath') || 'build';
|
||||
const buildMethod = core.getInput('buildMethod'); // processed in docker file
|
||||
const customParameters = core.getInput('customParameters') || '';
|
||||
|
||||
// Sanitise input
|
||||
const projectPath = rawProjectPath.replace(/\/$/, '');
|
||||
|
||||
// Return sanitised input
|
||||
return {
|
||||
version,
|
||||
platform,
|
||||
unityVersion,
|
||||
targetPlatform,
|
||||
projectPath,
|
||||
buildName,
|
||||
buildsPath,
|
||||
method: buildMethod,
|
||||
buildMethod,
|
||||
customParameters,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export default Input;
|
||||
|
||||
@@ -5,5 +5,9 @@ describe('Input', () => {
|
||||
it('does not throw', () => {
|
||||
expect(() => Input.getFromUser()).not.toThrow();
|
||||
});
|
||||
|
||||
it('returns an object', () => {
|
||||
expect(typeof Input.getFromUser()).toStrictEqual('object');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
51
src/model/platform.js
Normal file
51
src/model/platform.js
Normal 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;
|
||||
37
src/model/platform.test.js
Normal file
37
src/model/platform.test.js
Normal file
@@ -0,0 +1,37 @@
|
||||
import Platform from './platform';
|
||||
|
||||
describe('Platform', () => {
|
||||
describe('default', () => {
|
||||
it('does not throw', () => {
|
||||
expect(() => Platform.default).not.toThrow();
|
||||
});
|
||||
|
||||
it('returns a string', () => {
|
||||
expect(typeof Platform.default).toStrictEqual('string');
|
||||
});
|
||||
|
||||
it('returns a platform', () => {
|
||||
expect(Object.values(Platform.types)).toContain(Platform.default);
|
||||
});
|
||||
});
|
||||
|
||||
describe('isWindows', () => {
|
||||
it('returns true for windows', () => {
|
||||
expect(Platform.isWindows(Platform.types.StandaloneWindows64)).toStrictEqual(true);
|
||||
});
|
||||
|
||||
it('returns false for MacOS', () => {
|
||||
expect(Platform.isWindows(Platform.types.StandaloneOSX)).toStrictEqual(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('isAndroid', () => {
|
||||
it('returns true for Android', () => {
|
||||
expect(Platform.isAndroid(Platform.types.Android)).toStrictEqual(true);
|
||||
});
|
||||
|
||||
it('returns false for Windows', () => {
|
||||
expect(Platform.isAndroid(Platform.types.StandaloneWindows64)).toStrictEqual(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
23
src/model/project.js
Normal file
23
src/model/project.js
Normal file
@@ -0,0 +1,23 @@
|
||||
import Unity from './unity';
|
||||
import Input from './input';
|
||||
import Action from './action';
|
||||
|
||||
class Project {
|
||||
static get relativePath() {
|
||||
const { projectPath } = Input.getFromUser();
|
||||
|
||||
return `${projectPath}`;
|
||||
}
|
||||
|
||||
static get absolutePath() {
|
||||
const { workspace } = Action;
|
||||
|
||||
return `${workspace}/${this.relativePath}`;
|
||||
}
|
||||
|
||||
static get libraryFolder() {
|
||||
return `${this.relativePath}/${Unity.libraryFolder}`;
|
||||
}
|
||||
}
|
||||
|
||||
export default Project;
|
||||
33
src/model/project.test.js
Normal file
33
src/model/project.test.js
Normal file
@@ -0,0 +1,33 @@
|
||||
import Project from './project';
|
||||
|
||||
describe('Platform', () => {
|
||||
describe('relativePath', () => {
|
||||
it('does not throw', () => {
|
||||
expect(() => Project.relativePath).not.toThrow();
|
||||
});
|
||||
|
||||
it('returns a string', () => {
|
||||
expect(typeof Project.relativePath).toStrictEqual('string');
|
||||
});
|
||||
});
|
||||
|
||||
describe('absolutePath', () => {
|
||||
it('does not throw', () => {
|
||||
expect(() => Project.absolutePath).not.toThrow();
|
||||
});
|
||||
|
||||
it('returns a string', () => {
|
||||
expect(typeof Project.absolutePath).toStrictEqual('string');
|
||||
});
|
||||
});
|
||||
|
||||
describe('libraryFolder', () => {
|
||||
it('does not throw', () => {
|
||||
expect(() => Project.libraryFolder).not.toThrow();
|
||||
});
|
||||
|
||||
it('returns a string', () => {
|
||||
expect(typeof Project.libraryFolder).toStrictEqual('string');
|
||||
});
|
||||
});
|
||||
});
|
||||
7
src/model/unity.js
Normal file
7
src/model/unity.js
Normal file
@@ -0,0 +1,7 @@
|
||||
class Unity {
|
||||
static get libraryFolder() {
|
||||
return 'Library';
|
||||
}
|
||||
}
|
||||
|
||||
export default Unity;
|
||||
13
src/model/unity.test.js
Normal file
13
src/model/unity.test.js
Normal file
@@ -0,0 +1,13 @@
|
||||
import Unity from './unity';
|
||||
|
||||
describe('Unity', () => {
|
||||
describe('libraryFolder', () => {
|
||||
it('does not throw', () => {
|
||||
expect(() => Unity.libraryFolder).not.toThrow();
|
||||
});
|
||||
|
||||
it('returns a string', () => {
|
||||
expect(typeof Unity.libraryFolder).toStrictEqual('string');
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user