revival/ci/build.sh

95 lines
2.1 KiB
Bash
Raw Normal View History

2021-01-30 15:18:47 +01:00
# osx unity build shell script
# $1 UNITY_VERSION
unityversion=$1
editorlogpath="$(pwd)/Editor.log"
2021-01-30 15:18:47 +01:00
editorpath="/Applications/Unity/Hub/Editor/$unityversion/Unity.app"
# remove previous Editor.log
echo "removing previous editor log..."
[ -f $editorlogpath ] && rm $editorlogpath
echo "starting build using unity v$unityversion..."
2021-03-09 18:30:48 +01:00
unitypid=-1
launch_unity () {
# launch unity in batch mode
open -g $editorpath --args \
-batchmode \
-quit \
-nographics \
-developmentBuild \
-executeMethod "Ktyl.Util.BuildCommand.Run" \
-logFile $editorlogpath \
-projectPath "$(pwd)/game"
unitypid=`pgrep -n Unity`
2021-03-09 18:35:28 +01:00
echo "launched unity ($unitypid)"
2021-03-09 18:30:48 +01:00
}
launch_unity
2021-03-09 18:37:43 +01:00
tries=120
2021-02-15 18:12:44 +01:00
count=0
2021-02-01 20:37:37 +01:00
while [ ! -f $editorlogpath ]
2021-02-01 20:36:39 +01:00
do
2021-03-09 18:30:48 +01:00
if ps -p $unitypid > /dev/null
then
2021-03-09 18:37:43 +01:00
echo "waiting for unity ($unitypid)"
2021-03-09 18:30:48 +01:00
else
echo "unity is no longer running - trying again"
# reset launch attempts
count=0
launch_unity
continue
fi
# wait a second
2021-02-01 20:36:39 +01:00
sleep 1
2021-02-15 18:12:44 +01:00
# decrement
count=`expr $count + 1`
if [ $count -eq $tries ] ; then
2021-03-09 18:30:48 +01:00
echo "early timeout - $tries seconds elapsed since last launch attempt"
2021-03-02 19:44:59 +01:00
exit 1
2021-02-15 18:12:44 +01:00
fi
2021-02-01 20:36:39 +01:00
done
# 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
2021-01-30 15:18:47 +01:00
do
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
break
fi
2021-01-30 15:18:47 +01:00
done
# kill zombie tail process
kill $(<"$work/tail.pid")
# exit with unity's exit code
exit $(cat $work/exitcode)
# vim: tabstop=4 shiftwidth=4 expandtab