From 50b597630592dcbcdc4a20e2b5114336bfb2b4a8 Mon Sep 17 00:00:00 2001 From: sgr Date: Thu, 9 Nov 2023 00:11:54 +0900 Subject: [PATCH] =?UTF-8?q?=E3=82=AB=E3=82=B9=E3=82=BF=E3=83=A0=E3=83=93?= =?UTF-8?q?=E3=83=AB=E3=83=89=E7=94=A8=E3=81=AEGitHub=20Actions=E3=82=92?= =?UTF-8?q?=E4=BD=9C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/develop_build.yml | 38 +++++++++++++++++++++++++ .github/workflows/release_build.yml | 38 +++++++++++++++++++++++++ Assets/Scripts/Editor/ProjectBuilder.cs | 24 +++++++++++++++- 3 files changed, 99 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/develop_build.yml create mode 100644 .github/workflows/release_build.yml diff --git a/.github/workflows/develop_build.yml b/.github/workflows/develop_build.yml new file mode 100644 index 0000000..ad74d5c --- /dev/null +++ b/.github/workflows/develop_build.yml @@ -0,0 +1,38 @@ +name: Develop Build +on: + workflow_dispatch: {} +jobs: + build: + name: Develop Build my project + runs-on: ubuntu-latest + steps: + # Checkout + - name: Checkout repository + uses: actions/checkout@v3 + with: + lfs: true + + # Cache + - uses: actions/cache@v3 + with: + path: Library + key: Library-${{ hashFiles('Assets/**', 'Packages/**', 'ProjectSettings/**') }} + restore-keys: | + Library- + + # Develop Build + - name: Develop Build project + uses: game-ci/unity-builder@v3 + env: + UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }} + with: + targetPlatform: WebGL + unityVersion: 2022.3.12f1 + # DevelopBuildForCICDのメソッド呼び出し + buildMethod: ProjectBuilder.DevelopBuildForCICD + + # Output + - uses: actions/upload-artifact@v3 + with: + name: Build + path: build diff --git a/.github/workflows/release_build.yml b/.github/workflows/release_build.yml new file mode 100644 index 0000000..ce6258b --- /dev/null +++ b/.github/workflows/release_build.yml @@ -0,0 +1,38 @@ +name: Release Build +on: + workflow_dispatch: {} +jobs: + build: + name: Release Build my project + runs-on: ubuntu-latest + steps: + # Checkout + - name: Checkout repository + uses: actions/checkout@v3 + with: + lfs: true + + # Cache + - uses: actions/cache@v3 + with: + path: Library + key: Library-${{ hashFiles('Assets/**', 'Packages/**', 'ProjectSettings/**') }} + restore-keys: | + Library- + + # Release Build + - name: Release Build project + uses: game-ci/unity-builder@v3 + env: + UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }} + with: + targetPlatform: WebGL + unityVersion: 2022.3.12f1 + # ReleaseBuildForCICDのメソッド呼び出し + buildMethod: ProjectBuilder.ReleaseBuildForCICD + + # Output + - uses: actions/upload-artifact@v3 + with: + name: Build + path: build diff --git a/Assets/Scripts/Editor/ProjectBuilder.cs b/Assets/Scripts/Editor/ProjectBuilder.cs index a33b603..8af3baa 100644 --- a/Assets/Scripts/Editor/ProjectBuilder.cs +++ b/Assets/Scripts/Editor/ProjectBuilder.cs @@ -23,7 +23,23 @@ public static void DevelopBuild() Build(BuildOptions.Development, BuildTarget.WebGL); } - private static void Build(BuildOptions buildOptions, BuildTarget buildTarget) + /// + /// CICDのワークフローからリリースビルドを実行する時はこちらを呼び出す + /// + private static void ReleaseBuildForCICD() + { + Build(BuildOptions.None, BuildTarget.WebGL, true); + } + + /// + /// CICDのワークフローから開発ビルドを実行する時はこちらを呼び出す + /// + private static void DevelopBuildForCICD() + { + Build(BuildOptions.Development, BuildTarget.WebGL, true); + } + + private static void Build(BuildOptions buildOptions, BuildTarget buildTarget, bool isCICD = false) { BuildPlayerOptions buildPlayerOptions = new BuildPlayerOptions(); // ビルド出力先 @@ -45,5 +61,11 @@ private static void Build(BuildOptions buildOptions, BuildTarget buildTarget) { Debug.LogError("Build Failed"); } + + if (isCICD) + { + //成否に応じてUnityEditorの終了プロセスを決定する + EditorApplication.Exit(summary.result == BuildResult.Succeeded ? 0 : 1); + } } } \ No newline at end of file