GitHub ActionsでUnityマルチプラットフォームビルド&itch.io(butler)に自動デプロイ環境を構築する

初めに

unityでPC向けのゲーム開発をしている中で、自分以外のチームメンバーに対してどうやって最新のビルドを触ってもらうか(デバッグしてもらうか)の方法はかなり悩みます。 方法として以下のようなものが考えられます。

  • 全員がunityを起動してビルドをする
  • 誰かがビルドしてgoogle drive等にアップロードする
  • steamなどのプラットフォームにデバッグ環境を用意してデプロイする

いずれもビルドの手間やアップロードの手間、登録費用など問題があります。

今回は、GitHub Actionsを使ってマルチプラットフォームのビルドおよびitch.ioのbutlerへのデプロイおよびbutlerを使った最新ビルドの確認について行っていきます

対象のプラットフォーム

Demo

以下のような流れになります。githubにpushしたらビルドとデプロイが自動で走ります。

butlerのデスクトップアプリを起動したら、最新版をダウンロードして起動します。以上で常に最新版を見ることができます。

今回検証を行ったRepositoryは以下になります

github.com

また itch.ioは以下のページで公開しています

https://ayousanz.itch.io/dutlter-test

butlerとは

Butler(バトラー)は、itch.ioが提供する公式のコマンドラインツールです。 ゲームビルドなどをitch.ioへアップロード・更新する際に使用し、特に差分アップデート機能が強力です。 これにより更新時のダウンロード量が最小限に抑えられ、迅速なビルド配布・テストに貢献します。 またデスクトップアプリも提供されており、ビルドした配布物を手軽に試せる環境が用意されています。

デスクトップアプリのダウンロードは以下

broth.itch.zone

開発環境

  • Unity 6000.0.43f1

Unityプロジェクトの作成

なんでもいいので、以下のようなプロジェクトを作成します。

こちらをGitHubにpushします

GitHubに必要な情報の登録

Unityのビルドをしてitch.ioにアップロードするためには、以下の情報をGitHubのシークレットキーに登録する必要があります

  • Unityのメールアドレスアドレス
  • Unityのパスワード
  • UnityのLicense
  • itch.ioのAPIキー

Unity周りは以下の記事に取得方法や登録方法を記載していますので、こちらをご確認ください。この記事では長くなるので省略します。

ayousanz.hatenadiary.jp

次にitch.ioのAPIキーですが itch.ioの settingを開いて、以下のAPI KeysのところからAPIを発行します。

Unityと合わせてitch.ioのAPIキーを以下のように登録します。

GitHubActoinsでビルド環境を構築

各プラットフォームに向けてGitHub Actioinsでビルドができる環境を構築します。

.github/workflows/build-deploy-all.yml にファイルを作成します。

name: Build and Deploy All Platforms to itch.io

on:
  push:
    branches: [ main ]
  workflow_dispatch:

env:
  UNITY_VERSION: '6000.0.43f1'

jobs:
  build:
    name: Build & Deploy ${{ matrix.targetPlatform }}
    strategy:
      fail-fast: false
      matrix:
        include:
          # Windows 64bit
          - targetPlatform: StandaloneWindows64
            os: ubuntu-latest # Ubuntuランナーでビルド可能
            itch_channel: windows-x64 # itch.io チャンネル名 (任意)
            artifact_suffix: win64
          # macOS Universal (Intel + Apple Silicon)
          - targetPlatform: StandaloneOSX
            os: macos-latest # macOSランナーが必要
            itch_channel: osx-universal # itch.io チャンネル名 (任意)
            artifact_suffix: osx
          # Linux 64bit
          - targetPlatform: StandaloneLinux64
            os: ubuntu-latest # Ubuntuランナーでビルド可能
            itch_channel: linux-x64 # itch.io チャンネル名 (任意)
            artifact_suffix: linux64
          # WebGL
          - targetPlatform: WebGL
            os: ubuntu-latest # Ubuntuランナーでビルド可能
            itch_channel: webgl # itch.io チャンネル名 (任意)
            artifact_suffix: webgl
          # Android
          - targetPlatform: Android
            os: ubuntu-latest # Ubuntuランナーでビルド可能 (GameCIがSDK/NDKを処理)
            itch_channel: android # itch.io チャンネル名 (任意)
            artifact_suffix: android

    # Matrixで指定されたOSランナーを使用
    runs-on: ${{ matrix.os }}

    steps:
      - name: Checkout repository
        uses: actions/checkout@v4.2.2
        with:
          lfs: true

      - name: Cache Unity Library folder
        uses: actions/cache@v4.2.0
        with:
          path: Library
          key: Library-${{ matrix.targetPlatform }}-${{ hashFiles('Assets/**', 'Packages/**', 'ProjectSettings/**') }}
          restore-keys: |
            Library-${{ matrix.targetPlatform }}-

      # 4. Unityプロジェクトのビルド (GameCIを使用)
      - name: Build Unity project for ${{ matrix.targetPlatform }}
        id: build
        uses: game-ci/unity-builder@v4.3.0
        env:
          UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }}
          UNITY_EMAIL: ${{ secrets.UNITY_EMAIL }}
          UNITY_PASSWORD: ${{ secrets.UNITY_PASSWORD }}
        with:
          unityVersion: ${{ env.UNITY_VERSION }}
          targetPlatform: ${{ matrix.targetPlatform }}

      - name: Upload build artifact (${{ matrix.targetPlatform }})
        uses: actions/upload-artifact@v4
        with:
          name: build-${{ matrix.targetPlatform }}
          path: build/${{ matrix.targetPlatform }}
          retention-days: 1

ビルドが完了するとGitHub Actionsのほうは以下のようになります。

butlerにアップロードする環境の構築

ビルドができたので、次にビルドしたデータをGitHub Actionsからitch.io側にアップロードします。

先ほどのワークフローの下に以下を追加します

  deploy:
    name: Deploy All to itch.io
    needs: build
    runs-on: ubuntu-latest
    strategy:
      fail-fast: false
      matrix:
        include:
          - targetPlatform: StandaloneWindows64
            itch_channel: windows-x64
          - targetPlatform: StandaloneOSX
            itch_channel: osx-universal
          - targetPlatform: StandaloneLinux64
            itch_channel: linux-x64
          - targetPlatform: WebGL
            itch_channel: webgl
          - targetPlatform: Android
            itch_channel: android
    steps:
      - name: Download build artifact (${{ matrix.targetPlatform }})
        uses: actions/download-artifact@v4
        with:
          name: build-${{ matrix.targetPlatform }}
          path: build/${{ matrix.targetPlatform }}
  
      - name: Upload build to itch.io (${{ matrix.itch_channel }})
        uses: yeslayla/butler-publish-itchio-action@v1.0.3
        env:
          BUTLER_CREDENTIALS: ${{ secrets.ITCHIO_API_KEY }}
          CHANNEL: ${{ matrix.itch_channel }}
          ITCH_GAME: dutlter-test
          ITCH_USER: ayousanz
          PACKAGE: build/${{ matrix.targetPlatform }} 

アップロードが完了すると以下のように反映されます

butlerのデスクトップアプリでアプリを起動する

まずは以下から環境にあうプラットフォームのインストーラーをダウンロードします。

itchio.itch.io

インストール後に起動すると登録したソフトを確認することができます。 アップロードは自動で行えるため、最新のものを手元で確認することができます。