2019-11-30 18:02:18 +00:00
# Unity - Builder
2019-12-22 21:06:34 +00:00
2020-06-19 23:29:02 +00:00
[](https://github.com/webbertakken/unity-builder/actions?query=branch%3Amaster+event%3Apush+workflow%3A%22Actions)
2020-02-09 00:14:36 +00:00
[](https://lgtm.com/projects/g/webbertakken/unity-builder/context:javascript)
[](https://codecov.io/gh/webbertakken/unity-builder)
2019-12-03 22:16:18 +00:00
---
2019-12-22 21:06:34 +00:00
GitHub Action to
[build Unity projects ](https://github.com/marketplace/actions/unity-builder )
2019-12-03 22:16:18 +00:00
for different platforms.
2019-12-22 21:06:34 +00:00
Part of the
[Unity Actions ](https://github.com/webbertakken/unity-actions )
2019-12-03 22:16:18 +00:00
collection.
---
2019-11-30 18:02:18 +00:00
[Github Action ](https://github.com/features/actions )
to build Unity projects for different platforms.
It is recommended to run the
[Test ](https://github.com/webbertakken/unity-actions#test )
2019-12-22 21:06:34 +00:00
action from the
[Unity Actions ](https://github.com/webbertakken/unity-actions )
2019-11-30 18:02:18 +00:00
collection before running this action. This action also requires the [Activation ](https://github.com/marketplace/actions/unity-activate ) step.
2019-12-01 01:03:52 +00:00
## Documentation
2019-12-22 21:06:34 +00:00
See the
2019-12-01 01:03:52 +00:00
[Unity Actions ](https://github.com/webbertakken/unity-actions )
collection repository for workflow documentation and reference implementation.
## Usage
2020-01-27 20:31:19 +00:00
#### Setup builder
By default the enabled scenes from the project's settings will be built.
2019-12-01 01:03:52 +00:00
Create or edit the file called `.github/workflows/main.yml` and add a job to it.
2020-01-27 20:31:19 +00:00
##### 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:
2020-01-07 22:46:19 +00:00
```yaml
2020-05-22 22:03:12 +00:00
- uses: webbertakken/unity-builder@< version >
2020-01-07 22:46:19 +00:00
env:
UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }}
with:
projectPath: path/to/your/project
unityVersion: 2020.X.XXXX
targetPlatform: WebGL
```
2020-01-27 20:31:19 +00:00
##### 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
2020-05-22 22:03:12 +00:00
- uses: webbertakken/unity-builder@< version >
2020-01-27 20:31:19 +00:00
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-
```
2020-02-01 19:21:22 +00:00
This simple addition could speed up your build by more than 50%.
2020-01-27 20:31:19 +00:00
## Complete example
2020-01-07 22:46:19 +00:00
A complete workflow that builds every available platform could look like this:
2019-12-01 01:03:52 +00:00
```yaml
name: Build project
2020-01-07 22:46:19 +00:00
on:
pull_request: {}
push: { branches: [master] }
env:
UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }}
2019-12-01 01:03:52 +00:00
jobs:
2019-12-22 21:06:34 +00:00
buildForSomePlatforms:
name: Build for ${{ matrix.targetPlatform }} on version ${{ matrix.unityVersion }}
2019-12-01 01:03:52 +00:00
runs-on: ubuntu-latest
2019-12-22 21:06:34 +00:00
strategy:
fail-fast: false
matrix:
projectPath:
- path/to/your/project
unityVersion:
- 2019.2.11f1
2020-01-07 22:46:19 +00:00
- 2019.3.0f1
2019-12-22 21:06:34 +00:00
targetPlatform:
2020-01-07 22:46:19 +00:00
- StandaloneOSX # Build a macOS standalone (Intel 64-bit).
- StandaloneWindows # Build a Windows standalone.
- StandaloneWindows64 # Build a Windows 64-bit standalone.
- StandaloneLinux64 # Build a Linux 64-bit standalone.
- iOS # Build an iOS player.
- Android # Build an Android .apk standalone app.
- WebGL # WebGL.
- WSAPlayer # Build an Windows Store Apps player.
- PS4 # Build a PS4 Standalone.
- XboxOne # Build a Xbox One Standalone.
- tvOS # Build to Apple's tvOS platform.
- Switch # Build a Nintendo Switch player.
2019-12-01 01:03:52 +00:00
steps:
2020-02-01 19:21:22 +00:00
- uses: actions/checkout@v2
with:
lfs: true
2020-01-27 20:31:19 +00:00
- uses: actions/cache@v1.1.0
with:
path: ${{ matrix.projectPath }}/Library
key: Library-${{ matrix.projectPath }}-${{ matrix.targetPlatform }}
restore-keys: |
Library-${{ matrix.projectPath }}-
Library-
2020-05-22 22:03:12 +00:00
- uses: webbertakken/unity-builder@< version >
2019-12-22 21:06:34 +00:00
with:
projectPath: ${{ matrix.projectPath }}
unityVersion: ${{ matrix.unityVersion }}
targetPlatform: ${{ matrix.targetPlatform }}
- uses: actions/upload-artifact@v1
with:
name: Build
path: build
2019-12-01 01:03:52 +00:00
```
2020-01-27 20:31:19 +00:00
> **Note:** _Environment variables are set for all jobs in the workflow like this._
2019-12-07 23:59:14 +00:00
2019-12-22 21:06:34 +00:00
## Configuration options
2019-12-01 01:03:52 +00:00
2019-12-22 21:06:34 +00:00
Below options can be specified under `with:` for the `unity-builder` action.
2019-12-01 01:03:52 +00:00
2019-12-22 21:06:34 +00:00
#### projectPath
2019-12-01 01:03:52 +00:00
2019-12-22 21:06:34 +00:00
Specify the path to your Unity project to be built.
The path should be relative to the root of your project.
2019-12-01 01:03:52 +00:00
2019-12-22 21:06:34 +00:00
_**required:** `false` _
_**default:** `<your project root>` _
2019-12-01 01:03:52 +00:00
2019-12-22 21:06:34 +00:00
#### unityVersion
Version of Unity to use for building the project.
_**required:** `false` _
_**default:** `2019.2.1f11` _
#### targetPlatform
Platform that the build should target.
2020-01-07 05:09:18 +00:00
Must be one of the [allowed values ](https://docs.unity3d.com/ScriptReference/BuildTarget.html ) listed in the Unity scripting manual.
2019-12-22 21:06:34 +00:00
_**required:** `true` _
#### buildName
2019-12-01 01:03:52 +00:00
2020-01-20 23:06:14 +00:00
Name of the build. Also the folder in which the build will be stored within `buildsPath` .
2019-12-07 23:59:14 +00:00
2019-12-22 21:06:34 +00:00
_**required:** `false` _
2020-01-20 23:06:14 +00:00
_**default:** `<build_target>` _
2019-12-22 21:06:34 +00:00
#### buildsPath
Path where the builds should be stored.
In this folder a folder will be created for every targetPlatform.
_**required:** `false` _
_**default:** `build` _
2020-01-08 20:14:42 +00:00
#### buildMethod
2019-12-22 21:06:34 +00:00
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:**_
2019-12-01 01:03:52 +00:00
```yaml
2020-04-22 20:13:10 +00:00
- uses: webbertakken/unity-builder@< version >
2019-12-22 21:06:34 +00:00
with:
2020-01-08 20:14:42 +00:00
buildMethod: EditorNamespace.BuilderClassName.StaticBulidMethod
2019-12-01 01:03:52 +00:00
```
2019-12-22 21:06:34 +00:00
_**required:** `false` _
_**default:** Built-in script that will run a build out of the box._
2019-12-01 01:03:52 +00:00
2020-04-22 20:13:10 +00:00
#### versioning
2020-05-22 22:03:12 +00:00
Configure a specific versioning strategy
2020-04-22 20:13:10 +00:00
```yaml
- uses: webbertakken/unity-builder@< version >
with:
versioning: Semantic
```
2020-05-22 22:03:12 +00:00
Find the available strategies below:
2020-04-22 20:13:10 +00:00
2020-05-22 22:03:12 +00:00
##### Semantic
2020-04-22 20:13:10 +00:00
2020-05-22 22:03:12 +00:00
Versioning out of the box! ** (recommended)**
2020-04-22 20:13:10 +00:00
2020-06-19 23:29:02 +00:00
> Compatible with **all platforms**.
> Does **not** modify your repository.
2020-05-22 22:03:12 +00:00
> Requires **zero configuration**.
2020-04-22 20:13:10 +00:00
2020-05-22 22:03:12 +00:00
How it works:
2020-04-22 20:13:10 +00:00
2020-06-19 23:29:02 +00:00
> Generates a version based on [semantic versioning](https://semver.org/).
> Follows `<major>.<minor>.<patch>` for example `0.17.2`.
> The latest tag dictates `<major>.<minor>` (defaults to 0.0 for no tag).
2020-05-22 22:03:12 +00:00
> The number of commits (since the last tag, if any) is used for `<patch>`.
2020-04-26 19:00:24 +00:00
2020-05-22 22:03:12 +00:00
No configuration required.
2020-04-26 19:00:24 +00:00
2020-04-22 20:13:10 +00:00
##### Custom
2020-05-22 22:03:12 +00:00
Allows specifying a custom version in the `version` field. ** (advanced users)**
2020-04-22 20:13:10 +00:00
2020-05-22 22:03:12 +00:00
> This strategy is useful when your project or pipeline has some kind of orchestration
> that determines the versions.
##### None
No version will be set by Builder. ** (not recommended)**
2020-04-22 20:13:10 +00:00
2020-05-22 22:03:12 +00:00
> Not recommended unless you generate a new version in a pre-commit hook. Manually
> setting versions is error-prone.
2020-04-26 19:00:24 +00:00
2020-06-24 22:02:05 +00:00
#### androidVersionCode
Configure the android `versionCode` .
When not specified, the version code is generated from the version using the `major * 1000000 + minor * 1000 + patch` scheme;
2020-07-06 01:41:21 +00:00
#### androidAppBundle
Set this flag to `true` to build '.aab' instead of '.apk'.
_**required:** `false` _
_**default:** `false` _
#### androidKeystoreName
Configure the android `keystoreName` .
_**required:** `false` _
_**default:** ""_
#### androidKeystoreBase64
Configure the base64 contents of the android keystore file.
The contents will be decoded from base64 with `echo $androidKeystoreBase64 | base64 --decode > $androidKeystoreName` ;
_**required:** `false` _
_**default:** ""_
#### androidKeystorePass
Configure the android `keystorePass` .
_**required:** `false` _
_**default:** ""_
#### androidKeyaliasName
Configure the android `keyaliasName` .
_**required:** `false` _
_**default:** ""_
#### androidKeyaliasPass
Configure the android `keyaliasPass` .
_**required:** `false` _
_**default:** ""_
2020-05-21 13:02:15 +00:00
#### allowDirtyBuild
Allows the branch of the build to be dirty, and still generate the build.
```yaml
- uses: webbertakken/unity-builder@< version >
with:
allowDirtyBuild: true
```
Note that it is generally bad practice to modify your branch
in a CI Pipeline. However there are exceptions where this might
be needed. (use with care).
2020-07-08 20:44:54 +00:00
_**required:** `false` _
_**default:** false_
2020-01-27 18:52:17 +00:00
#### 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
2020-04-22 20:13:10 +00:00
- uses: webbertakken/unity-builder@< version >
2020-01-27 18:52:17 +00:00
with:
customParameters: -profile SomeProfile -someBoolean -someValue exampleValue
```
_**required:** `false` _
_**default:** ""_
2019-12-01 01:03:52 +00:00
## More actions
2019-12-22 21:06:34 +00:00
Visit
[Unity Actions ](https://github.com/webbertakken/unity-actions )
2019-12-01 01:03:52 +00:00
to find related actions for Unity.
2019-12-03 22:27:05 +00:00
Feel free to contribute.
2019-12-22 21:06:34 +00:00
## Licence
2019-12-03 22:27:05 +00:00
[MIT ](./LICENSE )