Skip to content

Improve CI stability with comprehensive error handling and fix Unity package import path #198

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 4 commits into
base: next
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 49 additions & 4 deletions features/scripts/build_android.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,31 +24,76 @@ fi

UNITY_PATH="/Applications/Unity/Hub/Editor/$UNITY_PERFORMANCE_VERSION/Unity.app/Contents/MacOS"

# Check if Unity path exists
if [ ! -f "$UNITY_PATH/Unity" ]; then
echo "Unity executable not found at $UNITY_PATH/Unity"
exit 1
fi

pushd "${0%/*}"
script_path=`pwd`
popd

pushd "$script_path/../fixtures"

project_path=`pwd`/mazerunner

# Run unity and immediately exit afterwards, log all output
if [ "$BUILD_TYPE" == "dev" ]; then
DEFAULT_CLI_ARGS="-quit -batchmode -nographics -logFile build_android_dev.log"
EXECUTE_METHOD="Builder.AndroidDev"
APK_NAME="mazerunner-dev.apk"
FINAL_APK_NAME="mazerunner-dev_${UNITY_PERFORMANCE_VERSION:0:4}.apk"
else
DEFAULT_CLI_ARGS="-quit -batchmode -nographics -logFile build_android.log"
EXECUTE_METHOD="Builder.AndroidRelease"
APK_NAME="mazerunner.apk"
FINAL_APK_NAME="mazerunner_${UNITY_PERFORMANCE_VERSION:0:4}.apk"
fi

project_path=`pwd`/mazerunner
# Clean up old build artifacts
echo "Cleaning up old build artifacts..."
if [ -f "$project_path/$FINAL_APK_NAME" ]; then
echo "Removing old APK: $project_path/$FINAL_APK_NAME"
rm -f "$project_path/$FINAL_APK_NAME"
fi

# Build for Android
if [ -f "$project_path/$APK_NAME" ]; then
echo "Removing previous build output: $project_path/$APK_NAME"
rm -f "$project_path/$APK_NAME"
fi

echo "Building Android APK with Unity..."
echo "Unity path: $UNITY_PATH/Unity"
echo "Project path: $project_path"
echo "Execute method: $EXECUTE_METHOD"

# Build for Android
$UNITY_PATH/Unity $DEFAULT_CLI_ARGS -projectPath $project_path -executeMethod $EXECUTE_METHOD
RESULT=$?
if [ $RESULT -ne 0 ]; then exit $RESULT; fi
if [ $RESULT -ne 0 ]; then
echo "Unity build failed with exit code $RESULT"
log_file="build_android.log"
if [ "$BUILD_TYPE" == "dev" ]; then
log_file="build_android_dev.log"
fi
if [ -f "$project_path/$log_file" ]; then
echo "Last 50 lines of build log:"
tail -50 "$project_path/$log_file"
fi
exit $RESULT
fi

# Check if the build output exists
if [ ! -f "$project_path/$APK_NAME" ]; then
echo "Error: Expected build output not found: $project_path/$APK_NAME"
exit 1
fi

echo "Renaming APK to final name..."
mv $project_path/$APK_NAME $project_path/$FINAL_APK_NAME

mv $project_path/$APK_NAME $project_path/${APK_NAME%.apk}_${UNITY_PERFORMANCE_VERSION:0:4}.apk
echo "Build completed successfully!"
echo "Output: $project_path/$FINAL_APK_NAME"

popd
120 changes: 97 additions & 23 deletions features/scripts/build_ios.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,29 @@

set -e

if [ -z "$1" ]
then
if [ -z "$1" ]; then
echo "Build type must be specified (dev or release)"
exit 1
fi

BUILD_TYPE=$1

if [ "$BUILD_TYPE" != "dev" ] && [ "$BUILD_TYPE" != "release" ]
then
if [ "$BUILD_TYPE" != "dev" ] && [ "$BUILD_TYPE" != "release" ]; then
echo "Invalid build type specified. Use 'dev' or 'release'."
exit 1
fi

if [ -z "$UNITY_PERFORMANCE_VERSION" ]; then
echo "UNITY_PERFORMANCE_VERSION must be set"
exit 1
fi

pushd "${0%/*}"
script_path=`pwd`
popd
pushd "$script_path/../fixtures"
project_path=`pwd`/mazerunner

# Clean any previous builds
echo "🧹 Cleaning previous .ipa files..."
if [[ -d "$project_path/output/" ]]; then
find "$project_path/output/" -name "*.ipa" -exec rm -f {} +
else
echo "ℹ️ Output directory does not exist, skipping cleanup."
fi

# Determine project path based on build type
if [ "$BUILD_TYPE" == "dev" ]; then
PROJECT_DIR="$project_path/mazerunner_dev_xcode"
Expand All @@ -39,35 +34,114 @@ else
IPA_NAME="mazerunner"
fi

FINAL_IPA_NAME="${IPA_NAME}_${UNITY_PERFORMANCE_VERSION:0:4}.ipa"

# Validate required files exist
if [ ! -d "$PROJECT_DIR" ]; then
echo "ERROR: Xcode project directory not found: $PROJECT_DIR"
exit 1
fi

if [ ! -d "$PROJECT_DIR/Unity-iPhone.xcodeproj" ]; then
echo "ERROR: Xcode project not found: $PROJECT_DIR/Unity-iPhone.xcodeproj"
exit 1
fi

if [ ! -f "$script_path/exportOptions.plist" ]; then
echo "ERROR: Export options plist not found: $script_path/exportOptions.plist"
exit 1
fi

# Clean any previous builds
echo "🧹 Cleaning previous build artifacts..."
if [[ -d "$project_path/output/" ]]; then
echo "Removing old output directory..."
rm -rf "$project_path/output/"
fi

if [[ -d "$project_path/archive/" ]]; then
echo "Removing old archive directory..."
rm -rf "$project_path/archive/"
fi

# Remove old IPA if it exists
if [ -f "$project_path/$FINAL_IPA_NAME" ]; then
echo "Removing old IPA: $FINAL_IPA_NAME"
rm -f "$project_path/$FINAL_IPA_NAME"
fi

# Create directories
mkdir -p "$project_path/output/"
mkdir -p "$project_path/archive/"

echo "📦 Starting iOS build process for $BUILD_TYPE..."
echo "Project: $PROJECT_DIR"
echo "Final IPA: $FINAL_IPA_NAME"

# Archive and export the project
xcrun xcodebuild -project $PROJECT_DIR/Unity-iPhone.xcodeproj \
xcrun xcodebuild -project "$PROJECT_DIR/Unity-iPhone.xcodeproj" \
-scheme Unity-iPhone \
-configuration Debug \
-archivePath $project_path/archive/Unity-iPhone.xcarchive \
-archivePath "$project_path/archive/Unity-iPhone.xcarchive" \
-allowProvisioningUpdates \
-allowProvisioningDeviceRegistration \
-quiet \
GCC_WARN_INHIBIT_ALL_WARNINGS=YES \
archive

if [ $? -ne 0 ]
then
echo "Failed to archive project"
ARCHIVE_RESULT=$?
if [ $ARCHIVE_RESULT -ne 0 ]; then
echo "Failed to archive project with exit code $ARCHIVE_RESULT"
exit 1
fi

# Verify archive was created
if [ ! -d "$project_path/archive/Unity-iPhone.xcarchive" ]; then
echo "❌ Archive was not created at expected location"
exit 1
fi

echo "✅ Archive completed successfully"
echo "📱 Starting export process..."

xcrun xcodebuild -exportArchive \
-archivePath $project_path/archive/Unity-iPhone.xcarchive \
-exportPath $project_path/output/ \
-archivePath "$project_path/archive/Unity-iPhone.xcarchive" \
-exportPath "$project_path/output/" \
-quiet \
-exportOptionsPlist $script_path/exportOptions.plist
-exportOptionsPlist "$script_path/exportOptions.plist"

if [ $? -ne 0 ]; then
echo "Failed to export app"
EXPORT_RESULT=$?
if [ $EXPORT_RESULT -ne 0 ]; then
echo "❌ Failed to export app with exit code $EXPORT_RESULT"
exit 1
fi

echo "✅ Export completed successfully"
echo "📁 Moving IPA to final location..."

# Move to known location for running (note - the name of the .ipa differs between Xcode versions)
find $project_path/output/ -name "*.ipa" -exec mv '{}' $project_path/${IPA_NAME}_${UNITY_PERFORMANCE_VERSION:0:4}.ipa \;
IPA_COUNT=$(find "$project_path/output/" -name "*.ipa" | wc -l)
if [ $IPA_COUNT -eq 0 ]; then
echo "❌ No IPA files found in output directory"
ls -la "$project_path/output/"
exit 1
fi

if [ $IPA_COUNT -gt 1 ]; then
echo "⚠️ Multiple IPA files found, using the first one:"
find "$project_path/output/" -name "*.ipa" -ls
fi

# Move the IPA file to final location
find "$project_path/output/" -name "*.ipa" -exec mv '{}' "$project_path/$FINAL_IPA_NAME" \; -quit

# Verify the final IPA exists
if [ ! -f "$project_path/$FINAL_IPA_NAME" ]; then
echo "❌ Failed to move IPA to final location"
exit 1
fi

echo "✅ IPA successfully created: $FINAL_IPA_NAME"
ls -lh "$project_path/$FINAL_IPA_NAME"

popd
46 changes: 44 additions & 2 deletions features/scripts/build_macos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ then
exit 1
fi

UNITY_PATH="/Applications/Unity/Hub/Editor/$UNITY_PERFORMANCE_VERSION/Unity.app/Contents/MacOS"
# Check if Unity path exists
if [ ! -f "$UNITY_PATH/Unity" ]; then
echo "Unity executable not found at $UNITY_PATH/Unity"
exit 1
fi

pushd "${0%/*}"
script_path=`pwd`
Expand All @@ -43,24 +47,62 @@ fi
old_app_path="$project_path/${APP_NAME}_${UNITY_PERFORMANCE_VERSION:0:4}.app"
old_zip_path="$project_path/${APP_NAME}_${UNITY_PERFORMANCE_VERSION:0:4}.zip"

echo "Cleaning up old build artifacts..."
if [ -d "$old_app_path" ]; then
echo "Removing old app: $old_app_path"
rm -rf "$old_app_path"
fi

if [ -f "$old_zip_path" ]; then
echo "Removing old zip: $old_zip_path"
rm -f "$old_zip_path"
fi

# Also clean up the immediate build output
if [ -d "$project_path/${APP_NAME}.app" ]; then
echo "Removing previous build output: $project_path/${APP_NAME}.app"
rm -rf "$project_path/${APP_NAME}.app"
fi

# Run unity and immediately exit afterwards, log all output
DEFAULT_CLI_ARGS="-quit -batchmode -nographics -logFile build_macos.log"

echo "Building macOS app with Unity..."
echo "Unity path: $UNITY_PATH/Unity"
echo "Project path: $project_path"
echo "Execute method: $EXECUTE_METHOD"

# Build for MacOS
$UNITY_PATH/Unity $DEFAULT_CLI_ARGS -projectPath $project_path -executeMethod $EXECUTE_METHOD
RESULT=$?
if [ $RESULT -ne 0 ]; then exit $RESULT; fi
if [ $RESULT -ne 0 ]; then
echo "Unity build failed with exit code $RESULT"
if [ -f "$project_path/build_macos.log" ]; then
echo "Last 50 lines of build log:"
tail -50 "$project_path/build_macos.log"
fi
exit $RESULT
fi

# Check if the build output exists
if [ ! -d "$project_path/${APP_NAME}.app" ]; then
echo "Error: Expected build output not found: $project_path/${APP_NAME}.app"
exit 1
fi

echo "Renaming build output..."
mv $project_path/${APP_NAME}.app $project_path/${APP_NAME}_${UNITY_PERFORMANCE_VERSION:0:4}.app

echo "Creating zip archive..."
(cd $project_path && zip -q -r ${APP_NAME}_${UNITY_PERFORMANCE_VERSION:0:4}.zip ${APP_NAME}_${UNITY_PERFORMANCE_VERSION:0:4}.app)

# Verify the zip was created successfully
if [ ! -f "$project_path/${APP_NAME}_${UNITY_PERFORMANCE_VERSION:0:4}.zip" ]; then
echo "Error: Failed to create zip archive"
exit 1
fi

echo "Build completed successfully!"
echo "Output: $project_path/${APP_NAME}_${UNITY_PERFORMANCE_VERSION:0:4}.zip"

popd
Loading