diff --git a/features/scripts/build_android.sh b/features/scripts/build_android.sh index 53dd7726..a686c471 100755 --- a/features/scripts/build_android.sh +++ b/features/scripts/build_android.sh @@ -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 diff --git a/features/scripts/build_ios.sh b/features/scripts/build_ios.sh index 952839d1..7cdc1688 100755 --- a/features/scripts/build_ios.sh +++ b/features/scripts/build_ios.sh @@ -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" @@ -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 diff --git a/features/scripts/build_macos.sh b/features/scripts/build_macos.sh index 4a352e42..daef769e 100755 --- a/features/scripts/build_macos.sh +++ b/features/scripts/build_macos.sh @@ -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` @@ -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 diff --git a/features/scripts/build_webgl.sh b/features/scripts/build_webgl.sh index 4b8d6d1b..5acf10e5 100755 --- a/features/scripts/build_webgl.sh +++ b/features/scripts/build_webgl.sh @@ -24,6 +24,12 @@ 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 @@ -44,12 +50,62 @@ else OUTPUT_FOLDER="mazerunner_webgl" fi +# Clean up old build artifacts +old_folder_path="$project_path/${OUTPUT_FOLDER}_${UNITY_PERFORMANCE_VERSION:0:4}" +old_zip_path="$project_path/${OUTPUT_FOLDER}_${UNITY_PERFORMANCE_VERSION:0:4}.zip" + +echo "Cleaning up old build artifacts..." +if [ -d "$old_folder_path" ]; then + echo "Removing old folder: $old_folder_path" + rm -rf "$old_folder_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/$OUTPUT_FOLDER" ]; then + echo "Removing previous build output: $project_path/$OUTPUT_FOLDER" + rm -rf "$project_path/$OUTPUT_FOLDER" +fi + +echo "Building WebGL with Unity..." +echo "Unity path: $UNITY_PATH/Unity" +echo "Project path: $project_path" +echo "Execute method: $EXECUTE_METHOD" + $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_webgl.log" ]; then + echo "Last 50 lines of build log:" + tail -50 "$project_path/build_webgl.log" + fi + exit $RESULT +fi + +# Check if the build output exists +if [ ! -d "$project_path/$OUTPUT_FOLDER" ]; then + echo "Error: Expected build output not found: $project_path/$OUTPUT_FOLDER" + exit 1 +fi +echo "Renaming build output..." mv $project_path/$OUTPUT_FOLDER $project_path/${OUTPUT_FOLDER}_${UNITY_PERFORMANCE_VERSION:0:4} +echo "Creating zip archive..." (cd $project_path && zip -q -r ${OUTPUT_FOLDER}_${UNITY_PERFORMANCE_VERSION:0:4}.zip ${OUTPUT_FOLDER}_${UNITY_PERFORMANCE_VERSION:0:4}) +# Verify the zip was created successfully +if [ ! -f "$project_path/${OUTPUT_FOLDER}_${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/${OUTPUT_FOLDER}_${UNITY_PERFORMANCE_VERSION:0:4}.zip" + popd diff --git a/features/scripts/build_windows.sh b/features/scripts/build_windows.sh index e9f05d94..69ed14cc 100755 --- a/features/scripts/build_windows.sh +++ b/features/scripts/build_windows.sh @@ -33,12 +33,43 @@ rm "$project_path/Assets/Editor/DisablingBitcodeiOS.cs.meta" UNITY_PATH="/mnt/c/Program Files/Unity/Hub/Editor/$UNITY_PERFORMANCE_VERSION/Editor/Unity.exe" +# Check if Unity path exists +if [ ! -f "$UNITY_PATH" ]; then + echo "Unity executable not found at $UNITY_PATH" + exit 1 +fi + +# Clean up old zip files +if [ -f "features/fixtures/mazerunner/build/Windows-dev-${UNITY_PERFORMANCE_VERSION:0:4}.zip" ]; then + echo "Removing old dev zip file" + rm -f "features/fixtures/mazerunner/build/Windows-dev-${UNITY_PERFORMANCE_VERSION:0:4}.zip" +fi + +if [ -f "features/fixtures/mazerunner/build/Windows-${UNITY_PERFORMANCE_VERSION:0:4}.zip" ]; then + echo "Removing old release zip file" + rm -f "features/fixtures/mazerunner/build/Windows-${UNITY_PERFORMANCE_VERSION:0:4}.zip" +fi + +# Clean up old Windows build directory +if [ -d "features/fixtures/mazerunner/build/Windows" ]; then + echo "Removing old Windows build directory" + rm -rf "features/fixtures/mazerunner/build/Windows" +fi + +echo "Building Windows executable with Unity..." +echo "Unity path: $UNITY_PATH" +echo "Project path (WSL): $project_path" +echo "Project path (Windows): $win_project_path" +echo "Run mode: $RUN_MODE" + if [ "$RUN_MODE" == "dev" ]; then + echo "Executing Unity build for dev..." "$UNITY_PATH" $DEFAULT_CLI_ARGS \ -projectPath "$win_project_path" \ -executeMethod "Builder.WindowsDev" ZIP_FILE="Windows-dev-${UNITY_PERFORMANCE_VERSION:0:4}.zip" elif [ "$RUN_MODE" == "release" ]; then + echo "Executing Unity build for release..." "$UNITY_PATH" $DEFAULT_CLI_ARGS \ -projectPath "$win_project_path" \ -executeMethod "Builder.WindowsRelease" @@ -49,8 +80,28 @@ else fi 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_windows.log" ]; then + echo "Last 50 lines of build log:" + tail -50 "$project_path/build_windows.log" + fi + exit $RESULT +fi + +# Verify Windows build directory exists +if [ ! -d "features/fixtures/mazerunner/build/Windows" ]; then + echo "Error: Expected Windows build directory not found" + exit 1 +fi # Zip up the built artifacts +echo "Creating zip archive: $ZIP_FILE" cd features/fixtures/mazerunner/build -zip -r $ZIP_FILE Windows +if ! zip -r $ZIP_FILE Windows; then + echo "Error: Failed to create zip archive" + exit 1 +fi + +echo "Build completed successfully!" +echo "Output: features/fixtures/mazerunner/build/$ZIP_FILE" diff --git a/features/scripts/build_xcode_project.sh b/features/scripts/build_xcode_project.sh index ca6a2948..4acb42d5 100755 --- a/features/scripts/build_xcode_project.sh +++ b/features/scripts/build_xcode_project.sh @@ -2,10 +2,10 @@ set -e -# Check for unity version -if [ -z "$1" ] -then - echo "ERROR: No Path Set" +# Check for xcode project path +if [ -z "$1" ]; then + echo "ERROR: No Xcode project path specified" + echo "Usage: $0 " exit 1 fi @@ -13,53 +13,119 @@ XCODE_PROJECT_PATH=$1 echo "Xcode Project path set to $XCODE_PROJECT_PATH" -# Check for unity version -if [ -z "$2" ] -then - echo "ERROR: No export name Set" +# Validate xcode project path exists +if [ ! -d "$XCODE_PROJECT_PATH" ]; then + echo "ERROR: Xcode project path does not exist: $XCODE_PROJECT_PATH" exit 1 fi -EXPORT_NAME=$2 +# Check for export name +if [ -z "$2" ]; then + echo "ERROR: No export name specified" + echo "Usage: $0 " + exit 1 +fi +EXPORT_NAME=$2 echo "Xcode export name set to $EXPORT_NAME" +# Validate required files exist +XCODE_PROJECT="$XCODE_PROJECT_PATH/Unity-iPhone.xcodeproj" +if [ ! -d "$XCODE_PROJECT" ]; then + echo "ERROR: Xcode project not found: $XCODE_PROJECT" + exit 1 +fi + +EXPORT_OPTIONS="features/scripts/exportOptions.plist" +if [ ! -f "$EXPORT_OPTIONS" ]; then + echo "ERROR: Export options plist not found: $EXPORT_OPTIONS" + exit 1 +fi + # Clean any previous builds -echo "๐Ÿงน Cleaning previous .ipa files..." +echo "๐Ÿงน Cleaning previous build artifacts..." if [[ -d "$XCODE_PROJECT_PATH/output/" ]]; then - find "$XCODE_PROJECT_PATH/output/" -name "*.ipa" -exec rm -f {} + -else - echo "โ„น๏ธ Output directory does not exist, skipping cleanup." + echo "Removing old output directory..." + rm -rf "$XCODE_PROJECT_PATH/output/" +fi + +if [[ -d "$XCODE_PROJECT_PATH/archive/" ]]; then + echo "Removing old archive directory..." + rm -rf "$XCODE_PROJECT_PATH/archive/" fi +# Create output directories +mkdir -p "$XCODE_PROJECT_PATH/output/" +mkdir -p "$XCODE_PROJECT_PATH/archive/" + +echo "๐Ÿ“ฆ Starting Xcode archive process..." + # Archive and export the project -xcrun xcodebuild -project $XCODE_PROJECT_PATH/Unity-iPhone.xcodeproj \ +xcrun xcodebuild -project "$XCODE_PROJECT" \ -scheme Unity-iPhone \ -configuration Debug \ - -archivePath $XCODE_PROJECT_PATH/archive/Unity-iPhone.xcarchive \ + -archivePath "$XCODE_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 "$XCODE_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 $XCODE_PROJECT_PATH/archive/Unity-iPhone.xcarchive \ - -exportPath $XCODE_PROJECT_PATH/output/ \ + -archivePath "$XCODE_PROJECT_PATH/archive/Unity-iPhone.xcarchive" \ + -exportPath "$XCODE_PROJECT_PATH/output/" \ -quiet \ - -exportOptionsPlist features/scripts/exportOptions.plist + -exportOptionsPlist "$EXPORT_OPTIONS" -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 $XCODE_PROJECT_PATH/output/ -name "*.ipa" -exec mv '{}' features/fixtures/minimalapp/$EXPORT_NAME.ipa \; +IPA_COUNT=$(find "$XCODE_PROJECT_PATH/output/" -name "*.ipa" | wc -l) +if [ $IPA_COUNT -eq 0 ]; then + echo "โŒ No IPA files found in output directory" + ls -la "$XCODE_PROJECT_PATH/output/" + exit 1 +fi + +if [ $IPA_COUNT -gt 1 ]; then + echo "โš ๏ธ Multiple IPA files found, using the first one:" + find "$XCODE_PROJECT_PATH/output/" -name "*.ipa" -ls +fi + +# Ensure target directory exists +mkdir -p features/fixtures/minimalapp/ + +# Move the IPA file +find "$XCODE_PROJECT_PATH/output/" -name "*.ipa" -exec mv '{}' "features/fixtures/minimalapp/$EXPORT_NAME.ipa" \; -quit + +# Verify the final IPA exists +if [ ! -f "features/fixtures/minimalapp/$EXPORT_NAME.ipa" ]; then + echo "โŒ Failed to move IPA to final location" + exit 1 +fi + +echo "โœ… IPA successfully created: features/fixtures/minimalapp/$EXPORT_NAME.ipa" +ls -lh "features/fixtures/minimalapp/$EXPORT_NAME.ipa" diff --git a/features/scripts/do_size_test.sh b/features/scripts/do_size_test.sh index 79116e3e..f7e712e0 100755 --- a/features/scripts/do_size_test.sh +++ b/features/scripts/do_size_test.sh @@ -10,49 +10,111 @@ fi UNITY_PATH="/Applications/Unity/Hub/Editor/$UNITY_PERFORMANCE_VERSION/Unity.app/Contents/MacOS" +# Check if Unity executable exists +if [ ! -f "$UNITY_PATH/Unity" ]; then + echo "Unity executable not found at $UNITY_PATH/Unity" + exit 1 +fi + DEFAULT_CLI_ARGS="-quit -batchmode -nographics" project_path=features/fixtures/minimalapp - package_path=upm-package.zip - package_destination=features/fixtures/minimalapp/Packages +# Validate package exists +if [ ! -f "$package_path" ]; then + echo "Package not found: $package_path" + exit 1 +fi + +# Validate project path exists +if [ ! -d "$project_path" ]; then + echo "Project path not found: $project_path" + exit 1 +fi -echo "remove existing packages" +echo "Removing existing packages..." rm -rf "$package_destination" -echo "building android without bugsnag" +echo "Building Android without bugsnag..." $UNITY_PATH/Unity $DEFAULT_CLI_ARGS -projectPath $project_path -executeMethod Builder.BuildAndroidWithout -logFile build_android_minimal_without.log RESULT=$? -if [ $RESULT -ne 0 ]; then exit $RESULT; fi +if [ $RESULT -ne 0 ]; then + echo "Android build without bugsnag failed with exit code $RESULT" + if [ -f "build_android_minimal_without.log" ]; then + echo "Last 30 lines of build log:" + tail -30 "build_android_minimal_without.log" + fi + exit $RESULT +fi -echo "building ios without bugsnag" +echo "Building iOS without bugsnag..." $UNITY_PATH/Unity $DEFAULT_CLI_ARGS -projectPath $project_path -executeMethod Builder.BuildIosWithout -logFile export_ios_xcode_project_minimal_without.log RESULT=$? -if [ $RESULT -ne 0 ]; then exit $RESULT; fi - -source ./features/scripts/build_xcode_project.sh features/fixtures/minimalapp/minimal_without_xcode without_bugsnag - +if [ $RESULT -ne 0 ]; then + echo "iOS build without bugsnag failed with exit code $RESULT" + if [ -f "export_ios_xcode_project_minimal_without.log" ]; then + echo "Last 30 lines of build log:" + tail -30 "export_ios_xcode_project_minimal_without.log" + fi + exit $RESULT +fi -echo "import package" -unzip -q "$package_path" -d "$package_destination" +echo "Building Xcode project without bugsnag..." +if ! source ./features/scripts/build_xcode_project.sh features/fixtures/minimalapp/minimal_without_xcode without_bugsnag; then + echo "Xcode build without bugsnag failed" + exit 1 +fi +echo "Importing package..." +if ! unzip -q "$package_path" -d "$package_destination"; then + echo "Failed to extract package: $package_path" + exit 1 +fi -echo "building android with bugsnag" +echo "Building Android with bugsnag..." $UNITY_PATH/Unity $DEFAULT_CLI_ARGS -projectPath $project_path -executeMethod Builder.BuildAndroidWith -logFile build_android_minimal_with.log RESULT=$? -if [ $RESULT -ne 0 ]; then exit $RESULT; fi +if [ $RESULT -ne 0 ]; then + echo "Android build with bugsnag failed with exit code $RESULT" + if [ -f "build_android_minimal_with.log" ]; then + echo "Last 30 lines of build log:" + tail -30 "build_android_minimal_with.log" + fi + exit $RESULT +fi -echo "building ios with bugsnag" +echo "Building iOS with bugsnag..." $UNITY_PATH/Unity $DEFAULT_CLI_ARGS -projectPath $project_path -executeMethod Builder.BuildIosWith -logFile export_ios_xcode_project_minimal_with.log RESULT=$? -if [ $RESULT -ne 0 ]; then exit $RESULT; fi -ls +if [ $RESULT -ne 0 ]; then + echo "iOS build with bugsnag failed with exit code $RESULT" + if [ -f "export_ios_xcode_project_minimal_with.log" ]; then + echo "Last 30 lines of build log:" + tail -30 "export_ios_xcode_project_minimal_with.log" + fi + exit $RESULT +fi -source ./features/scripts/build_xcode_project.sh features/fixtures/minimalapp/minimal_with_xcode with_bugsnag +echo "Building Xcode project with bugsnag..." +if ! source ./features/scripts/build_xcode_project.sh features/fixtures/minimalapp/minimal_with_xcode with_bugsnag; then + echo "Xcode build with bugsnag failed" + exit 1 +fi cd features/fixtures/minimalapp -bundle install -bundle exec danger \ No newline at end of file +echo "Installing bundle dependencies for size test..." +if ! bundle install; then + echo "Bundle install failed for size test" + exit 1 +fi + +echo "Running danger for size comparison..." +if ! bundle exec danger; then + echo "Danger execution failed" + exit 1 +fi + +echo "Size test completed successfully!" \ No newline at end of file diff --git a/features/scripts/generate_xcode_project.sh b/features/scripts/generate_xcode_project.sh index 539cdbc1..5bfae87a 100755 --- a/features/scripts/generate_xcode_project.sh +++ b/features/scripts/generate_xcode_project.sh @@ -2,28 +2,31 @@ set -e -if [ -z "$UNITY_PERFORMANCE_VERSION" ] -then +if [ -z "$UNITY_PERFORMANCE_VERSION" ]; then echo "UNITY_PERFORMANCE_VERSION must be set" exit 1 fi -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 UNITY_PATH="/Applications/Unity/Hub/Editor/$UNITY_PERFORMANCE_VERSION/Unity.app/Contents/MacOS" +# Check if Unity executable 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 @@ -34,15 +37,60 @@ DEFAULT_CLI_ARGS="-quit -nographics -batchmode -logFile generateXcodeProject.log project_path=`pwd`/mazerunner +# Validate project path +if [ ! -d "$project_path" ]; then + echo "Project path not found: $project_path" + exit 1 +fi + # Generate the Xcode project for iOS if [ "$BUILD_TYPE" == "dev" ]; then EXECUTE_METHOD="Builder.IosDev" + XCODE_OUTPUT_DIR="$project_path/mazerunner_dev_xcode" else EXECUTE_METHOD="Builder.IosRelease" + XCODE_OUTPUT_DIR="$project_path/mazerunner_xcode" +fi + +# Clean up old Xcode project if it exists +if [ -d "$XCODE_OUTPUT_DIR" ]; then + echo "Removing existing Xcode project: $XCODE_OUTPUT_DIR" + rm -rf "$XCODE_OUTPUT_DIR" fi +echo "Generating Xcode project for iOS ($BUILD_TYPE)..." +echo "Unity path: $UNITY_PATH/Unity" +echo "Project path: $project_path" +echo "Execute method: $EXECUTE_METHOD" +echo "Expected output: $XCODE_OUTPUT_DIR" + $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 "Xcode project generation failed with exit code $RESULT" + if [ -f "generateXcodeProject.log" ]; then + echo "Last 50 lines of generation log:" + tail -50 "generateXcodeProject.log" + fi + exit $RESULT +fi + +# Verify the Xcode project was created +if [ ! -d "$XCODE_OUTPUT_DIR" ]; then + echo "ERROR: Expected Xcode project directory not found: $XCODE_OUTPUT_DIR" + echo "Contents of project directory:" + ls -la "$project_path/" + exit 1 +fi + +if [ ! -d "$XCODE_OUTPUT_DIR/Unity-iPhone.xcodeproj" ]; then + echo "ERROR: Unity-iPhone.xcodeproj not found in: $XCODE_OUTPUT_DIR" + echo "Contents of Xcode directory:" + ls -la "$XCODE_OUTPUT_DIR/" + exit 1 +fi + +echo "โœ… Xcode project generation completed successfully!" +echo "Project location: $XCODE_OUTPUT_DIR" popd diff --git a/features/scripts/import_package.sh b/features/scripts/import_package.sh index b19fc953..52b4636d 100755 --- a/features/scripts/import_package.sh +++ b/features/scripts/import_package.sh @@ -32,13 +32,19 @@ BUGSNAG_RELEASE_URL="https://github.com/bugsnag/bugsnag-unity/releases/latest/do # Download the latest Bugsnag Unity package if it doesn't exist or override it echo "Downloading Bugsnag.unitypackage from $BUGSNAG_RELEASE_URL" -curl -L "$BUGSNAG_RELEASE_URL" -o "$PACKAGE_DOWNLOAD_PATH" -RESULT=$? -if [ $RESULT -ne 0 ]; then - echo "Failed to download Bugsnag.unitypackage" - exit $RESULT +if ! curl -L --fail --silent --show-error "$BUGSNAG_RELEASE_URL" -o "$PACKAGE_DOWNLOAD_PATH"; then + echo "Failed to download Bugsnag.unitypackage from $BUGSNAG_RELEASE_URL" + exit 1 fi +# Verify the downloaded file +if [ ! -f "$PACKAGE_DOWNLOAD_PATH" ] || [ ! -s "$PACKAGE_DOWNLOAD_PATH" ]; then + echo "Downloaded package is empty or missing: $PACKAGE_DOWNLOAD_PATH" + exit 1 +fi + +echo "Successfully downloaded Bugsnag.unitypackage ($(stat -f%z "$PACKAGE_DOWNLOAD_PATH" 2>/dev/null || stat -c%s "$PACKAGE_DOWNLOAD_PATH") bytes)" + # Check if Unity path exists if [ ! -f "$UNITY_PATH" ]; then echo "Unity executable not found at $UNITY_PATH" @@ -47,13 +53,20 @@ fi # Importing the Bugsnag package into Unity project echo "Importing Bugsnag.unitypackage into $FIXTURE_PATH" +echo "Unity path: $UNITY_PATH" +echo "Package path: $PACKAGE_DOWNLOAD_PATH" + "$UNITY_PATH" $DEFAULT_CLI_ARGS \ -projectPath $FIXTURE_PATH \ -ignoreCompilerErrors \ -importPackage "Bugsnag.unitypackage" RESULT=$? if [ $RESULT -ne 0 ]; then - echo "Failed to import Bugsnag.unitypackage" + echo "Unity package import failed with exit code $RESULT" + if [ -f "${FIXTURE_PATH}/import_package.log" ]; then + echo "Last 50 lines of import log:" + tail -50 "${FIXTURE_PATH}/import_package.log" + fi exit $RESULT fi diff --git a/features/scripts/run-macos-ci-tests.sh b/features/scripts/run-macos-ci-tests.sh index 08f73c7f..0e079fdf 100755 --- a/features/scripts/run-macos-ci-tests.sh +++ b/features/scripts/run-macos-ci-tests.sh @@ -22,16 +22,39 @@ fi pushd features/fixtures/mazerunner/ if [ "$BUILD_TYPE" == "dev" ]; then - unzip mazerunner_macos_dev_${UNITY_PERFORMANCE_VERSION:0:4}.zip + ZIP_FILE="mazerunner_macos_dev_${UNITY_PERFORMANCE_VERSION:0:4}.zip" APP_NAME="mazerunner_macos_dev_${UNITY_PERFORMANCE_VERSION:0:4}.app" else - unzip mazerunner_macos_${UNITY_PERFORMANCE_VERSION:0:4}.zip + ZIP_FILE="mazerunner_macos_${UNITY_PERFORMANCE_VERSION:0:4}.zip" APP_NAME="mazerunner_macos_${UNITY_PERFORMANCE_VERSION:0:4}.app" fi + +# Validate zip file exists +if [ ! -f "$ZIP_FILE" ]; then + echo "Error: Zip file $ZIP_FILE not found" + exit 1 +fi + +# Clean up any existing app directory before extraction +if [ -d "$APP_NAME" ]; then + echo "Removing existing app directory: $APP_NAME" + rm -rf "$APP_NAME" +fi + +# Extract with error handling +echo "Extracting $ZIP_FILE..." +if ! unzip -q "$ZIP_FILE"; then + echo "Error: Failed to extract $ZIP_FILE" + exit 1 +fi popd rm -rf Gemfile.lock -bundle install +echo "Installing bundle dependencies..." +if ! bundle install; then + echo "Error: Bundle install failed" + exit 1 +fi if [ "$BUILD_TYPE" == "dev" ]; then bundle exec maze-runner --app=features/fixtures/mazerunner/$APP_NAME --os=macos --fail-fast features/dev.feature diff --git a/features/scripts/run-webgl-ci-tests.sh b/features/scripts/run-webgl-ci-tests.sh index d3280c81..cc8bd674 100755 --- a/features/scripts/run-webgl-ci-tests.sh +++ b/features/scripts/run-webgl-ci-tests.sh @@ -11,18 +11,43 @@ BUILD_TYPE=$1 if [ "$BUILD_TYPE" == "dev" ]; then ZIP_FILE="mazerunner_webgl_dev_${UNITY_PERFORMANCE_VERSION:0:4}.zip" + EXTRACT_DIR="mazerunner_webgl_dev_${UNITY_PERFORMANCE_VERSION:0:4}" elif [ "$BUILD_TYPE" == "release" ]; then ZIP_FILE="mazerunner_webgl_${UNITY_PERFORMANCE_VERSION:0:4}.zip" + EXTRACT_DIR="mazerunner_webgl_${UNITY_PERFORMANCE_VERSION:0:4}" else echo "Invalid argument: $BUILD_TYPE. Use 'release' or 'dev'." exit 1 fi pushd features/fixtures/mazerunner/ - unzip $ZIP_FILE + +# Validate zip file exists +if [ ! -f "$ZIP_FILE" ]; then + echo "Error: Zip file $ZIP_FILE not found" + exit 1 +fi + +# Clean up any existing extracted directory +if [ -d "$EXTRACT_DIR" ]; then + echo "Removing existing directory: $EXTRACT_DIR" + rm -rf "$EXTRACT_DIR" +fi + +# Extract with error handling +echo "Extracting $ZIP_FILE..." +if ! unzip -q "$ZIP_FILE"; then + echo "Error: Failed to extract $ZIP_FILE" + exit 1 +fi + popd -bundle install +echo "Installing bundle dependencies..." +if ! bundle install; then + echo "Error: Bundle install failed" + exit 1 +fi if [ "$BUILD_TYPE" == "dev" ]; then bundle exec maze-runner --farm=local --browser=firefox --fail-fast features/dev.feature diff --git a/features/scripts/run-windows-ci-tests.sh b/features/scripts/run-windows-ci-tests.sh index 56316805..e849f751 100755 --- a/features/scripts/run-windows-ci-tests.sh +++ b/features/scripts/run-windows-ci-tests.sh @@ -12,19 +12,42 @@ BUILD_TYPE=$1 pushd features/fixtures/mazerunner/build if [ "$BUILD_TYPE" == "dev" ]; then - unzip Windows-dev-${UNITY_PERFORMANCE_VERSION:0:4}.zip + ZIP_FILE="Windows-dev-${UNITY_PERFORMANCE_VERSION:0:4}.zip" EXE_FILE="mazerunner_windows_dev.exe" elif [ "$BUILD_TYPE" == "release" ]; then - unzip Windows-${UNITY_PERFORMANCE_VERSION:0:4}.zip + ZIP_FILE="Windows-${UNITY_PERFORMANCE_VERSION:0:4}.zip" EXE_FILE="mazerunner_windows.exe" else echo "Invalid argument: $BUILD_TYPE. Use 'release' or 'dev'." exit 1 fi +# Validate zip file exists +if [ ! -f "$ZIP_FILE" ]; then + echo "Error: Zip file $ZIP_FILE not found" + exit 1 +fi + +# Clean up any existing Windows directory before extraction +if [ -d "Windows" ]; then + echo "Removing existing Windows directory" + rm -rf Windows +fi + +# Extract with error handling +echo "Extracting $ZIP_FILE..." +if ! unzip -q "$ZIP_FILE"; then + echo "Error: Failed to extract $ZIP_FILE" + exit 1 +fi + popd -bundle install +echo "Installing bundle dependencies..." +if ! bundle install; then + echo "Error: Bundle install failed" + exit 1 +fi if [ "$BUILD_TYPE" == "dev" ]; then bundle exec maze-runner --app=features/fixtures/mazerunner/build/Windows/$EXE_FILE --os=windows --fail-fast features/dev.feature diff --git a/features/support/env.rb b/features/support/env.rb index 43551f01..bc0738ab 100644 --- a/features/support/env.rb +++ b/features/support/env.rb @@ -119,12 +119,19 @@ $logger.info "Clearing #{support_dir}" FileUtils.rm_rf(support_dir) $logger.info 'Clearing User defaults' - Maze::Runner.run_command('defaults delete com.bugsnag.Mazerunner'); - Maze::Runner.run_command('defaults write com.bugsnag.Mazerunner ApplePersistenceIgnoreState YES'); - - # This is to get around a strange macos bug where clearing prefs does not work - $logger.info 'Killing defaults service' - Maze::Runner.run_command("killall -u #{ENV['USER']} cfprefsd") + begin + Maze::Runner.run_command('defaults delete com.bugsnag.Mazerunner 2>/dev/null || exit 0', timeout: 10); + Maze::Runner.run_command('defaults write com.bugsnag.Mazerunner ApplePersistenceIgnoreState YES', timeout: 10); + + # This is to get around a strange macOS bug where clearing prefs does not work + $logger.info 'Killing defaults service' + Maze::Runner.run_command("killall -u #{ENV['USER']} cfprefsd 2>/dev/null || exit 0", timeout: 10) + + # Give the defaults service time to restart + sleep 2 + rescue => e + $logger.warn "Failed to clear macOS defaults: #{e.message}" + end end end @@ -133,15 +140,29 @@ case Maze::Helper.get_current_platform when 'macos' - `killall Mazerunner` + # Kill processes with better error handling + system('killall Mazerunner 2>/dev/null') + # Give processes time to terminate gracefully + sleep 1 when 'windows' - Maze::Runner.run_command("/mnt/c/Windows/system32/taskkill.exe /IM mazerunner_windows.exe || exit 0") - Maze::Runner.run_command("/mnt/c/Windows/system32/taskkill.exe /IM mazerunner_windows_dev.exe || exit 0") + # Kill processes with better error handling and timeout + Maze::Runner.run_command("/mnt/c/Windows/system32/taskkill.exe /F /IM mazerunner_windows.exe 2>/dev/null || exit 0", timeout: 10) + Maze::Runner.run_command("/mnt/c/Windows/system32/taskkill.exe /F /IM mazerunner_windows_dev.exe 2>/dev/null || exit 0", timeout: 10) + # Give processes time to terminate + sleep 1 when 'webgl' - execute_command('close_application') + begin + execute_command('close_application') + rescue => e + $logger.warn "Failed to close WebGL application: #{e.message}" + end when 'switch' - # Terminate the app - Maze::Runner.run_command('ControlTarget.exe terminate') + begin + # Terminate the app with timeout + Maze::Runner.run_command('ControlTarget.exe terminate', timeout: 10) + rescue => e + $logger.warn "Failed to terminate Switch app: #{e.message}" + end end end diff --git a/scripts/code_format.sh b/scripts/code_format.sh index fc954a37..92907f8d 100755 --- a/scripts/code_format.sh +++ b/scripts/code_format.sh @@ -9,27 +9,66 @@ fi UNITY_PATH="/Applications/Unity/Hub/Editor/$UNITY_PERFORMANCE_VERSION/Unity.app/Contents/MacOS" DEFAULT_CLI_ARGS="-quit -batchmode -nographics" PROJECT_PATH="BugsnagPerformance" +SOLUTION_PATH="$PROJECT_PATH/BugsnagPerformance.sln" + +# Check if Unity executable exists +if [ ! -f "$UNITY_PATH/Unity" ]; then + echo "Unity executable not found at $UNITY_PATH/Unity" + exit 1 +fi + +# Check if project path exists +if [ ! -d "$PROJECT_PATH" ]; then + echo "Project path not found: $PROJECT_PATH" + exit 1 +fi + +echo "Generating .sln and project files..." +echo "Unity path: $UNITY_PATH/Unity" +echo "Project path: $PROJECT_PATH" # Generate .sln and project files $UNITY_PATH/Unity $DEFAULT_CLI_ARGS -projectPath "$PROJECT_PATH" -executeMethod "UnityEditor.SyncVS.SyncSolution" RESULT=$? if [ $RESULT -ne 0 ]; then + echo "Failed to generate solution files with exit code $RESULT" exit $RESULT fi +# Check if solution file was generated +if [ ! -f "$SOLUTION_PATH" ]; then + echo "Solution file not found after generation: $SOLUTION_PATH" + exit 1 +fi + +echo "Checking if dotnet is available..." +if ! command -v dotnet &> /dev/null; then + echo "dotnet command not found. Please install .NET SDK." + exit 1 +fi + # Decide which dotnet format command to run based on the argument FORMAT_COMMAND="dotnet format" if [ "$1" == "--verify" ]; then FORMAT_COMMAND="dotnet format --verify-no-changes" + echo "Running code format verification..." +else + echo "Running code format..." fi +echo "Command: $FORMAT_COMMAND \"$SOLUTION_PATH\"" + # Execute dotnet format -$FORMAT_COMMAND "$PROJECT_PATH/BugsnagPerformance.sln" +$FORMAT_COMMAND "$SOLUTION_PATH" EXIT_CODE=$? if [ "$EXIT_CODE" -ne 0 ]; then - echo "Error: Code formatting verification found issues." + if [ "$1" == "--verify" ]; then + echo "Error: Code formatting verification found issues. Run 'rake code:format' to fix them." + else + echo "Error: Code formatting failed." + fi exit "$EXIT_CODE" fi -echo "Done." \ No newline at end of file +echo "Code formatting completed successfully!" \ No newline at end of file