LoginSignup
9
3

More than 3 years have passed since last update.

UnityとGitHubActionsを使って自動ビルドする【複数プラットフォーム同時ビルド】

Last updated at Posted at 2021-04-11

はじめに

最終的に仕上がったものは以下のリポジトリで公開してあります。
分からないことがあったときは参考にしてみてください。

手順

下準備

適当なUnityプロジェクトのリポジトリを用意します。

1. ULFファイルを入手する

GitHub Actions上でUnityライセンスをアクティベートするためのULFファイルを入手します。

この手順に関しては別の記事として書かせてもらいました。(GUIのみで簡単にできます)

2. ULFファイルをSecretsに登録する

  1. プロジェクトリポジトリのSettings > Secretsメニューを選択する。
  2. New repository secretボタンをクリックする。
  3. Nameに"UNITY_LICENSE"と入力し、ValueにULFファイルの中身をコピペする。
  4. Add secretボタンをクリックする。

これでULFファイルの中身は非公開のまま、環境変数として扱うことができます。

3. GitHub Actions上でビルドするためのYAMLを記述する

リポジトリの.github/workflows/フォルダ下にbuild.yamlを作成し、以下のように記述します。

build.yaml
name: Build

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

jobs:
  build:
    name: ${{ matrix.targetPlatform }}
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        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.

    steps:
      # Checkout
      - name: Checkout
        uses: actions/checkout@v2
        with:
          fetch-depth: 0
          lfs: true

      # Cache
      - name: Cache
        uses: actions/cache@v2
        with:
          path: Library
          key: Library-${{ matrix.targetPlatform }}
          restore-keys: Library-

      # Build
      - name: Build
        uses: game-ci/unity-builder@v2
        env:
          UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }}
        with:
          targetPlatform: ${{ matrix.targetPlatform }}

      # Upload Build
      - name: Upload Build
        uses: actions/upload-artifact@v2
        with:
          name: Build-${{ matrix.targetPlatform }}
          path: build/${{ matrix.targetPlatform }}

targetPlatformの一覧

4. 実際にビルドしてみる

  1. リポジトリにPushまたはPull Requestを行い、プロジェクトをビルドするワークフローを実行する。
  2. ワークフローが完了するまで待つ

以下のように✔マークが表示されていれば成功です。

BuildResult

右上のArtifactsから、ビルドされた成果物をダウンロードできます。

さいごに

最終的に仕上がったリポジトリです。詰まったときは参考にしてみてください。

CIは初めてであまり詳しくないので、間違えているところがあれば教えてもらえると幸いです。

参考

9
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
3