Release/v4.3.0 #76
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # コンパイルエラーがないかをチェックするワークフロー | |
| # プルリクエスト作成時に自動実行されます | |
| # win, ios, mac, android の各プラットフォームに対してチェックを行います | |
| name: CheckCompileErrors | |
| # 発火タイミング設定 pullRequestに限定する | |
| on: | |
| pull_request: | |
| types: [opened, synchronize, reopened] | |
| jobs: | |
| checkCompileErrors: | |
| name: Check Compile Errors (${{ matrix.docker-image }}) | |
| runs-on: ubuntu-latest | |
| # 各種プラットフォームのDockerイメージで実行できるようにmatrixを定義する | |
| strategy: | |
| max-parallel: 2 | |
| matrix: | |
| # ここで指定しているDockerImageはGameCIが提供しているUnityEditorのイメージです | |
| # os-UnityVersion-targetplatform-gameCiVersion の規則でタグが存在します | |
| # https://hub.docker.com/r/unityci/editor/tags | |
| # Unityバージョン(定数): ${{ vars.UNITY_VERSION }} | |
| # バージョンを変更する場合は、リポジトリのSettings > Secrets and variables > Actions > Variables | |
| # で UNITY_VERSION を定義してください | |
| include: | |
| - docker-image: unityci/editor:ubuntu-${{ vars.UNITY_VERSION }}-windows-mono-3.2.1 | |
| build-target: Win64 | |
| - docker-image: unityci/editor:ubuntu-${{ vars.UNITY_VERSION }}-ios-3.2.1 | |
| build-target: iOS | |
| - docker-image: unityci/editor:ubuntu-${{ vars.UNITY_VERSION }}-mac-mono-3.2.1 | |
| build-target: OSXUniversal | |
| - docker-image: unityci/editor:ubuntu-${{ vars.UNITY_VERSION }}-android-3.2.1 | |
| build-target: Android | |
| env: | |
| UNITY_EMAIL: ${{ secrets.UNITY_EMAIL }} | |
| UNITY_PASSWORD: ${{ secrets.UNITY_PASSWORD }} | |
| UNITY_SERIAL: ${{ secrets.UNITY_SERIAL }} | |
| steps: | |
| # 該当ブランチをCheckout | |
| - name: Checkout PlateauUnitySDK | |
| uses: actions/checkout@v3 | |
| with: | |
| fetch-depth: 0 | |
| lfs: true | |
| # package.jsonのハッシュを計算してキャッシュキーに使用 | |
| - name: Calculate package hash | |
| id: package-hash | |
| run: | | |
| PACKAGE_HASH=$(sha256sum package.json | cut -d' ' -f1) | |
| echo "hash=$PACKAGE_HASH" >> $GITHUB_OUTPUT | |
| echo "Package hash: $PACKAGE_HASH" | |
| # unityEditorのdockerイメージが巨大なのでディスク容量を空ける | |
| - name: Free Disk Space (Ubuntu) | |
| uses: jlumbroso/free-disk-space@main | |
| # 全部消す設定にすると時間がかなりかかってしまうので必要最小限に抑える | |
| with: | |
| tool-cache: false | |
| android: true | |
| dotnet: false | |
| haskell: true | |
| large-packages: false | |
| docker-images: false | |
| swap-storage: false | |
| # unity-projectをキャッシュから復元(プラットフォームごとにキャッシュ) | |
| - name: Restore Unity project | |
| id: cache-unity-project | |
| uses: actions/cache@v3 | |
| with: | |
| path: unity-project | |
| key: unity-project-2022.3.25f1-${{ matrix.build-target }}-${{ steps.package-hash.outputs.hash }} | |
| # キャッシュがヒットしなかった場合のみ、Unityプロジェクトを作成 | |
| - name: Create Project | |
| if: steps.cache-unity-project.outputs.cache-hit != 'true' | |
| run: | | |
| docker run --rm \ | |
| -v ${{ github.workspace }}/unity-project:/project \ | |
| -w /project \ | |
| -e UNITY_EMAIL="${{ env.UNITY_EMAIL }}" \ | |
| -e UNITY_PASSWORD="${{ env.UNITY_PASSWORD }}" \ | |
| -e UNITY_SERIAL="${{ env.UNITY_SERIAL }}" \ | |
| ${{ matrix.docker-image }} \ | |
| unity-editor -batchmode -quit -nographics \ | |
| -username "${{ env.UNITY_EMAIL }}" \ | |
| -password "${{ env.UNITY_PASSWORD }}" \ | |
| -serial "${{ env.UNITY_SERIAL }}" \ | |
| -createProject /project \ | |
| -logFile - | |
| sudo chown -R $(id -u):$(id -g) unity-project | |
| # 現在のリポジトリのコードをUnityプロジェクトのPackages/PlateauUnitySDKに移動 | |
| - name: Move package code to Unity project | |
| run: | | |
| echo "Moving PlateauUnitySDK package to Unity project..." | |
| PROJECT_DIR="unity-project" | |
| # UnityプロジェクトのPackagesディレクトリを作成 | |
| mkdir -p "$PROJECT_DIR/Packages/PlateauUnitySDK" | |
| # rsyncを使ってunity-projectを除外して直接Packages/PlateauUnitySDKにコピー | |
| rsync -a --exclude='unity-project' --exclude='.git' --exclude='.github' . "$PROJECT_DIR/Packages/PlateauUnitySDK/" | |
| echo "Package code moved successfully" | |
| # CI用のビルドスクリプトを生成 | |
| - name: Create CI Build Script | |
| run: | | |
| PROJECT_DIR="unity-project" | |
| EDITOR_DIR="$PROJECT_DIR/Assets/Editor" | |
| mkdir -p "$EDITOR_DIR" | |
| cat > "$EDITOR_DIR/CIBuildScript.cs" << 'EOF' | |
| using System; | |
| using System.IO; | |
| using System.Linq; | |
| using UnityEditor; | |
| using UnityEditor.Build.Reporting; | |
| using UnityEngine; | |
| namespace PLATEAU.Editor | |
| { | |
| /// <summary> | |
| /// CI/CD用のビルドスクリプト | |
| /// コマンドラインから -executeMethod PLATEAU.Editor.CIBuildScript.Build で実行可能 | |
| /// </summary> | |
| public static class CIBuildScript | |
| { | |
| /// <summary> | |
| /// コマンドラインからビルドを実行するメソッド | |
| /// 使用例: Unity -executeMethod PLATEAU.Editor.CIBuildScript.Build -buildPath ./build/Win64 | |
| /// </summary> | |
| public static void Build() | |
| { | |
| // コマンドライン引数からビルドパスを取得 | |
| string buildPath = GetCommandLineArg("-buildPath"); | |
| if (string.IsNullOrEmpty(buildPath)) | |
| { | |
| // デフォルトのビルドパス | |
| buildPath = Path.Combine(Application.dataPath, "..", "build", EditorUserBuildSettings.activeBuildTarget.ToString()); | |
| } | |
| // 絶対パスに変換 | |
| buildPath = Path.GetFullPath(buildPath); | |
| // ビルドターゲットを取得(-buildTargetで指定されている場合はEditorUserBuildSettingsに設定されている) | |
| BuildTarget buildTarget = EditorUserBuildSettings.activeBuildTarget; | |
| BuildTargetGroup buildTargetGroup = BuildPipeline.GetBuildTargetGroup(buildTarget); | |
| // ビルドオプションを設定 | |
| BuildPlayerOptions buildPlayerOptions = new BuildPlayerOptions | |
| { | |
| scenes = GetEnabledScenes(), | |
| locationPathName = buildPath, | |
| target = buildTarget, | |
| options = BuildOptions.None | |
| }; | |
| // プラットフォームごとのビルドパス調整 | |
| if (buildTarget == BuildTarget.StandaloneWindows || buildTarget == BuildTarget.StandaloneWindows64) | |
| { | |
| if (!buildPath.EndsWith(".exe")) | |
| { | |
| buildPath = Path.Combine(buildPath, "Build.exe"); | |
| } | |
| buildPlayerOptions.locationPathName = buildPath; | |
| } | |
| else if (buildTarget == BuildTarget.StandaloneOSX) | |
| { | |
| if (!buildPath.EndsWith(".app")) | |
| { | |
| buildPath = Path.Combine(buildPath, "Build.app"); | |
| } | |
| buildPlayerOptions.locationPathName = buildPath; | |
| } | |
| else if (buildTarget == BuildTarget.Android) | |
| { | |
| if (!buildPath.EndsWith(".apk")) | |
| { | |
| buildPath = Path.Combine(buildPath, "Build.apk"); | |
| } | |
| buildPlayerOptions.locationPathName = buildPath; | |
| } | |
| else if (buildTarget == BuildTarget.iOS) | |
| { | |
| // iOSの場合はXcodeプロジェクトが生成されるので、そのままディレクトリパス | |
| buildPlayerOptions.locationPathName = buildPath; | |
| } | |
| Debug.Log($"Building for {buildTarget} to {buildPlayerOptions.locationPathName}"); | |
| // ビルド実行 | |
| BuildReport report = BuildPipeline.BuildPlayer(buildPlayerOptions); | |
| BuildSummary summary = report.summary; | |
| if (summary.result == BuildResult.Succeeded) | |
| { | |
| Debug.Log($"Build succeeded: {summary.totalSize} bytes"); | |
| EditorApplication.Exit(0); | |
| } | |
| else if (summary.result == BuildResult.Failed) | |
| { | |
| Debug.LogError($"Build failed"); | |
| EditorApplication.Exit(1); | |
| } | |
| else | |
| { | |
| Debug.LogWarning($"Build completed with warnings"); | |
| EditorApplication.Exit(0); | |
| } | |
| } | |
| /// <summary> | |
| /// コマンドライン引数から値を取得 | |
| /// </summary> | |
| private static string GetCommandLineArg(string name) | |
| { | |
| string[] args = Environment.GetCommandLineArgs(); | |
| for (int i = 0; i < args.Length - 1; i++) | |
| { | |
| if (args[i] == name) | |
| { | |
| return args[i + 1]; | |
| } | |
| } | |
| return null; | |
| } | |
| /// <summary> | |
| /// 有効なシーンを取得 | |
| /// </summary> | |
| private static string[] GetEnabledScenes() | |
| { | |
| return EditorBuildSettings.scenes | |
| .Where(scene => scene.enabled) | |
| .Select(scene => scene.path) | |
| .ToArray(); | |
| } | |
| } | |
| } | |
| EOF | |
| echo "CI Build Script created at $EDITOR_DIR/CIBuildScript.cs" | |
| # batchModeでUnityプロジェクトをビルドする。コンパイルエラーやビルドエラーがある場合0以外で終了するのでエラー検知が出来る | |
| - name: Build Unity Application | |
| id: build-app | |
| run: | | |
| echo "Building Unity application..." | |
| echo "Docker image: ${{ matrix.docker-image }}" | |
| echo "Build target: ${{ matrix.build-target }}" | |
| docker run --rm \ | |
| -v ${{ github.workspace }}/unity-project:/project \ | |
| -w /project \ | |
| -e UNITY_EMAIL="${{ env.UNITY_EMAIL }}" \ | |
| -e UNITY_PASSWORD="${{ env.UNITY_PASSWORD }}" \ | |
| -e UNITY_SERIAL="${{ env.UNITY_SERIAL }}" \ | |
| ${{ matrix.docker-image }} \ | |
| unity-editor -batchmode -quit -nographics \ | |
| -username "${{ env.UNITY_EMAIL }}" \ | |
| -password "${{ env.UNITY_PASSWORD }}" \ | |
| -serial "${{ env.UNITY_SERIAL }}" \ | |
| -projectPath /project \ | |
| -buildTarget ${{ matrix.build-target }} \ | |
| -executeMethod PLATEAU.Editor.CIBuildScript.Build \ | |
| -buildPath ./build/${{ matrix.build-target }} \ | |
| -logFile - | |
| # コンパイルエラーまたはビルドエラーが検出された場合、プルリクエストにコメントを追加 | |
| - name: Comment on PR if build errors found | |
| if: failure() && steps.build-app.outcome == 'failure' | |
| uses: actions/github-script@v7 | |
| with: | |
| github-token: ${{ secrets.GITHUB_TOKEN }} | |
| script: | | |
| // プルリクエストにコメントを追加 | |
| const prNumber = context.payload.pull_request?.number || context.issue.number; | |
| const dockerImage = '${{ matrix.docker-image }}'; | |
| await github.rest.issues.createComment({ | |
| issue_number: prNumber, | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| body: `## ❌ ビルドエラーが検出されました\n\nDockerイメージ: ${dockerImage}\n\n詳細はワークフローのログを確認してください。` | |
| }); | |