🐕
【Unity】GameCIにUnityプロジェクトのバージョンを適応させてみた
はじめに
今回はデスクトップマスコットと呼ばれるOSSプロジェクトの開発過程で発見した物になります。
GameCIはデフォルトの設定ではUnityプロジェクトのバージョンを自動で0.0.0からビルドするごとにインクリメントしてくれるようになっています。
しかし、バージョンをCIよりUnity本プロジェクト主導で管理したと思ったので調べました。
参考になったリンク
やってみる
Unityプロジェクトのバージョンを取得する
バージョンを取得するブランチでプロジェクトからバージョンを抽出しoutputに出力します。
jobs:
check-branch:
runs-on: ubuntu-latest
outputs:
current_version: ${{ steps.check_branch.outputs.current_version }}
steps:
- uses: actions/checkout@v4.2.2
with:
fetch-depth: 0 # すべての履歴とタグを取得
- name: Check event type and branch
id: check_branch
run: |
# ProjectSettings.assetから現在のバージョンを取得
current_version=$(grep -m1 'bundleVersion:' ProjectSettings/ProjectSettings.asset | awk '{print $2}')
echo "current_version=${current_version}" >> $GITHUB_OUTPUT
ProjectSettings.assetの中身にあるbundleVersionを取得しています。
...
tvOSBundleVersion: 1.0
bundleVersion: 0.1.0
preloadedAssets:
...
outputに出力
current_version=$(grep -m1 'bundleVersion:' ProjectSettings/ProjectSettings.asset | awk '{print $2}')
バージョンを適応させる
needsでcheck-branchジョブのoutputを参照できるようにし、GameCIステップのoptionでversionを指定します。
build-windows:
needs: [check-branch]
runs-on: windows-latest
steps:
- name: Check out my unity project.
uses: actions/checkout@v4.2.2
- name: Create LFS file list
run: git lfs ls-files -l | cut -d' ' -f1 | sort > .lfs-assets-id
- name: Restore LFS cache
uses: actions/cache@v4.2.0
id: lfs-cache
with:
path: .git/lfs
key: ${{ runner.os }}-lfs-${{ hashFiles('.lfs-assets-id') }}
- name: Git LFS Pull
run: |
git lfs pull
git add .
git reset --hard
- uses: actions/cache@v4.2.0
with:
path: Library
key: Library-${{ hashFiles('Assets/**', 'Packages/**', 'ProjectSettings/**') }}
restore-keys: |
Library-
- name: Run the build for StandaloneWindows64
uses: game-ci/unity-builder@v4.3.0
env:
UNITY_EMAIL: ${{ secrets.UNITY_EMAIL }}
UNITY_PASSWORD: ${{ secrets.UNITY_PASSWORD }}
UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }}
with:
targetPlatform: StandaloneWindows64
unityVersion: '6000.0.31f1'
buildName: 'uDesktopMascot'
versioning: Custom
version: ${{ needs.check-branch.outputs.current_version }}
versioningのオプションをCustomにすることで、versionをカスタムで指定できるようになります。
- name: Run the build for StandaloneWindows64
uses: game-ci/unity-builder@v4.3.0
env:
UNITY_EMAIL: ${{ secrets.UNITY_EMAIL }}
UNITY_PASSWORD: ${{ secrets.UNITY_PASSWORD }}
UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }}
with:
targetPlatform: StandaloneWindows64
unityVersion: '6000.0.31f1'
buildName: 'uDesktopMascot'
versioning: Custom <--- ここでカスタムなバージョンを指定できるようにする
version: ${{ needs.check-branch.outputs.current_version }} <--- ここでバージョンを指定する
ビルドした成果物の名前も指定できるよ
デフォルトではプラットフォーム名がビルドした成果物の名前になります。今回はWindowsなので、StandaloneWindows64.exeという名前になります。
指定する方法はbuildNameオプションで指定する方法になります。
targetPlatform: StandaloneWindows64
unityVersion: '6000.0.31f1'
buildName: 'uDesktopMascot' <--- ここでビルドした成果物の名前を指定する
versioning: Custom
version: ${{ needs.check-branch.outputs.current_version }}
おわりに
Discordに結構有益な情報があるので、よく見るといいかもしれません。

midra-lab.notion.site/MidraLab-dd08b86fba4e4041a14e09a1d36f36ae 個人が興味を持ったこと × チームで面白いものや興味を持ったものを試していくコミュニティ
Discussion