#!/bin/zsh set -euo pipefail script_dir=${0:A:h} project_root=${script_dir:h} unity_executable=${PROJECTQUINT_UNITY_PATH:-/Applications/Unity/Hub/Editor/6000.3.20f1/Unity.app/Contents/MacOS/Unity} output_app=${PROJECTQUINT_BUILD_PATH:-} if [[ -z "$output_app" || "$output_app" != /* || "$output_app" != *.app ]]; then print -u2 "PROJECTQUINT_BUILD_PATH must be an absolute .app output path." exit 2 fi if [[ ! -x "$unity_executable" ]]; then print -u2 "Unity executable was not found: $unity_executable" exit 2 fi release_manifest="$project_root/Packages/manifest.release.json" if [[ ! -f "$release_manifest" ]]; then print -u2 "Release package manifest was not found: $release_manifest" exit 2 fi fmod_package=("$project_root"/Library/PackageCache/com.fmod.fmod-for-unity-2-03@*(N/)) if (( ${#fmod_package} != 1 )); then print -u2 "Expected exactly one cached FMOD package, found ${#fmod_package}." exit 2 fi staging_base=${TMPDIR:-/tmp} staging_root=$(/usr/bin/mktemp -d "$staging_base/ProjectQuint-release.XXXXXX") staging_project="$staging_root/ProjectQuint" log_directory="$project_root/_workspace/logs" timestamp=$(/bin/date +%Y%m%d-%H%M%S) build_log="$log_directory/release-staging-build-$timestamp.log" previous_app= build_succeeded=0 cleanup() { local exit_code=$? trap - EXIT INT TERM if (( build_succeeded == 0 )) && [[ -n "$previous_app" && -d "$previous_app" ]]; then if [[ -d "$output_app" ]]; then local failed_directory="$project_root/_workspace/failed-builds/$timestamp" /bin/mkdir -p "$failed_directory" /bin/mv "$output_app" "$failed_directory/ProjectQuint.app" fi /bin/mkdir -p "${output_app:h}" /bin/mv "$previous_app" "$output_app" fi /bin/rm -rf "$staging_root" exit "$exit_code" } trap cleanup EXIT INT TERM /bin/mkdir -p "$staging_project/Packages" "$log_directory" for source_directory in Assets ProjectSettings ThirdParty Tools Native; do /usr/bin/rsync -a "$project_root/$source_directory/" "$staging_project/$source_directory/" done /bin/cp "$release_manifest" "$staging_project/Packages/manifest.json" embedded_fmod="$staging_project/Packages/com.fmod.fmod-for-unity-2-03" /bin/cp -cR "${fmod_package[1]}" "$embedded_fmod" if [[ "$embedded_fmod" != "$staging_project"/Packages/* || ! -d "$embedded_fmod/FMOD" ]]; then print -u2 "Refusing to prune an unresolved FMOD staging path: $embedded_fmod" exit 2 fi /bin/rm -rf \ "$embedded_fmod/FMOD/addons/Haptics" \ "$embedded_fmod/FMOD/addons/Haptics.meta" \ "$embedded_fmod/FMOD/addons/ResonanceAudio" \ "$embedded_fmod/FMOD/addons/ResonanceAudio.meta" \ "$embedded_fmod/FMOD/platforms/mac/lib/fmod_haptics.bundle" \ "$embedded_fmod/FMOD/platforms/mac/lib/fmod_haptics.bundle.meta" \ "$embedded_fmod/FMOD/platforms/mac/lib/resonanceaudio.bundle" \ "$embedded_fmod/FMOD/platforms/mac/lib/resonanceaudio.bundle.meta" for platform_name in android html5 ios linux tvos uwp visionos win; do /bin/rm -rf \ "$embedded_fmod/FMOD/platforms/$platform_name/lib" \ "$embedded_fmod/FMOD/platforms/$platform_name/lib.meta" done /bin/rm -f \ "$embedded_fmod/FMOD/platform_ios.mm" \ "$embedded_fmod/FMOD/platform_ios.mm.meta" if [[ -d "$output_app" ]]; then build_root=${output_app:h:h} previous_directory="$build_root/Stable-before-release-prune-$timestamp" /bin/mkdir -p "$previous_directory" previous_app="$previous_directory/ProjectQuint.app" /bin/mv "$output_app" "$previous_app" fi PROJECTQUINT_BUILD_PATH="$output_app" \ "$unity_executable" \ -batchmode \ -nographics \ -projectPath "$staging_project" \ -executeMethod ProjectQuint.Editor.ProjectQuintBuild.BuildMacStable \ -quit \ -logFile "$build_log" if [[ ! -d "$output_app" ]]; then print -u2 "Unity exited without producing the expected app: $output_app" exit 1 fi build_succeeded=1 print "Stable release build: $output_app" print "Build log: $build_log"