cft
Become a CreatorSign inGet Started

Unity cloud builds (within GitHub) ☁️🔧[1/3]

Tired of waiting for Unity to finish that build for you to get back to work? Let's do that on someone else's machine!


user

Marlow Haspert

4 months ago | 4 min read
Follow

unity-cloud-builds-within-github-13-odzld

Introduction

Since I started goofing around in the gamedev world I also started to miss some things. What I missed, really was the lack of tools for a certain developer that works using Unity as an engine and was really used to comply to the big software factories way of doing code, specially with a lot of automatic checks.

This is the first of a series of three posts, the original (spanish) version of this one was previously published here. Over the course of them I will try to share with you in a simple way the current workflow that we are using in the games studio I work at to build & publish a Unity WebGL project to a local server.

GitHub Actions

GitHub Actions is a continuous integration and continuous delivery (CI/CD) platform that allows you to automate your build, test, and deployment pipeline. It goes beyond just DevOps and lets you run workflows when other events happen in your repository or on-demand.A workflow is a configurable automated process that will run one or more jobs. Workflows are defined by a YAML file checked in to your repository like any other file. To know more about GitHub Actions, you can check the docs.

GameCI

While looking around the official GitHub actions marketplace, I ended up finding GameCI: a community supported project that offers begginer-friendly, high quality CI/CD techniques for videogames development projects. I am going to use some of the workflows that they provide for this post.

Mental Model:

Our workflow process will contain three jobs:

  1. Build from Unity: our executable will be exposed as an artifact that can be consumed by other jobs.
  2. Publish: copy the build that is stored as an artifact, to an FTP server.
  3. Notification: send a Discord message containing a link to the published version of our game.

Let's work!

The main action that we're going to use, has a very thorough documentation that's available here. Moreover, one of the prerequisites when running this action is first to get a Unity license that's valid for our environment (the Octocat's computer, maybe?). In order to do so, you can follow these steps on the official guide. Once this is done, which has to be done just once per repository, you can keep reading and getting your hands in action (pun intended) without issues.

Like we said before, a workflow is composed of one or more jobs. First, you will need to create a .github/workflows/ directory in the root of your repository to store your workflow files. There we will add the workflow definition file, creating a build.yml file containing the following:

name: Build project

on:

workflow_dispatch:

jobs:

buildForWebGL:

This definition means that our workflow is called “Build project”, that it can be executed on-demand and that it contains a job called “buildForWebGL”. The full workflow file looks like this:

name: Build project

on:

workflow_dispatch:

jobs:

buildForWebGL:

name: Build for WebGL

runs-on: ubuntu-latest

strategy:

fail-fast: false

steps:

- name: Get current date

id: date

run: echo "::set-output name=date::$(date +'%Y-%m-%d')"

- name: Extract branch name

shell: bash

run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})"

id: extract_branch

- name: Checkout

uses: actions/checkout@v2

with:

fetch-depth: 0

lfs: true

- name: Cache

uses: actions/cache@v2

with:

path: Library

key: Library-WebGL

restore-keys: Library-

- name: Start Build

uses: game-ci/unity-builder@v2

env:

UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }}

with:

targetPlatform: WebGL

versioning: Semantic

- name: Upload artifact

uses: actions/upload-artifact@v2

with:

name: build-${{ steps.date.outputs.date }}-${{ github.run_id }}

path: build/WebGL

The steps are the building parts of a job, and they execute in an ordered manner. This should make more sense once we're able to execute the workflow.

In this job, the variable name for ${{ secrets.UNITY_LICENSE }} should match the one that you created in the activation process.

We can find and run our workflow under the Actions tab in the main “page” of our repository. Once it has run, you will be able to see the artifact that the workflow produced and that it can be downloaded. This is the WebGL build that we're going to copy to a FTP server in a next step… automagically 🌟

Thanks for reading! 🥰 If you have any questions or comments, please let me know! Feedback is greatly appreciated.

Upvote


user
Created by

Marlow Haspert

Follow

Unity Dev @ Arf Games Studio

Non-binary & bisexual 🏳️‍🌈 || cuando muera con mis huesos quiero que hagan ukeleles🎶


people
Post

Upvote

Downvote

Comment

Bookmark

Share


Related Articles