From 352d77d9780d71c69373e1addc36527abec1491c Mon Sep 17 00:00:00 2001 From: Aaron Alaniz Date: Thu, 28 Sep 2023 04:06:55 -0500 Subject: [PATCH] Improve CI and fix iOS debug build (#9) --- .../actions/setup-lightsaber-ci/action.yml | 27 ++++++- .github/workflows/lightsaber-ci.yml | 80 +++++++++++++++++-- iosApp/iosApp.xcodeproj/project.pbxproj | 14 +++- .../aaron/lightsaber/audio/IosSoundPlayer.kt | 1 + 4 files changed, 107 insertions(+), 15 deletions(-) diff --git a/.github/actions/setup-lightsaber-ci/action.yml b/.github/actions/setup-lightsaber-ci/action.yml index eb2f637..fd70910 100644 --- a/.github/actions/setup-lightsaber-ci/action.yml +++ b/.github/actions/setup-lightsaber-ci/action.yml @@ -23,9 +23,30 @@ runs: path: | androidApp/build - - name: iOS App Build Cache + - name: iOS App Debug iphoneos Build Cache uses: actions/cache@v3 with: - key: build-ios-${{ github.sha }} + key: build-ios-debug-iphoneos-${{ github.sha }} path: | - build \ No newline at end of file + iosApp/build/ios/Debug-iphoneos + + - name: iOS App Release iphoneos Build Cache + uses: actions/cache@v3 + with: + key: build-ios-release-iphoneos-${{ github.sha }} + path: | + iosApp/build/ios/Release-iphoneos + + - name: iOS App Debug iphonesimulator Build Cache + uses: actions/cache@v3 + with: + key: build-ios-debug-iphonesimulator-${{ github.sha }} + path: | + iosApp/build/ios/Debug-iphonesimulator + + - name: iOS App Release iphonesimulator Build Cache + uses: actions/cache@v3 + with: + key: build-ios-release-iphonesimulator-${{ github.sha }} + path: | + iosApp/build/ios/Release-iphonesimulator \ No newline at end of file diff --git a/.github/workflows/lightsaber-ci.yml b/.github/workflows/lightsaber-ci.yml index 4203071..1460461 100644 --- a/.github/workflows/lightsaber-ci.yml +++ b/.github/workflows/lightsaber-ci.yml @@ -20,7 +20,7 @@ jobs: - name: Build Shared # TODO Understand why compileIosMainKotlinMetadata fails every time - run: ./gradlew shared:build -x compileIosMainKotlinMetadata + run: ./gradlew shared:assemble -x compileIosMainKotlinMetadata build-androidApp: runs-on: macos-latest @@ -32,20 +32,67 @@ jobs: - name: Build Android App run: ./gradlew androidApp:build - build-debug-iosApp: + build-iosApp: runs-on: macos-latest + strategy: + matrix: + configuration: [Debug, Release] + target: [iphonesimulator, iphoneos] needs: build-shared steps: - uses: actions/checkout@v3 - uses: ./.github/actions/setup-lightsaber-ci + # Signing Xcode applications + # https://docs.github.com/en/actions/deployment/deploying-xcode-applications/installing-an-apple-certificate-on-macos-runners-for-xcode-development + - name: Install the Apple certificate and provisioning profile + env: + BUILD_CERTIFICATE_BASE64: ${{ secrets.BUILD_CERTIFICATE_BASE64 }} + P12_PASSWORD: ${{ secrets.P12_PASSWORD }} + BUILD_PROVISION_PROFILE_BASE64: ${{ secrets.BUILD_PROVISION_PROFILE_BASE64 }} + KEYCHAIN_PASSWORD: ${{ secrets.KEYCHAIN_PASSWORD }} + run: | + # create variables + CERTIFICATE_PATH=$RUNNER_TEMP/build_certificate.p12 + PP_PATH=$RUNNER_TEMP/build_pp.mobileprovision + KEYCHAIN_PATH=$RUNNER_TEMP/app-signing.keychain-db + + # import certificate and provisioning profile from secrets + echo -n "$BUILD_CERTIFICATE_BASE64" | base64 --decode -o $CERTIFICATE_PATH + echo -n "$BUILD_PROVISION_PROFILE_BASE64" | base64 --decode -o $PP_PATH + + # create temporary keychain + security create-keychain -p "$KEYCHAIN_PASSWORD" $KEYCHAIN_PATH + security set-keychain-settings -lut 21600 $KEYCHAIN_PATH + security unlock-keychain -p "$KEYCHAIN_PASSWORD" $KEYCHAIN_PATH + + # import certificate to keychain + security import $CERTIFICATE_PATH -P "$P12_PASSWORD" -A -t cert -f pkcs12 -k $KEYCHAIN_PATH + security list-keychain -d user -s $KEYCHAIN_PATH + + # apply provisioning profile + mkdir -p ~/Library/MobileDevice/Provisioning\ Profiles + cp $PP_PATH ~/Library/MobileDevice/Provisioning\ Profiles + - name: Shared Pod Install - run: ./gradlew shared:podInstall + run: ./gradlew podInstall + + - name: Build iOS App + env: + LIGHTSABER_TEAM_ID: ${{ secrets.LIGHTSABER_TEAM_ID }} + run: | + xcodebuild -workspace ${{ github.workspace }}/iosApp/iosApp.xcworkspace \ + -scheme iosApp \ + -configuration ${{ matrix.configuration }} \ + -xcconfig ${{ github.workspace }}/iosApp/Configuration/Config.xcconfig \ + OBJROOT=${{ github.workspace }}/iosApp/build/ios SYMROOT=${{ github.workspace }}/iosApp/build/ios \ + -sdk ${{ matrix.target }} - # TODO Setup xcodebuild command correctly - # - name: Build Debug iOS App - # run: xcodebuild -workspace ./iosApp/iosApp.xcworkspace -scheme iosApp -configuration Debug | - # OBJROOT=./build/ios SYMROOT=./build/ios -arch arm64 -allowProvisioningUpdates + - name: Clean up keychain and provisioning profile + if: ${{ always() }} + run: | + security delete-keychain $RUNNER_TEMP/app-signing.keychain-db + rm ~/Library/MobileDevice/Provisioning\ Profiles/build_pp.mobileprovision test-shared: runs-on: macos-latest @@ -67,4 +114,21 @@ jobs: - uses: mobile-dev-inc/action-maestro-cloud@v1.1.0 with: api-key: ${{ secrets.MAESTRO_CLOUD_API_KEY }} - app-file: androidApp/build/outputs/apk/debug/androidApp-debug.apk \ No newline at end of file + app-file: androidApp/build/outputs/apk/debug/androidApp-debug.apk + + e2e-test-iosApp: + runs-on: macos-latest + needs: build-iosApp + steps: + - uses: actions/checkout@v3 + - uses: ./.github/actions/setup-lightsaber-ci + + + # TODO Run e2e tests when Compose Multiplatform supports either Compose test tags or + # accessibility labels + - name: Check for app file + run: test -e ./iosApp/build/ios/Release-iphonesimulator/Lightsaber.app +# - uses: mobile-dev-inc/action-maestro-cloud@v1.1.0 +# with: +# api-key: ${{ secrets.MAESTRO_CLOUD_API_KEY }} +# app-file: ./iosApp/build/ios/Release-iphonesimulator/Lightsaber.app \ No newline at end of file diff --git a/iosApp/iosApp.xcodeproj/project.pbxproj b/iosApp/iosApp.xcodeproj/project.pbxproj index 3c74208..40bbec7 100644 --- a/iosApp/iosApp.xcodeproj/project.pbxproj +++ b/iosApp/iosApp.xcodeproj/project.pbxproj @@ -353,9 +353,11 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_IDENTITY = "Apple Development"; - CODE_SIGN_STYLE = Automatic; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + CODE_SIGN_STYLE = Manual; DEVELOPMENT_ASSET_PATHS = "\"iosApp/Preview Content\""; - DEVELOPMENT_TEAM = "${TEAM_ID}"; + DEVELOPMENT_TEAM = ""; + "DEVELOPMENT_TEAM[sdk=iphoneos*]" = "${TEAM_ID}"; ENABLE_PREVIEWS = YES; INFOPLIST_FILE = iosApp/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 14.1; @@ -366,6 +368,7 @@ PRODUCT_BUNDLE_IDENTIFIER = "${BUNDLE_ID}"; PRODUCT_NAME = "${APP_NAME}"; PROVISIONING_PROFILE_SPECIFIER = ""; + "PROVISIONING_PROFILE_SPECIFIER[sdk=iphoneos*]" = "lightsaber-development"; SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; }; @@ -377,9 +380,11 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CODE_SIGN_IDENTITY = "Apple Development"; - CODE_SIGN_STYLE = Automatic; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + CODE_SIGN_STYLE = Manual; DEVELOPMENT_ASSET_PATHS = "\"iosApp/Preview Content\""; - DEVELOPMENT_TEAM = "${TEAM_ID}"; + DEVELOPMENT_TEAM = ""; + "DEVELOPMENT_TEAM[sdk=iphoneos*]" = "${TEAM_ID}"; ENABLE_PREVIEWS = YES; INFOPLIST_FILE = iosApp/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 14.1; @@ -390,6 +395,7 @@ PRODUCT_BUNDLE_IDENTIFIER = "${BUNDLE_ID}"; PRODUCT_NAME = "${APP_NAME}"; PROVISIONING_PROFILE_SPECIFIER = ""; + "PROVISIONING_PROFILE_SPECIFIER[sdk=iphoneos*]" = "lightsaber-development"; SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; }; diff --git a/shared/src/iosMain/kotlin/xyz/alaniz/aaron/lightsaber/audio/IosSoundPlayer.kt b/shared/src/iosMain/kotlin/xyz/alaniz/aaron/lightsaber/audio/IosSoundPlayer.kt index 29f2572..c7973f7 100644 --- a/shared/src/iosMain/kotlin/xyz/alaniz/aaron/lightsaber/audio/IosSoundPlayer.kt +++ b/shared/src/iosMain/kotlin/xyz/alaniz/aaron/lightsaber/audio/IosSoundPlayer.kt @@ -89,6 +89,7 @@ class IosSoundPlayer(private val audioEngine: AVAudioEngine) : SoundPlayer { } soundResourceToPlayerNodeMap.clear() } + playingSounds.clear() audioEngine.stop() }