mirror of
https://github.com/game-ci/unity-builder.git
synced 2026-02-02 14:49:08 +08:00
Compare commits
30 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
948a53575b | ||
|
|
5abc3164f9 | ||
|
|
3ae2ac1bb9 | ||
|
|
250a665fce | ||
|
|
7c90cddd43 | ||
|
|
ed7918e4f4 | ||
|
|
b4a1f1ab7b | ||
|
|
bafc8e806b | ||
|
|
2ab738c083 | ||
|
|
9a639e97e3 | ||
|
|
0130f1d603 | ||
|
|
454ff6054c | ||
|
|
dccdec9d3b | ||
|
|
0bb0dbd7be | ||
|
|
4312758325 | ||
|
|
302bd4c880 | ||
|
|
25294aec32 | ||
|
|
ae18dc32c9 | ||
|
|
69c4feba8f | ||
|
|
119a2b3b02 | ||
|
|
b385278dec | ||
|
|
9996187855 | ||
|
|
093eb69424 | ||
|
|
26f0080aae | ||
|
|
f7727333bf | ||
|
|
f14fe9806a | ||
|
|
c53fa402db | ||
|
|
b955df1dcb | ||
|
|
9a21280b09 | ||
|
|
e9496f5ba2 |
18
.editorconfig
Normal file
18
.editorconfig
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
root = true
|
||||||
|
|
||||||
|
[*]
|
||||||
|
charset = utf-8
|
||||||
|
end_of_line = lf
|
||||||
|
indent_size = 2
|
||||||
|
indent_style = space
|
||||||
|
insert_final_newline = true
|
||||||
|
max_line_length = 100
|
||||||
|
tab_width = 2
|
||||||
|
trim_trailing_whitespace = true
|
||||||
|
|
||||||
|
[*.md]
|
||||||
|
max_line_length = 0
|
||||||
|
trim_trailing_whitespace = false
|
||||||
|
|
||||||
|
[COMMIT_EDITMSG]
|
||||||
|
max_line_length = 0
|
||||||
2
.eslintignore
Normal file
2
.eslintignore
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
**/node_modules/**
|
||||||
|
**/dist/**
|
||||||
21
.eslintrc.json
Normal file
21
.eslintrc.json
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
{
|
||||||
|
"parser": "babel-eslint",
|
||||||
|
"env": {
|
||||||
|
"node": true,
|
||||||
|
"es6": true,
|
||||||
|
"jest": true
|
||||||
|
},
|
||||||
|
"parserOptions": {
|
||||||
|
"ecmaVersion": 2020,
|
||||||
|
"ecmaFeatures": {
|
||||||
|
"impliedStrict": true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"extends": ["airbnb", "plugin:unicorn/recommended", "prettier"],
|
||||||
|
"plugins": ["react", "jsx-a11y", "import", "prettier", "flowtype", "unicorn"],
|
||||||
|
"settings": { "react": { "version": "latest" } },
|
||||||
|
"rules": {
|
||||||
|
"prettier/prettier": "error",
|
||||||
|
"import/no-extraneous-dependencies": 0
|
||||||
|
}
|
||||||
|
}
|
||||||
76
.github/workflows/main.yml
vendored
76
.github/workflows/main.yml
vendored
@@ -1,42 +1,54 @@
|
|||||||
name: Actions 😎
|
name: Actions 😎
|
||||||
|
|
||||||
on:
|
on:
|
||||||
pull_request: {}
|
pull_request: {}
|
||||||
push: { branches: [master] }
|
push: { branches: [master] }
|
||||||
|
|
||||||
|
env:
|
||||||
|
UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }}
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
buildForWebGL:
|
buildForAllPlatforms:
|
||||||
name: Build for WebGL 🕸
|
name: Build for ${{ matrix.targetPlatform }} on version ${{ matrix.unityVersion }}
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
projectPath:
|
||||||
|
- test-project
|
||||||
|
unityVersion:
|
||||||
|
- 2019.2.11f1
|
||||||
|
# - 2019.3.0f1 # requires unity-activate to upgrade
|
||||||
|
targetPlatform:
|
||||||
|
- WebGL
|
||||||
|
- iOS
|
||||||
|
# - StandaloneOSX
|
||||||
|
# - StandaloneWindows
|
||||||
|
# - StandaloneWindows64
|
||||||
|
# - StandaloneLinux64
|
||||||
|
# - PS4
|
||||||
|
# - XboxOne
|
||||||
|
# - Switch
|
||||||
|
# - Android
|
||||||
|
# - tvOS
|
||||||
|
# - Lumin
|
||||||
|
# - BJM
|
||||||
|
# - Stadia
|
||||||
|
# - WSAPlayer
|
||||||
|
# - Facebook
|
||||||
|
# - NoTarget
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
# Checkout repository (required to test local actions)
|
- uses: actions/checkout@v1
|
||||||
- name: Checkout repository
|
- uses: webbertakken/unity-activate@v1
|
||||||
uses: actions/checkout@v1
|
- uses: ./
|
||||||
|
with:
|
||||||
# Activate license
|
projectPath: ${{ matrix.projectPath }}
|
||||||
- name: Activate license
|
unityVersion: ${{ matrix.unityVersion }}
|
||||||
uses: webbertakken/unity-activate@v1
|
targetPlatform: ${{ matrix.targetPlatform }}
|
||||||
env:
|
- uses: webbertakken/unity-return-license@v1
|
||||||
UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }}
|
if: always()
|
||||||
|
- uses: actions/upload-artifact@v1
|
||||||
# Configure builder
|
|
||||||
- name: Build project
|
|
||||||
id: buildStep
|
|
||||||
uses: ./
|
|
||||||
env:
|
|
||||||
UNITY_PROJECT_PATH: test-project
|
|
||||||
BUILD_NAME: TestBuild
|
|
||||||
BUILD_TARGET: WebGL
|
|
||||||
BUILDS_PATH: builds
|
|
||||||
BUILD_METHOD: ""
|
|
||||||
|
|
||||||
# Upload distributables
|
|
||||||
- name: Upload Build
|
|
||||||
uses: actions/upload-artifact@v1
|
|
||||||
with:
|
with:
|
||||||
name: Build
|
name: Build
|
||||||
path: ${{ steps.buildStep.outputs.allBuildsPath }}
|
path: build
|
||||||
|
|
||||||
# Return license
|
|
||||||
- name: Return License
|
|
||||||
uses: webbertakken/unity-return-license@v1
|
|
||||||
if: always()
|
|
||||||
|
|||||||
15
.github/workflows/test.yml
vendored
Normal file
15
.github/workflows/test.yml
vendored
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
name: Test Action
|
||||||
|
|
||||||
|
on: [push]
|
||||||
|
|
||||||
|
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
|
||||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1 +1,2 @@
|
|||||||
.idea
|
.idea
|
||||||
|
node_modules
|
||||||
|
|||||||
2
.prettierignore
Normal file
2
.prettierignore
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
**/node_modules/**
|
||||||
|
**/dist/**
|
||||||
6
.prettierrc.json
Normal file
6
.prettierrc.json
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"semi": true,
|
||||||
|
"singleQuote": true,
|
||||||
|
"trailingComma": "all",
|
||||||
|
"printWidth": 100
|
||||||
|
}
|
||||||
3
.yarnrc
Normal file
3
.yarnrc
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
save-prefix ""
|
||||||
|
--install.audit true
|
||||||
|
--add.audit true
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
FROM gableroux/unity3d:2019.2.11f1-webgl
|
ARG IMAGE
|
||||||
|
FROM $IMAGE
|
||||||
|
|
||||||
LABEL "com.github.actions.name"="Unity - Builder"
|
LABEL "com.github.actions.name"="Unity - Builder"
|
||||||
LABEL "com.github.actions.description"="Build Unity projects for different platforms."
|
LABEL "com.github.actions.description"="Build Unity projects for different platforms."
|
||||||
|
|||||||
154
README.md
154
README.md
@@ -1,14 +1,15 @@
|
|||||||
# Unity - Builder
|
# Unity - Builder
|
||||||
|
|
||||||
[](https://github.com/webbertakken/unity-builder/actions?query=branch%3Amaster+workflow%3A%22Actions+%F0%9F%98%8E%22)
|
[](https://github.com/webbertakken/unity-builder/actions?query=branch%3Amaster+workflow%3A%22Actions+%F0%9F%98%8E%22)
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
GitHub Action to
|
GitHub Action to
|
||||||
[build Unity projects](https://github.com/marketplace/actions/unity-builder)
|
[build Unity projects](https://github.com/marketplace/actions/unity-builder)
|
||||||
for different platforms.
|
for different platforms.
|
||||||
|
|
||||||
Part of the
|
Part of the
|
||||||
[Unity Actions](https://github.com/webbertakken/unity-actions)
|
[Unity Actions](https://github.com/webbertakken/unity-actions)
|
||||||
collection.
|
collection.
|
||||||
|
|
||||||
---
|
---
|
||||||
@@ -18,13 +19,13 @@ to build Unity projects for different platforms.
|
|||||||
|
|
||||||
It is recommended to run the
|
It is recommended to run the
|
||||||
[Test](https://github.com/webbertakken/unity-actions#test)
|
[Test](https://github.com/webbertakken/unity-actions#test)
|
||||||
action from the
|
action from the
|
||||||
[Unity Actions](https://github.com/webbertakken/unity-actions)
|
[Unity Actions](https://github.com/webbertakken/unity-actions)
|
||||||
collection before running this action. This action also requires the [Activation](https://github.com/marketplace/actions/unity-activate) step.
|
collection before running this action. This action also requires the [Activation](https://github.com/marketplace/actions/unity-activate) step.
|
||||||
|
|
||||||
## Documentation
|
## Documentation
|
||||||
|
|
||||||
See the
|
See the
|
||||||
[Unity Actions](https://github.com/webbertakken/unity-actions)
|
[Unity Actions](https://github.com/webbertakken/unity-actions)
|
||||||
collection repository for workflow documentation and reference implementation.
|
collection repository for workflow documentation and reference implementation.
|
||||||
|
|
||||||
@@ -36,68 +37,109 @@ Create or edit the file called `.github/workflows/main.yml` and add a job to it.
|
|||||||
name: Build project
|
name: Build project
|
||||||
on: [push]
|
on: [push]
|
||||||
jobs:
|
jobs:
|
||||||
buildForWebGL:
|
buildForSomePlatforms:
|
||||||
name: Build for WebGL 🕸
|
name: Build for ${{ matrix.targetPlatform }} on version ${{ matrix.unityVersion }}
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
projectPath:
|
||||||
|
- path/to/your/project
|
||||||
|
unityVersion:
|
||||||
|
- 2019.2.11f1
|
||||||
|
targetPlatform:
|
||||||
|
- WebGL
|
||||||
|
- iOS
|
||||||
steps:
|
steps:
|
||||||
```
|
- uses: actions/checkout@v1
|
||||||
|
- uses: webbertakken/unity-activate@v1
|
||||||
Activate Unity in a step using the
|
- uses: webbertakken/unity-builder@v0.3
|
||||||
[Unity Activate](https://github.com/marketplace/actions/unity-activate)
|
with:
|
||||||
action.
|
projectPath: ${{ matrix.projectPath }}
|
||||||
|
unityVersion: ${{ matrix.unityVersion }}
|
||||||
Configure the builder as follows:
|
targetPlatform: ${{ matrix.targetPlatform }}
|
||||||
|
- uses: webbertakken/unity-return-license@v1
|
||||||
```yaml
|
if: always()
|
||||||
# Configure builder
|
- uses: actions/upload-artifact@v1
|
||||||
- name: Build project
|
|
||||||
id: buildStep
|
|
||||||
uses: webbertakken/unity-builder@v0.2 # WIP (only webgl for now)
|
|
||||||
env:
|
|
||||||
# Optional: Path to your project, leave blank for "./"
|
|
||||||
UNITY_PROJECT_PATH: path/to/your/project
|
|
||||||
|
|
||||||
# Name for your build
|
|
||||||
BUILD_NAME: TestBuild
|
|
||||||
|
|
||||||
# Optional: Builds path, leave blank for "build"
|
|
||||||
BUILDS_PATH: build
|
|
||||||
|
|
||||||
# Target platform for your build
|
|
||||||
BUILD_TARGET: WebGL
|
|
||||||
|
|
||||||
# Optional: <StaticBuildClass.StaticMethod>
|
|
||||||
BUILD_METHOD: ""
|
|
||||||
```
|
|
||||||
|
|
||||||
> _**Note:** By default the enabled scenes from the
|
|
||||||
project's settings will be built._
|
|
||||||
|
|
||||||
You use the id to **upload your built files** like so:
|
|
||||||
|
|
||||||
```yaml
|
|
||||||
# Upload distributables
|
|
||||||
- name: Upload Build
|
|
||||||
uses: actions/upload-artifact@v1
|
|
||||||
with:
|
with:
|
||||||
name: Build
|
name: Build
|
||||||
path: ${{ steps.buildStep.outputs.allBuildsPath }}
|
path: build
|
||||||
```
|
```
|
||||||
|
|
||||||
Return the Unity license in a final step using the
|
> **Notes:**
|
||||||
[Unity Return License](https://github.com/marketplace/actions/unity-return-license)
|
>
|
||||||
action.
|
> - Don't forget to replace _<test-project>_ with your project name.
|
||||||
|
> - By default the enabled scenes from the project's settings will be built.
|
||||||
|
|
||||||
Commit and push your workflow definition.
|
## Configuration options
|
||||||
|
|
||||||
|
Below options can be specified under `with:` for the `unity-builder` action.
|
||||||
|
|
||||||
|
#### projectPath
|
||||||
|
|
||||||
|
Specify the path to your Unity project to be built.
|
||||||
|
The path should be relative to the root of your project.
|
||||||
|
|
||||||
|
_**required:** `false`_
|
||||||
|
_**default:** `<your project root>`_
|
||||||
|
|
||||||
|
#### unityVersion
|
||||||
|
|
||||||
|
Version of Unity to use for building the project.
|
||||||
|
|
||||||
|
_**required:** `false`_
|
||||||
|
_**default:** `2019.2.1f11`_
|
||||||
|
|
||||||
|
#### targetPlatform
|
||||||
|
|
||||||
|
Platform that the build should target.
|
||||||
|
|
||||||
|
_**required:** `true`_
|
||||||
|
|
||||||
|
#### buildName
|
||||||
|
|
||||||
|
Name of the build.
|
||||||
|
|
||||||
|
_**required:** `false`_
|
||||||
|
_**default:** `testBuild`_
|
||||||
|
|
||||||
|
#### buildsPath
|
||||||
|
|
||||||
|
Path where the builds should be stored.
|
||||||
|
|
||||||
|
In this folder a folder will be created for every targetPlatform.
|
||||||
|
|
||||||
|
_**required:** `false`_
|
||||||
|
_**default:** `build`_
|
||||||
|
|
||||||
|
#### buildCommand
|
||||||
|
|
||||||
|
Custom command to run your build.
|
||||||
|
|
||||||
|
There are two conditions for a custom buildCommand:
|
||||||
|
|
||||||
|
- Must reference a valid path to a `static` method.
|
||||||
|
- The class must reside in the `Assets/Editor` directory.
|
||||||
|
|
||||||
|
_**example:**_
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
- uses: webbertakken/unity-builder@master
|
||||||
|
with:
|
||||||
|
buildCommand: EditorNamespace.BuilderClassName.StaticBulidMethod
|
||||||
|
```
|
||||||
|
|
||||||
|
_**required:** `false`_
|
||||||
|
_**default:** Built-in script that will run a build out of the box._
|
||||||
|
|
||||||
## More actions
|
## More actions
|
||||||
|
|
||||||
Visit
|
Visit
|
||||||
[Unity Actions](https://github.com/webbertakken/unity-actions)
|
[Unity Actions](https://github.com/webbertakken/unity-actions)
|
||||||
to find related actions for Unity.
|
to find related actions for Unity.
|
||||||
|
|
||||||
Feel free to contribute.
|
Feel free to contribute.
|
||||||
|
|
||||||
## Licence
|
## Licence
|
||||||
|
|
||||||
[MIT](./LICENSE)
|
[MIT](./LICENSE)
|
||||||
|
|||||||
36
action.yml
36
action.yml
@@ -1,15 +1,37 @@
|
|||||||
name: 'Unity - Builder'
|
name: 'Unity - Builder'
|
||||||
author: Webber Takken <webber@takken.io>
|
author: Webber Takken <webber@takken.io>
|
||||||
description: 'Build Unity projects for different platforms.'
|
description: 'Build Unity projects for different platforms.'
|
||||||
inputs: {}
|
inputs:
|
||||||
|
unityVersion:
|
||||||
|
required: false
|
||||||
|
default: ''
|
||||||
|
description: 'Version of unity to use for building the project.'
|
||||||
|
targetPlatform:
|
||||||
|
required: false
|
||||||
|
default: ''
|
||||||
|
description: 'Platform that the build should target.'
|
||||||
|
projectPath:
|
||||||
|
required: false
|
||||||
|
default: ''
|
||||||
|
description: 'Relative path to the project to be built.'
|
||||||
|
buildName:
|
||||||
|
required: false
|
||||||
|
default: ''
|
||||||
|
description: 'Name of the build.'
|
||||||
|
buildsPath:
|
||||||
|
required: false
|
||||||
|
default: ''
|
||||||
|
description: 'Path where the builds should be stored.'
|
||||||
|
buildMethod:
|
||||||
|
required: false
|
||||||
|
default: ''
|
||||||
|
description: 'Path to a Namespace.Class.StaticMethod to run to perform the build.'
|
||||||
outputs:
|
outputs:
|
||||||
buildPath:
|
buildPath:
|
||||||
description: "Path where the current platform has been built to."
|
description: 'Path where the current platform has been built to.'
|
||||||
allBuildsPath:
|
|
||||||
description: "Path where the build folders are stored. Each platform creates a folder within it."
|
|
||||||
runs:
|
|
||||||
using: 'docker'
|
|
||||||
image: 'Dockerfile'
|
|
||||||
branding:
|
branding:
|
||||||
icon: 'box'
|
icon: 'box'
|
||||||
color: 'gray-dark'
|
color: 'gray-dark'
|
||||||
|
runs:
|
||||||
|
using: 'node12'
|
||||||
|
main: 'dist/index.js'
|
||||||
|
|||||||
15
babel.config.js
Normal file
15
babel.config.js
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
const esModules = ['lodash-es'].join('|');
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
ignore: [`/node_modules/(?!${esModules})`],
|
||||||
|
presets: [
|
||||||
|
[
|
||||||
|
'@babel/preset-env',
|
||||||
|
{
|
||||||
|
targets: {
|
||||||
|
node: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
],
|
||||||
|
};
|
||||||
1
dist/index.js
vendored
Normal file
1
dist/index.js
vendored
Normal file
File diff suppressed because one or more lines are too long
@@ -4,15 +4,17 @@
|
|||||||
# Set project path
|
# Set project path
|
||||||
#
|
#
|
||||||
|
|
||||||
UNITY_PROJECT_PATH=$GITHUB_WORKSPACE/$UNITY_PROJECT_PATH
|
UNITY_PROJECT_PATH=$GITHUB_WORKSPACE/$PROJECT_PATH
|
||||||
|
echo "Using project path \"$UNITY_PROJECT_PATH\"."
|
||||||
|
|
||||||
#
|
#
|
||||||
# Set the name for the build
|
# Set the name for the build
|
||||||
#
|
#
|
||||||
|
|
||||||
if [ -z "$BUILD_NAME" ]; then
|
if [ -z "$BUILD_NAME" ]; then
|
||||||
BUILD_NAME=buildName
|
BUILD_NAME="build-$(date '+%F-%H%M')"
|
||||||
fi
|
fi
|
||||||
|
echo "Using build name \"$BUILD_NAME\"."
|
||||||
|
|
||||||
#
|
#
|
||||||
# Set the builds target platform;
|
# Set the builds target platform;
|
||||||
@@ -29,6 +31,7 @@ fi
|
|||||||
if [ -z "$BUILD_TARGET" ]; then
|
if [ -z "$BUILD_TARGET" ]; then
|
||||||
BUILD_TARGET=WebGL
|
BUILD_TARGET=WebGL
|
||||||
fi
|
fi
|
||||||
|
echo "Using build target \"$BUILD_TARGET\"."
|
||||||
|
|
||||||
#
|
#
|
||||||
# Set builds path
|
# Set builds path
|
||||||
@@ -38,13 +41,9 @@ if [ -z "$BUILDS_PATH" ]; then
|
|||||||
BUILDS_PATH=build
|
BUILDS_PATH=build
|
||||||
fi
|
fi
|
||||||
BUILDS_FULL_PATH=$GITHUB_WORKSPACE/$BUILDS_PATH
|
BUILDS_FULL_PATH=$GITHUB_WORKSPACE/$BUILDS_PATH
|
||||||
|
|
||||||
#
|
|
||||||
# Set path for current build (relative and full)
|
|
||||||
#
|
|
||||||
|
|
||||||
CURRENT_BUILD_PATH=$BUILDS_PATH/$BUILD_TARGET
|
CURRENT_BUILD_PATH=$BUILDS_PATH/$BUILD_TARGET
|
||||||
CURRENT_BUILD_FULL_PATH=$BUILDS_FULL_PATH/$BUILD_TARGET
|
CURRENT_BUILD_FULL_PATH=$BUILDS_FULL_PATH/$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:
|
||||||
@@ -63,6 +62,7 @@ if [ -z "$BUILD_METHOD" ]; then
|
|||||||
# Use the script from this action which builds the scenes that are enabled in
|
# Use the script from this action which builds the scenes that are enabled in
|
||||||
# the project.
|
# the project.
|
||||||
#
|
#
|
||||||
|
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
|
||||||
|
|||||||
8
jest.config.js
Normal file
8
jest.config.js
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
const esModules = ['lodash-es'].join('|');
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
testEnvironment: 'node',
|
||||||
|
moduleFileExtensions: ['js', 'jsx', 'json', 'vue'],
|
||||||
|
transform: { '^.+\\.(js|jsx)?$': 'babel-jest' },
|
||||||
|
transformIgnorePatterns: [`/node_modules/(?!${esModules})`],
|
||||||
|
};
|
||||||
57
package.json
Normal file
57
package.json
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
{
|
||||||
|
"name": "unity-builder",
|
||||||
|
"version": "0.2.0",
|
||||||
|
"description": "Build Unity projects for different platforms.",
|
||||||
|
"main": "src/index.js",
|
||||||
|
"repository": "git@github.com:webbertakken/unity-builder.git",
|
||||||
|
"author": "Webber <webber@takken.io>",
|
||||||
|
"license": "MIT",
|
||||||
|
"scripts": {
|
||||||
|
"build": "ncc build --out dist --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"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@babel/cli": "7.7.5",
|
||||||
|
"@babel/core": "7.7.5",
|
||||||
|
"@babel/preset-env": "7.7.7",
|
||||||
|
"@zeit/ncc": "0.20.5",
|
||||||
|
"babel-eslint": "10.0.3",
|
||||||
|
"eslint": "6.7.2",
|
||||||
|
"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-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",
|
||||||
|
"lodash-es": "4.17.15",
|
||||||
|
"prettier": "1.19.1"
|
||||||
|
},
|
||||||
|
"husky": {
|
||||||
|
"hooks": {
|
||||||
|
"pre-commit": "lint-staged && yarn build && git add dist"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"lint-staged": {
|
||||||
|
"*.{js,jsx}": [
|
||||||
|
"prettier --write",
|
||||||
|
"eslint",
|
||||||
|
"git add",
|
||||||
|
"jest --findRelatedTests"
|
||||||
|
],
|
||||||
|
"*.{json,md,yaml,yml}": [
|
||||||
|
"prettier --write",
|
||||||
|
"git add"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
22
src/index.js
Normal file
22
src/index.js
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
import Action from './model/action';
|
||||||
|
import Docker from './model/docker';
|
||||||
|
import ImageTag from './model/image-tag';
|
||||||
|
import Input from './model/input';
|
||||||
|
|
||||||
|
const core = require('@actions/core');
|
||||||
|
|
||||||
|
async function action() {
|
||||||
|
Action.checkCompatibility();
|
||||||
|
|
||||||
|
const { dockerfile, workspace } = Action;
|
||||||
|
const { version, platform, projectPath, buildName, buildsPath, method } = Input.getFromUser();
|
||||||
|
|
||||||
|
const baseImage = new ImageTag({ version, platform });
|
||||||
|
const builtImage = await Docker.build({ path: workspace, dockerfile, baseImage });
|
||||||
|
|
||||||
|
await Docker.run(builtImage, { workspace, platform, projectPath, buildName, buildsPath, method });
|
||||||
|
}
|
||||||
|
|
||||||
|
action().catch(error => {
|
||||||
|
core.setFailed(error.message);
|
||||||
|
});
|
||||||
47
src/model/action.js
Normal file
47
src/model/action.js
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
import path from 'path';
|
||||||
|
|
||||||
|
export default class Action {
|
||||||
|
static get supportedPlatforms() {
|
||||||
|
return ['linux'];
|
||||||
|
}
|
||||||
|
|
||||||
|
static get isRunningLocally() {
|
||||||
|
return process.env.RUNNER_WORKSPACE === undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
static get isRunningFromSource() {
|
||||||
|
return __dirname !== 'dist';
|
||||||
|
}
|
||||||
|
|
||||||
|
static get name() {
|
||||||
|
return 'unity-builder';
|
||||||
|
}
|
||||||
|
|
||||||
|
static get rootFolder() {
|
||||||
|
if (!Action.isRunningLocally) {
|
||||||
|
const workspace = process.env.RUNNER_WORKSPACE;
|
||||||
|
return `${workspace}/${path.basename(workspace)}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Action.isRunningFromSource) {
|
||||||
|
return path.dirname(path.dirname(path.dirname(__filename)));
|
||||||
|
}
|
||||||
|
|
||||||
|
return path.dirname(path.dirname(__filename));
|
||||||
|
}
|
||||||
|
|
||||||
|
static get dockerfile() {
|
||||||
|
return `${Action.rootFolder}/Dockerfile`;
|
||||||
|
}
|
||||||
|
|
||||||
|
static get workspace() {
|
||||||
|
return process.env.GITHUB_WORKSPACE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static checkCompatibility() {
|
||||||
|
const currentPlatform = process.platform;
|
||||||
|
if (!Action.supportedPlatforms.includes(currentPlatform)) {
|
||||||
|
throw new Error(`Currently ${currentPlatform}-platform is not supported`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
20
src/model/action.test.js
Normal file
20
src/model/action.test.js
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
import path from 'path';
|
||||||
|
import Action from './action';
|
||||||
|
|
||||||
|
describe('Action', () => {
|
||||||
|
describe('compatibility check', () => {
|
||||||
|
it('throws for anything other than linux', () => {
|
||||||
|
if (process.platform !== 'linux') {
|
||||||
|
expect(() => Action.checkCompatibility()).toThrow();
|
||||||
|
} else {
|
||||||
|
expect(() => Action.checkCompatibility()).not.toThrow();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns the root folder of the action', () => {
|
||||||
|
const { rootFolder, name } = Action;
|
||||||
|
|
||||||
|
expect(path.basename(rootFolder)).toStrictEqual(name);
|
||||||
|
});
|
||||||
|
});
|
||||||
55
src/model/docker.js
Normal file
55
src/model/docker.js
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
import { exec } from '@actions/exec';
|
||||||
|
import ImageTag from './image-tag';
|
||||||
|
|
||||||
|
export default class Docker {
|
||||||
|
static async build(buildParameters, silent = false) {
|
||||||
|
const { path, dockerfile, baseImage } = buildParameters;
|
||||||
|
const { version, platform } = baseImage;
|
||||||
|
|
||||||
|
const tag = new ImageTag({ repository: '', name: 'unity-builder', version, platform });
|
||||||
|
const command = `docker build ${path} \
|
||||||
|
--file ${dockerfile} \
|
||||||
|
--build-arg IMAGE=${baseImage} \
|
||||||
|
--tag ${tag}`;
|
||||||
|
|
||||||
|
await exec(command, null, { silent });
|
||||||
|
|
||||||
|
return tag;
|
||||||
|
}
|
||||||
|
|
||||||
|
static async run(image, parameters, silent = false) {
|
||||||
|
const { workspace, platform, projectPath, buildName, buildsPath, method } = parameters;
|
||||||
|
|
||||||
|
const command = `docker run \
|
||||||
|
--workdir /github/workspace \
|
||||||
|
--rm \
|
||||||
|
--env PROJECT_PATH=${projectPath} \
|
||||||
|
--env BUILD_TARGET=${platform} \
|
||||||
|
--env BUILD_NAME=${buildName} \
|
||||||
|
--env BUILDS_PATH=${buildsPath} \
|
||||||
|
--env BUILD_METHOD=${method} \
|
||||||
|
--env HOME=/github/home \
|
||||||
|
--env GITHUB_REF \
|
||||||
|
--env GITHUB_SHA \
|
||||||
|
--env GITHUB_REPOSITORY \
|
||||||
|
--env GITHUB_ACTOR \
|
||||||
|
--env GITHUB_WORKFLOW \
|
||||||
|
--env GITHUB_HEAD_REF \
|
||||||
|
--env GITHUB_BASE_REF \
|
||||||
|
--env GITHUB_EVENT_NAME \
|
||||||
|
--env GITHUB_WORKSPACE=/github/workspace \
|
||||||
|
--env GITHUB_ACTION \
|
||||||
|
--env GITHUB_EVENT_PATH \
|
||||||
|
--env RUNNER_OS \
|
||||||
|
--env RUNNER_TOOL_CACHE \
|
||||||
|
--env RUNNER_TEMP \
|
||||||
|
--env RUNNER_WORKSPACE \
|
||||||
|
--volume "/var/run/docker.sock":"/var/run/docker.sock" \
|
||||||
|
--volume "/home/runner/work/_temp/_github_home":"/github/home" \
|
||||||
|
--volume "/home/runner/work/_temp/_github_workflow":"/github/workflow" \
|
||||||
|
--volume "${workspace}":"/github/workspace" \
|
||||||
|
${image}`;
|
||||||
|
|
||||||
|
await exec(command, null, { silent });
|
||||||
|
}
|
||||||
|
}
|
||||||
35
src/model/docker.test.js
Normal file
35
src/model/docker.test.js
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
import Action from './action';
|
||||||
|
import Docker from './docker';
|
||||||
|
import ImageTag from './image-tag';
|
||||||
|
|
||||||
|
describe('Docker', () => {
|
||||||
|
it('builds', async () => {
|
||||||
|
const path = Action.rootFolder;
|
||||||
|
const dockerfile = `${path}/Dockerfile`;
|
||||||
|
const baseImage = new ImageTag({
|
||||||
|
repository: '',
|
||||||
|
name: 'alpine',
|
||||||
|
version: '3',
|
||||||
|
platform: 'Test',
|
||||||
|
});
|
||||||
|
|
||||||
|
const tag = await Docker.build({ path, dockerfile, baseImage }, true);
|
||||||
|
|
||||||
|
expect(tag).toBeInstanceOf(ImageTag);
|
||||||
|
expect(tag.toString()).toStrictEqual('unity-builder:3');
|
||||||
|
}, 240000);
|
||||||
|
|
||||||
|
it.skip('runs', async () => {
|
||||||
|
const image = 'unity-builder:2019.2.11f1-webgl';
|
||||||
|
|
||||||
|
const parameters = {
|
||||||
|
workspace: Action.rootFolder,
|
||||||
|
projectPath: `${Action.rootFolder}/test-project`,
|
||||||
|
buildName: 'someBulidName',
|
||||||
|
buildsPath: 'build',
|
||||||
|
method: '',
|
||||||
|
};
|
||||||
|
|
||||||
|
await Docker.run(image, parameters);
|
||||||
|
});
|
||||||
|
});
|
||||||
83
src/model/image-tag.js
Normal file
83
src/model/image-tag.js
Normal file
@@ -0,0 +1,83 @@
|
|||||||
|
import { has, get, trimEnd, trimStart } from 'lodash-es';
|
||||||
|
|
||||||
|
export default class ImageTag {
|
||||||
|
constructor(imageProperties) {
|
||||||
|
const {
|
||||||
|
repository = 'gableroux',
|
||||||
|
name = 'unity3d',
|
||||||
|
version = '2019.2.11f1',
|
||||||
|
platform,
|
||||||
|
} = imageProperties;
|
||||||
|
|
||||||
|
if (!ImageTag.versionPattern.test(version)) {
|
||||||
|
throw new Error(`Invalid version "${version}".`);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!has(ImageTag.targetPlatformToBuilderPlatformMap, platform)) {
|
||||||
|
throw new Error(`Platform "${platform}" is currently not supported.`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const builderPlatform = get(
|
||||||
|
ImageTag.targetPlatformToBuilderPlatformMap,
|
||||||
|
platform,
|
||||||
|
ImageTag.builderPlatforms.generic,
|
||||||
|
);
|
||||||
|
|
||||||
|
Object.assign(this, { repository, name, version, platform, builderPlatform });
|
||||||
|
}
|
||||||
|
|
||||||
|
static get versionPattern() {
|
||||||
|
return /^20\d{2}\.\d\.\w{3,4}|3$/;
|
||||||
|
}
|
||||||
|
|
||||||
|
static get builderPlatforms() {
|
||||||
|
return {
|
||||||
|
generic: '',
|
||||||
|
webgl: 'webgl',
|
||||||
|
mac: 'mac',
|
||||||
|
windows: 'windows',
|
||||||
|
android: 'android',
|
||||||
|
ios: 'ios',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
static get targetPlatformToBuilderPlatformMap() {
|
||||||
|
const { generic, webgl, mac, windows, android, ios } = ImageTag.builderPlatforms;
|
||||||
|
|
||||||
|
// @see: https://github.com/Unity-Technologies/UnityCsReference/blob/9034442437e6b5efe28c51d02e978a96a3ce5439/Editor/Mono/BuildTarget.cs
|
||||||
|
return {
|
||||||
|
Test: generic,
|
||||||
|
WebGL: webgl,
|
||||||
|
StandaloneOSX: mac,
|
||||||
|
StandaloneWindows: windows,
|
||||||
|
StandaloneWindows64: windows,
|
||||||
|
StandaloneLinux64: generic,
|
||||||
|
PS4: generic,
|
||||||
|
XboxOne: generic,
|
||||||
|
Switch: generic,
|
||||||
|
Android: android,
|
||||||
|
iOS: ios,
|
||||||
|
tvOS: generic,
|
||||||
|
Lumin: generic,
|
||||||
|
BJM: generic,
|
||||||
|
Stadia: generic,
|
||||||
|
WSAPlayer: generic,
|
||||||
|
Facebook: generic,
|
||||||
|
NoTarget: generic,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
get tag() {
|
||||||
|
return trimEnd(`${this.version}-${this.builderPlatform}`, '-');
|
||||||
|
}
|
||||||
|
|
||||||
|
get image() {
|
||||||
|
return trimStart(`${this.repository}/${this.name}`, '/');
|
||||||
|
}
|
||||||
|
|
||||||
|
toString() {
|
||||||
|
const { image, tag } = this;
|
||||||
|
|
||||||
|
return `${image}:${tag}`;
|
||||||
|
}
|
||||||
|
}
|
||||||
67
src/model/image-tag.test.js
Normal file
67
src/model/image-tag.test.js
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
import ImageTag from './image-tag';
|
||||||
|
|
||||||
|
describe('UnityImageVersion', () => {
|
||||||
|
const some = {
|
||||||
|
repository: 'test1',
|
||||||
|
name: 'test2',
|
||||||
|
version: '2099.9.f9f9',
|
||||||
|
platform: 'Stadia',
|
||||||
|
builderPlatform: '',
|
||||||
|
};
|
||||||
|
|
||||||
|
const defaults = {
|
||||||
|
repository: 'gableroux',
|
||||||
|
name: 'unity3d',
|
||||||
|
image: 'gableroux/unity3d',
|
||||||
|
};
|
||||||
|
|
||||||
|
describe('constructor', () => {
|
||||||
|
it('can be called', () => {
|
||||||
|
const { platform } = some;
|
||||||
|
expect(() => new ImageTag({ platform })).not.toThrow();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('accepts parameters and sets the right properties', () => {
|
||||||
|
const image = new ImageTag(some);
|
||||||
|
|
||||||
|
expect(image.repository).toStrictEqual(some.repository);
|
||||||
|
expect(image.name).toStrictEqual(some.name);
|
||||||
|
expect(image.version).toStrictEqual(some.version);
|
||||||
|
expect(image.platform).toStrictEqual(some.platform);
|
||||||
|
expect(image.builderPlatform).toStrictEqual(some.builderPlatform);
|
||||||
|
});
|
||||||
|
|
||||||
|
test.each(['2000.0.0f0', '2011.1.11f1'])('accepts %p version format', version => {
|
||||||
|
expect(() => new ImageTag({ version, platform: some.platform })).not.toThrow();
|
||||||
|
});
|
||||||
|
|
||||||
|
test.each(['some version', '', 1, null])('throws for incorrect versions %p', version => {
|
||||||
|
const { platform } = some;
|
||||||
|
expect(() => new ImageTag({ version, platform })).toThrow();
|
||||||
|
});
|
||||||
|
|
||||||
|
test.each([undefined, 'nonExisting'])('throws for unsupported target %p', platform => {
|
||||||
|
expect(() => new ImageTag({ platform })).toThrow();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('toString', () => {
|
||||||
|
it('returns the correct version', () => {
|
||||||
|
const image = new ImageTag({ version: '2099.1.1111', platform: some.platform });
|
||||||
|
|
||||||
|
expect(image.toString()).toStrictEqual(`${defaults.image}:2099.1.1111`);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns the specific build platform', () => {
|
||||||
|
const image = new ImageTag({ version: '2019.2.11f1', platform: 'WebGL' });
|
||||||
|
|
||||||
|
expect(image.toString()).toStrictEqual(`${defaults.image}:2019.2.11f1-webgl`);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns no specific build platform for generic targetPlatforms', () => {
|
||||||
|
const image = new ImageTag({ platform: 'Stadia' });
|
||||||
|
|
||||||
|
expect(image.toString()).toStrictEqual(`${defaults.image}:2019.2.11f1`);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
22
src/model/input.js
Normal file
22
src/model/input.js
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
const core = require('@actions/core');
|
||||||
|
|
||||||
|
export default 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');
|
||||||
|
|
||||||
|
return {
|
||||||
|
version,
|
||||||
|
platform,
|
||||||
|
projectPath,
|
||||||
|
buildName,
|
||||||
|
buildsPath,
|
||||||
|
method: buildMethod,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
9
src/model/input.test.js
Normal file
9
src/model/input.test.js
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
import Input from './input';
|
||||||
|
|
||||||
|
describe('Input', () => {
|
||||||
|
describe('getFromUser', () => {
|
||||||
|
it('does not throw', () => {
|
||||||
|
expect(() => Input.getFromUser()).not.toThrow();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user