Skip to content

Instantly share code, notes, and snippets.

@nekomimi-daimao
Last active November 11, 2022 10:00
Show Gist options
  • Select an option

  • Save nekomimi-daimao/9e4a8ff0e68818574f971a7ff86a536a to your computer and use it in GitHub Desktop.

Select an option

Save nekomimi-daimao/9e4a8ff0e68818574f971a7ff86a536a to your computer and use it in GitHub Desktop.
shell unity build with docker *MIT* https://opensource.org/licenses/mit-license.php
#!/bin/sh
# shellcheck disable=SC2086
# nekomimi-daimao
# *MIT* https://opensource.org/licenses/mit-license.php
# https://gist.github.com/nekomimi-daimao/9e4a8ff0e68818574f971a7ff86a536a
# create license file
# docker run --rm -v license:/license -w /license unityci/editor:ubuntu-2019.4.24f1-android-0.12.0 /opt/unity/Editor/Unity -quit -batchmode -nographics -logFile -createManualActivationFile
# usage
# ./unity_build_shell.sh https://github.com/nekomimi-daimao/AutoBuildExample.git capsule
#git
echo --- git phase start ---
url=$1
checkout=$2
TMP=$(cat /dev/urandom | LC_CTYPE=C tr -dc 'a-zA-Z0-9' | fold -w 16 | head -n 1)
docker volume create ${TMP}_VOL
docker run -itd --rm --name $TMP -v ${TMP}_VOL:/git/ --entrypoint "sh" alpine/git
docker exec $TMP git clone $url
dir_clone=$(docker exec $TMP ls)
dir_git="/git/${dir_clone}"
docker exec $TMP git -C $dir_git checkout $checkout
dir_root=$(docker exec $TMP git -C $dir_git rev-parse --show-toplevel | xargs basename)
branch=$(docker exec $TMP git -C $dir_git rev-parse --abbrev-ref HEAD)
hash=$(docker exec $TMP git -C $dir_git rev-parse --short HEAD)
echo
echo $dir_root
echo $branch
echo $hash
echo
docker stop $TMP
echo --- git phase end ---
#unity
echo --- unity phase start ---
UNITY_BUILD_IMAGE="unityci/editor:ubuntu-2019.4.24f1-android-0.12.0"
LICENSE_FILE_NAME="Unity_v2019.x.ulf"
build_state=${branch}_${hash}
command_copy="cp -rp /git /build"
command_register="/opt/unity/Editor/Unity \
-batchmode -nographics -quit -silent-crashes \
-logFile /output/${build_state}/android/${build_state}_license.log \
-manualLicenseFile /license/${LICENSE_FILE_NAME}"
command_build="/opt/unity/Editor/Unity \
-batchmode -nographics -quit \
-logFile /output/${build_state}/android/${build_state}_build.log \
-projectPath /build/git/${dir_clone} \
-executeMethod BuildExecutor.Build"
command_arg="-target android \
-out /output/${build_state}/android/${build_state}.apk"
docker run -itd --rm --name ${TMP}_BUILD -w /build -v license:/license:ro -v ${TMP}_VOL:/git:ro -v $dir_root:/output $UNITY_BUILD_IMAGE
docker exec ${TMP}_BUILD $command_copy
docker exec ${TMP}_BUILD $command_register
docker exec ${TMP}_BUILD $command_build $command_arg
docker stop ${TMP}_BUILD
sleep 1s
docker volume rm ${TMP}_VOL
echo --- unity phase end ---
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment