From 6c8be1faa4a2c3e7ee9d0507093fdd318e046c09 Mon Sep 17 00:00:00 2001 From: KonH Date: Thu, 6 Jun 2019 21:04:26 +0700 Subject: [PATCH] Fix build target usage --- Assets/Scripts/Editor/CustomBuildPipeline.cs | 13 ++++++++----- build.cake | 2 +- manual_build.sh | 6 ++---- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/Assets/Scripts/Editor/CustomBuildPipeline.cs b/Assets/Scripts/Editor/CustomBuildPipeline.cs index ca66ad6..201a248 100644 --- a/Assets/Scripts/Editor/CustomBuildPipeline.cs +++ b/Assets/Scripts/Editor/CustomBuildPipeline.cs @@ -5,7 +5,6 @@ namespace UnityCiPipeline { public class CustomBuildPipeline : MonoBehaviour { - [MenuItem("BuildPipeline/RunBuild")] public static void RunBuild(BuildTarget target) { var targetGroup = BuildPipeline.GetBuildTargetGroup(target); var opts = new BuildPlayerOptions { @@ -21,10 +20,7 @@ public static void RunBuild(BuildTarget target) { public static void RunBuild_WebGL() => RunBuild(BuildTarget.WebGL); public static void RunBuildForVersion() { - var targetVariable = Environment.GetEnvironmentVariable("BUILD_TARGET"); - if ( string.IsNullOrEmpty(targetVariable) ) { - throw new InvalidOperationException("BUILD_TARGET isn't provided!"); - } + var targetVariable = GetBuildTarget(); var target = (BuildTarget)Enum.Parse(typeof(BuildTarget), targetVariable); var commitHash = GetVersion(); Debug.Log($"RunBuildForCommit: version='{commitHash}'"); @@ -39,6 +35,13 @@ static string GetVersion() { .First(); } + static string GetBuildTarget() { + return Environment.GetCommandLineArgs() + .Where(a => a.StartsWith("-buildTarget=")) + .Select(a => a.Remove(0, "-buildTarget=".Length)) + .First(); + } + static void PrepareForBuild(string version) { PlayerSettings.bundleVersion = version; } diff --git a/build.cake b/build.cake index 5e172b9..fa18a6d 100644 --- a/build.cake +++ b/build.cake @@ -101,7 +101,7 @@ Task("Build") if ( string.IsNullOrEmpty(buildTarget) ) { buildTarget = "WebGL"; } - RunUnity($"-executeMethod UnityCiPipeline.CustomBuildPipeline.RunBuildForVersion -projectPath . -version={version}", false); + RunUnity($"-executeMethod UnityCiPipeline.CustomBuildPipeline.RunBuildForVersion -projectPath . -version={version} -buildTarget={buildTarget}", false); }); Task("Upload") diff --git a/manual_build.sh b/manual_build.sh index 52e686a..8b85265 100755 --- a/manual_build.sh +++ b/manual_build.sh @@ -1,18 +1,16 @@ #!/usr/bin/env bash -# env variables -# BUILD_TARGET - # arguments UNITY_PATH=$1 # path to Unity executable (.../Unity.app/Contents/MacOS/Unity) ITCH_DESTINATION=$2 # itch.io target like userName/projectName:platform VERSION=$3 # application version +BUILD_TARGET=$4 # build target echo "Remove old Build..." rm -rf Build echo "Run Unity from $UNITY_PATH..." -${UNITY_PATH} -quit -batchmode -logFile - -executeMethod UnityCiPipeline.CustomBuildPipeline.RunBuildForVersion -projectPath "$(PWD)" -version=${VERSION} +${UNITY_PATH} -quit -batchmode -logFile - -executeMethod UnityCiPipeline.CustomBuildPipeline.RunBuildForVersion -projectPath "$(PWD)" -version=${VERSION} -buildTarget=${BUILD_TARGET} echo "Push to itch.io..." butler push --userversion=${VERSION} --verbose Build ${ITCH_DESTINATION} \ No newline at end of file