Code Monkey home page Code Monkey logo

unity-builder's Introduction

Unity - Builder

Actions status snyk - known vulnerabilities lgtm - code quality codecov - test coverage


GitHub Action to build Unity projects for different platforms.

Part of the Unity Actions collection.


Github Action to build Unity projects for different platforms.

It is recommended to run the Test action from the Unity Actions collection before running this action. This action also requires the Activation step.

Documentation

See the Unity Actions 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 your license file and add it as a secret.

Then, define the build step as follows:

- uses: webbertakken/[email protected]
  env:
    UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }}
  with:
    projectPath: path/to/your/project
    unityVersion: 2020.X.XXXX
    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:

- uses: webbertakken/[email protected]
  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 after any build action.

By default, Builder outputs it's builds to a folder named build.

Example:

- 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 before any unity steps.

Example:

- uses: actions/[email protected]
  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:

name: Build project

on:
  pull_request: {}
  push: { branches: [master] }

env:
  UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }}

jobs:
  buildForSomePlatforms:
    name: Build for ${{ matrix.targetPlatform }} on version ${{ matrix.unityVersion }}
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        projectPath:
          - path/to/your/project
        unityVersion:
          - 2019.2.11f1
          - 2019.3.0f1
        targetPlatform:
          - 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.
    steps:
      - uses: actions/checkout@v2
        with:
          lfs: true
      - uses: actions/[email protected]
        with:
          path: ${{ matrix.projectPath }}/Library
          key: Library-${{ matrix.projectPath }}-${{ matrix.targetPlatform }}
          restore-keys: |
            Library-${{ matrix.projectPath }}-
            Library-
      - uses: webbertakken/[email protected]
        with:
          projectPath: ${{ matrix.projectPath }}
          unityVersion: ${{ matrix.unityVersion }}
          targetPlatform: ${{ matrix.targetPlatform }}
      - uses: actions/upload-artifact@v1
        with:
          name: Build
          path: build

Note: Environment variables are set for all jobs in the workflow like this.

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.

Must be one of the allowed values listed in the Unity scripting manual.

required: true

buildName

Name of the build. Also the folder in which the build will be stored within buildsPath.

required: false default: <build_target>

buildsPath

Path where the builds should be stored.

In this folder a folder will be created for every targetPlatform.

required: false default: build

buildMethod

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:

- uses: webbertakken/unity-builder@<version>
  with:
    buildMethod: EditorNamespace.BuilderClassName.StaticBulidMethod

required: false default: Built-in script that will run a build out of the box.

versioning

The versioning strategy to use.

Strategies only work when no custom buildMethod is specified.

required: false default: Auto

These are the available strategies:

None

No version will be set by Builder.

- uses: webbertakken/unity-builder@<version>
  with:
    versioning: None

Note that the version set in the project will be used instead.

Semantic (default)

Builder automatically generates a version based on semantic versioning out of the box.

The version works as follows: <major>.<minor>.<patch> for example 0.1.2.
The latest tag dictates <major>.<minor> and the number of commits since that tag is used in <patch>.

- uses: webbertakken/unity-builder@<version>
  with:
    versioning: Semantic

This strategy works well for the following reasons:

  • All builds have their unique version
  • No version related commits are created
  • No knowledge of git or versioning is required
  • Developer keeps control over major and minor versions using tags.
  • Zero configuration; It works out of the box
Tag

Uses the tag that points at HEAD as the version.

- uses: webbertakken/unity-builder@<version>
  with:
    versioning: Tag

This strategy works well when using a pipeline that specifically runs for tags.

The tag must be a version tag.

Custom

Allows specifying a custom version in the version field.

- uses: webbertakken/unity-builder@<version>
  with:
    versioning: Custom
    version: <some_version>

If there is a use case missing from Builder, feel free to create a feature request.

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:

- uses: webbertakken/unity-builder@<version>
  with:
    customParameters: -profile SomeProfile -someBoolean -someValue exampleValue

required: false default: ""

More actions

Visit Unity Actions to find related actions for Unity.

Feel free to contribute.

Licence

MIT

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.