Learn more

Save time with GitHub build automation for Unity

Inworld Team
October 17, 2023
Related posts
Want to try Inworld?
CONTACT SALES

It's a familiar scene: the dim glow of the monitor, the hum of your machine, and the clock ticking away as you wait for your game's build to complete 👩‍💻. Or maybe you're exporting your game to various platforms, wishing you could press a single button and make the process seamless. Enter GitHub build automation. 

In this article, we'll show you how Inworld harnesses this tool to automate the Unity build process.

Solution Inworld used

In the world of game development, having efficient tools is critical. That's where GitHub build automation comes into play for us at Inworld. We understand the importance of quick iterations and consistent quality, and that's why we've integrated GitHub automated builds through GitHub Actions into our development cycle for Unity.

Think of GitHub Actions as a helpful assistant, always keeping an eye on the code we commit. Every time a pull request (PR) is submitted, this system ensures that our Unity automated build processes are triggered. Our build ensures that our software development kits (SDKs) meet the high standards we've set.  

What happens when the build completes and it's time to release our SDKs? Our GitHub Actions workflow has a special process that packages everything up. This guarantees, not just a build, but a refined and polished product every step of the way. ✨

Benefits of GitHub automated builds 

Building on our use of GitHub build automation at Inworld, it's worth getting into the broader advantages of tools like Github Actions in game dev. Continuous integration and continuous deployment (CI/CD) are critical for increasing development velocity.

The power of CI/CD comes from its speed, quality, and consistency. These processes fast-track development and also ensure that builds are all made the same way, while also accounting for the nuances of different gaming platforms.

These tools are indispensable for the build process with their seamless integration capabilities, comprehensive features, and that much-needed assurance every game developer needs to sleep well at night.

Unity build automation with GitHub Actions 

Now let’s harness the power of GitHub Actions for Unity builds and get into the mechanics of this process 🛠️. In our workflow, we focus on the core aspects of building and releasing. You can find the yaml file used in our builds here and follow along.

The build

Our setup is initiated with the declaration of the workflow's name and its trigger. This configuration ensures the workflow springs into action when a new release is published.

Within our build job, several pivotal steps combine to form the crux of our operation:

1. Setting the stage:

runs-on: ubuntu-20.04

  • This line configures our workflow to operate on an Ubuntu 20.04 runner. We use Ubuntu 20.04 as it’s a popular choice due to its stability and wide support. Think of this step as selecting the environment or platform where all subsequent tasks are executed. 

2. Concurrency configuration:

concurrency:
  group: build-a-${{ github.ref }}
  cancel-in-progress: true

This configuration ensures efficiency. If multiple builds are triggered in succession, it ensures only the latest one runs, canceling any in-progress duplicates. This is especially useful to prevent redundant builds and accidental clicks. 

3. Checking out the code:

- name: Checkout code
  uses: actions/checkout@v3

Before any operations can be performed on our repository's code, we need to fetch it. This step checks out our repository, making the code accessible for all subsequent steps in the workflow.

4. Caching for efficiency:

- uses: actions/cache@v3
  with:
    path: Library
    key: Library-build
    restore-keys: Library-build

Building Unity projects can be time-consuming – that’s one of the core reasons why we’re automating our builds. This step caches the Library directory, which contains Unity's intermediate build artifacts. By doing so, repeated builds are faster as they can reuse previously computed data, rather than starting afresh.

5. The Unity build:

- uses: game-ci/unity-builder@v2
  with:
    unityVersion: 2021.3.6f1
  buildMethod: ExportPackage.Editor.UnityPackageExporter.Export

This is the heart and soul of our operation. The game-ci/unity-builder action streamlines the Unity build process. We specify the Unity version and the build method to ensure the project is compiled correctly. This action handles the complexities of running Unity in a CI/CD environment. It abstracts away the challenges and provides a seamless build experience. Remember, it’s all about speed and efficiency.

Note: game-ci is a community-driven project that aims to simplify the process of integrating CI/CD practices into game development. unity-builder is a specific action within the game-ci suite that’s tailored for Unity projects. This GitHub Action developed by the community features version specification, multi-platform support, and custom build methods. For more information on unity-builder check out their GitHub repo here.

6. Storing the build:

- name: upload-artifact
  uses: actions/upload-artifact@v3
  with:
    name: Inworld-Unity-SDK
    path: Build/

After the build is complete, we’re left with a compiled Unity package. This step takes that package and stores it as an artifact. Artifacts are temporary files that can be used by subsequent jobs in the workflow or downloaded for manual inspection.

The release

With the build now complete, our final task is to send it out to the community. We take the artifact from the build job and attach it to a GitHub Release.

1. Downloading the build artifact:

- uses: actions/download-artifact@v3
  id: download
    with:
      name: Inworld-Unity-SDK
      path: Build/

  • This step downloads the previously built Inworld-Unity-SDK artifact to the Build/ directory on our runner. The download identifier acts as a useful reference in subsequent steps further down the workflow.

2. Attaching the package to the release:

- name: Attach package to release
  uses: softprops/action-gh-release@v1
  if: startsWith(github.ref, 'refs/tags/')
  with:
    files: Build/ai.inworld.runtime-sdk.unitypackage

  • This is where the final magic happens. The softprops/action-gh-release action takes our Unity package and attaches it to a GitHub Release. The ‘if condition’ ensures this step only runs for tagged commits. By specifying the file path, we're directing the action to the exact location of our Unity package.

Note: softprops is also a community-driven project similar in a sense to game-ci. For more information on the project, check out their GitHub Marketplace page.

With these steps, we’ve automated our build process. The attach-to-release job takes the product of the build job and attaches it to a GitHub Release, making it accessible to users and the community. 

Conclusion

Automation tools have become increasingly important in modern game development. GitHub build automation isn't just about convenience—it completely transforms the CI/CD process. 

By implementing build automation at Inworld, we've streamlined and improved our development process. Our number one goal when we update our SDK is to minimize manual errors and offer you greater peace of mind in your development work with Inworld.

Curious about how Inworld’s Character Engine can elevate your game development process? Check out our Studio and create your first character today. Got questions? Jump into our Discord and ask us! ✨

Stay connected

Get the latest updates, events, and offers from Inworld.