diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 8289f1e..2f9badd 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -35,7 +35,7 @@ cleanup-build: CLEANUP_PATH: $CI_BUILDS_DIR/$CI_RUNNER_SHORT_TOKEN/$CI_PROJECT_NAME-build-$CI_PIPELINE_ID script: - echo "cleaning up build directory" - - rm -r $CLEANUP_PATH + - rm -r $CLEANUP_PATH $CLEANUP_PATH.tmp dependencies: - build diff --git a/ci/build.sh b/ci/build.sh index 559e7ab..b1f0935 100644 --- a/ci/build.sh +++ b/ci/build.sh @@ -3,7 +3,7 @@ # $1 UNITY_VERSION unityversion=$1 -editorlogpath="$HOME/Library/Logs/Unity/Editor.log" +editorlogpath="$(pwd)/Editor.log" editorpath="/Applications/Unity/Hub/Editor/$unityversion/Unity.app" # remove previous Editor.log @@ -21,16 +21,39 @@ open -g $editorpath --args \ -logFile $editorlogpath \ -projectPath "$(pwd)/game" -# wait for unity to exit -while pgrep -x Unity > /dev/null +# use a safe directory that is automatically removed by the shell when the script exists +work="$(mktemp -d)" || exit $? +trap "rm -rf '$work'" exit + +# default exit code +echo 1 > $work/exitcode + +# start tail in a subshell and store its pid, then read line by line to determine build result +(tail -n 1 -f $editorlogpath & + jobs -p %% > "$work/tail.pid" +) | while read line do - sleep 1 + echo "${line}" + + # check for build success + if [[ $line == *":: ktyl.build completed with code 0"* ]]; then + echo 0 > $work/exitcode + fi + + # check for exit + # TODO: ideally we should have a better indicator than the package manager's shutdown message + if [[ $line == *"[Package Manager] Server::Kill -- Server was shutdown"* ]]; then + echo "exit loop" + break + fi done -if [ -f $editorlogpath ]; then - echo "build completed, dumping log" - cat $editorlogpath - echo "TODO: check result of build by looking at the last few lines" -else - echo "no editor log to dump?" -fi +# kill zombie tail process +kill $(<"$work/tail.pid") + +exitcode=$(cat $work/exitcode) +echo "exit $exitcode" + +exit $exitcode + +# vim: tabstop=4 shiftwidth=4 expandtab \ No newline at end of file diff --git a/game/Assets/Scripts/Util/Editor/Build/BuildCommand.cs b/game/Assets/Scripts/Util/Editor/Build/BuildCommand.cs index 686ee45..45f3bcf 100644 --- a/game/Assets/Scripts/Util/Editor/Build/BuildCommand.cs +++ b/game/Assets/Scripts/Util/Editor/Build/BuildCommand.cs @@ -3,6 +3,8 @@ using System.Collections.Generic; using System.IO; using System.Linq; using UnityEditor; +using UnityEditor.Build.Reporting; +using UnityEditor.Compilation; using UnityEngine; namespace Ktyl.Util @@ -44,7 +46,12 @@ namespace Ktyl.Util target = BuildTarget.StandaloneWindows64 }; - BuildPipeline.BuildPlayer(options); + var report = BuildPipeline.BuildPlayer(options); + var result = report.summary.result; + if (result == BuildResult.Succeeded) + { + Debug.Log(":: ktyl.build completed with code 0"); + } // TODO: post-process }