properly tail log and check build result

This commit is contained in:
Cat Flynn 2021-02-01 18:00:00 +00:00
parent b5e904c835
commit e681a3f306
3 changed files with 43 additions and 13 deletions

View File

@ -35,7 +35,7 @@ cleanup-build:
CLEANUP_PATH: $CI_BUILDS_DIR/$CI_RUNNER_SHORT_TOKEN/$CI_PROJECT_NAME-build-$CI_PIPELINE_ID CLEANUP_PATH: $CI_BUILDS_DIR/$CI_RUNNER_SHORT_TOKEN/$CI_PROJECT_NAME-build-$CI_PIPELINE_ID
script: script:
- echo "cleaning up build directory" - echo "cleaning up build directory"
- rm -r $CLEANUP_PATH - rm -r $CLEANUP_PATH $CLEANUP_PATH.tmp
dependencies: dependencies:
- build - build

View File

@ -3,7 +3,7 @@
# $1 UNITY_VERSION # $1 UNITY_VERSION
unityversion=$1 unityversion=$1
editorlogpath="$HOME/Library/Logs/Unity/Editor.log" editorlogpath="$(pwd)/Editor.log"
editorpath="/Applications/Unity/Hub/Editor/$unityversion/Unity.app" editorpath="/Applications/Unity/Hub/Editor/$unityversion/Unity.app"
# remove previous Editor.log # remove previous Editor.log
@ -21,16 +21,39 @@ open -g $editorpath --args \
-logFile $editorlogpath \ -logFile $editorlogpath \
-projectPath "$(pwd)/game" -projectPath "$(pwd)/game"
# wait for unity to exit # use a safe directory that is automatically removed by the shell when the script exists
while pgrep -x Unity > /dev/null 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 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 done
if [ -f $editorlogpath ]; then # kill zombie tail process
echo "build completed, dumping log" kill $(<"$work/tail.pid")
cat $editorlogpath
echo "TODO: check result of build by looking at the last few lines" exitcode=$(cat $work/exitcode)
else echo "exit $exitcode"
echo "no editor log to dump?"
fi exit $exitcode
# vim: tabstop=4 shiftwidth=4 expandtab

View File

@ -3,6 +3,8 @@ using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using UnityEditor; using UnityEditor;
using UnityEditor.Build.Reporting;
using UnityEditor.Compilation;
using UnityEngine; using UnityEngine;
namespace Ktyl.Util namespace Ktyl.Util
@ -44,7 +46,12 @@ namespace Ktyl.Util
target = BuildTarget.StandaloneWindows64 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 // TODO: post-process
} }