ドキュメント

Unity Engine

Download Unity

Unity Engine

Build in a container with GitHub Actions

Run containerized Unity builds from a GitHub Actions workflow on a self-hosted runner.
読み終わるまでの所要時間 2 分最終更新 5日前

Run containerized Unity builds from a GitHub Actions workflow on a self-hosted runner.
GitHub Actions can run a job's steps inside a container started from your Editor image. This example builds your project for the Web platform, caches the
Library
folder between runs, and uploads the build as an artifact.

Prerequisites

  1. An Editor image in a registry your build agent can pull from. For more information, refer to Build a Unity Editor Docker image.
  2. A self-hosted runner on a Linux x64 machine on the same private network as your license server.
  3. A license server configuration file,
    services-config.json
    , at
    /etc/unity/services-config.json
    on the runner machine. For the file's content, refer to Build with Unity in a Docker container.
  4. The user or group that the container's actions run as has write access to the files and folders mounted into the container.
  5. git
    and
    git-lfs
    installed in your Editor image. The
    actions/checkout
    step runs inside the container, so it can't use the runner machine's Git to check out the repository and its Git LFS files.
  6. A build method in your project, such as
    BuildScript.BuildWeb
    in Run the build.

Add the build workflow

To add the build workflow:
  1. Create a workflow file in your repository, such as
    .github/workflows/build-web.yml
    , with the following content:
    name: Build for Webon: push: workflow_dispatch:jobs: build-web: runs-on: [self-hosted, linux, x64] container: image: ghcr.io/my-studio/unity-editor:6000.7.0f1-webgl-android options: >- --shm-size=8g -v /etc/unity/services-config.json:/usr/share/unity3d/config/services-config.json:ro steps: - uses: actions/checkout@v4 with: lfs: true - uses: actions/cache@v4 with: path: Library key: library-web-${{ hashFiles('Packages/packages-lock.json') }} - name: Build run: >- /opt/unity/editors/6000.7.0f1/Editor/Unity -batchmode -nographics -projectPath . -buildTarget WebGL -executeMethod BuildScript.BuildWeb -logFile - -quit - uses: actions/upload-artifact@v4 with: name: web path: Build/Web
    The workflow runs on every push and on demand. The
    container
    section starts the job in your Editor image with 8 GB of shared memory and mounts the license server configuration file read-only. The
    actions/cache
    step saves and restores the
    Library
    folder under a key derived from
    Packages/packages-lock.json
    , so jobs reuse the
    Library
    folder until your packages change.
  2. Commit the workflow file and push it to your repository.
GitHub Actions runs the build on your self-hosted runner and uploads the Web build as the
web
artifact. If the build method fails, the Editor exits with a nonzero code and the job fails.

Additional resources