From 78c780b3b604840241ab8574ad04b60c5e7d0606 Mon Sep 17 00:00:00 2001 From: Gergely Hegedus Date: Tue, 5 Sep 2023 12:24:55 +0300 Subject: [PATCH] ios job --- .github/workflows/deploy_to_firebase.yml | 105 +++++++++++++++++----- ios/Gemfile | 3 + ios/Gemfile.lock | 5 ++ ios/InitProject.xcodeproj/project.pbxproj | 21 ++++- ios/fastlane/Appfile | 2 +- ios/fastlane/Fastfile | 87 +++++++++++++++++- ios/fastlane/Pluginfile | 5 ++ ios/fastlane/README.md | 48 ++++++++++ 8 files changed, 249 insertions(+), 27 deletions(-) create mode 100644 ios/fastlane/Pluginfile create mode 100644 ios/fastlane/README.md diff --git a/.github/workflows/deploy_to_firebase.yml b/.github/workflows/deploy_to_firebase.yml index 8f0369b..33cd178 100644 --- a/.github/workflows/deploy_to_firebase.yml +++ b/.github/workflows/deploy_to_firebase.yml @@ -4,19 +4,67 @@ on: workflow_dispatch: jobs: - android-publish-to-firebase: - runs-on: ubuntu-latest +# android-publish-to-firebase: +# runs-on: ubuntu-latest +# permissions: +# contents: read +# steps: +# - name: Checkout repository +# uses: actions/checkout@v3 +# - name: Setup Java +# uses: actions/setup-java@v3 +# with: +# distribution: 'adopt' +# java-version: '11' +# cache: gradle +# - name: Setup Node +# uses: actions/setup-node@v3 +# with: +# node-version: 16 +# cache: 'npm' +# - name: Set up Ruby +# uses: ruby/setup-ruby@ec02537da5712d66d4d50a0f33b7eb52773b5ed1 +# with: +# ruby-version: '3.2.1' +# - name: Setup Fastlane +# working-directory: ./android +# run: bundle install +# - name: node_modules cache +# uses: actions/cache@v3 +# id: npm-cache +# with: +# path: node_modules +# key: ${{ runner.os }}-npm-${{ hashFiles('**/package-lock.json') }} +# restore-keys: ${{ runner.os }}-npm-${{ hashFiles('**/package-lock.json') }} +# - name: Install Dependencies +# run: npm ci +# - name: Restore Release Keystore +# env: +# keystore_base64: ${{ secrets.RELEASE_KEYSTORE_BASE64 }} +# run: | +# echo "$keystore_base64" | base64 --decode > release.keystore +# echo "CI_EVALUATION_KEYSTORE_FILE=`pwd`/release.keystore" >> $GITHUB_ENV +# - name: Restore Firebase Service Account +# env: +# firebase_service_account_base64: ${{ secrets.FIREBASE_SERVICE_ACCOUNT_BASE64 }} +# run: | +# echo "$firebase_service_account_base64" | base64 --decode > firebase-distribution-service-account.json +# echo "CI_EVALUATION_FIREBASE_SERVICE_ACCOUNT_FILE=`pwd`/firebase-distribution-service-account.json" >> $GITHUB_ENV +# - name: Deploy to Firebase +# env: +# CI_EVALUATION_KEY_ALIAS: ${{ secrets.CI_EVALUATION_KEY_ALIAS }} +# CI_EVALUATION_KEY_PASSWORD: ${{ secrets.CI_EVALUATION_KEY_PASSWORD }} +# CI_EVALUATION_STORE_PASSWORD: ${{ secrets.CI_EVALUATION_STORE_PASSWORD }} +# working-directory: ./android +# run: bundle exec fastlane deployInternalFirebase + + ios-publish-to-firebase: + runs-on: macos-latest permissions: contents: read steps: - name: Checkout repository uses: actions/checkout@v3 - - name: Setup Java - uses: actions/setup-java@v3 - with: - distribution: 'adopt' - java-version: '11' - cache: gradle - name: Setup Node uses: actions/setup-node@v3 with: @@ -27,7 +75,7 @@ jobs: with: ruby-version: '3.2.1' - name: Setup Fastlane - working-directory: ./android + working-directory: ./ios run: bundle install - name: node_modules cache uses: actions/cache@v3 @@ -38,22 +86,39 @@ jobs: restore-keys: ${{ runner.os }}-npm-${{ hashFiles('**/package-lock.json') }} - name: Install Dependencies run: npm ci - - name: Restore Release Keystore - env: - keystore_base64: ${{ secrets.RELEASE_KEYSTORE_BASE64 }} - run: | - echo "$keystore_base64" | base64 --decode > release.keystore - echo "CI_EVALUATION_KEYSTORE_FILE=`pwd`/release.keystore" >> $GITHUB_ENV + - name: pod install cache + uses: actions/cache@v3 + id: pod-cache + with: + path: ios/Pods + key: ${{ runner.os }}-pod-${{ hashFiles('ios/Podfile.lock') }} + restore-keys: ${{ runner.os }}-pod-${{ hashFiles('ios/Podfile.lock') }} + - name: Install iOS Dependencies + working-directory: ./ios + run: pod install - name: Restore Firebase Service Account env: firebase_service_account_base64: ${{ secrets.FIREBASE_SERVICE_ACCOUNT_BASE64 }} run: | echo "$firebase_service_account_base64" | base64 --decode > firebase-distribution-service-account.json echo "CI_EVALUATION_FIREBASE_SERVICE_ACCOUNT_FILE=`pwd`/firebase-distribution-service-account.json" >> $GITHUB_ENV + - name: Restore Provisioning Profile + env: + ci_evaluation_provision_profile_base64: ${{ secrets.CI_EVALUATION_PROVISION_PROFILE_BASE64 }} + run: | + echo "$ci_evaluation_provision_profile_base64" | base64 --decode > profile.mobileprovision + mkdir -p ~/Library/MobileDevice/Provisioning\ Profiles + cp profile.mobileprovision ~/Library/MobileDevice/Provisioning\ Profiles/profile.mobileprovision + echo "CI_EVALUATION_PROVISIONING_PROFILE_FILE=\"~/Library/MobileDevice/Provisioning Profiles/profile.mobileprovision\"" >> $GITHUB_ENV + - name: Restore iOS Cert + env: + ci_evaluation_cert_base64: ${{ secrets.CI_EVALUATION_CERT_BASE64 }} + run: | + echo "$ci_evaluation_cert_base64" | base64 --decode > ios_distribution.p12 + echo "CI_EVALUATION_IOS_CERT_FILE=`pwd`/ios_distribution.p12" >> $GITHUB_ENV - name: Deploy to Firebase env: - CI_EVALUATION_KEY_ALIAS: ${{ secrets.CI_EVALUATION_KEY_ALIAS }} - CI_EVALUATION_KEY_PASSWORD: ${{ secrets.CI_EVALUATION_KEY_PASSWORD }} - CI_EVALUATION_STORE_PASSWORD: ${{ secrets.CI_EVALUATION_STORE_PASSWORD }} - working-directory: ./android - run: bundle exec fastlane deployInternalFirebase + CI_EVALUATION_CERTIFICATE_PASSWORD: ${{ secrets.CI_EVALUATION_CERTIFICATE_PASSWORD }} + CI_EVALUATION_APP_IDENTIFIER: ${{ secrets.CI_EVALUATION_APP_IDENTIFIER }} + working-directory: ./ios + run: bundle exec fastlane deployInternalFirebase \ No newline at end of file diff --git a/ios/Gemfile b/ios/Gemfile index 7a118b4..cdd3a6b 100644 --- a/ios/Gemfile +++ b/ios/Gemfile @@ -1,3 +1,6 @@ source "https://rubygems.org" gem "fastlane" + +plugins_path = File.join(File.dirname(__FILE__), 'fastlane', 'Pluginfile') +eval_gemfile(plugins_path) if File.exist?(plugins_path) diff --git a/ios/Gemfile.lock b/ios/Gemfile.lock index 4551af7..1911269 100644 --- a/ios/Gemfile.lock +++ b/ios/Gemfile.lock @@ -105,6 +105,8 @@ GEM xcodeproj (>= 1.13.0, < 2.0.0) xcpretty (~> 0.3.0) xcpretty-travis-formatter (>= 0.0.3) + fastlane-plugin-firebase_app_distribution (0.7.2) + google-apis-firebaseappdistribution_v1 (~> 0.3.0) gh_inspector (1.1.3) google-apis-androidpublisher_v3 (0.49.0) google-apis-core (>= 0.11.0, < 2.a) @@ -117,6 +119,8 @@ GEM retriable (>= 2.0, < 4.a) rexml webrick + google-apis-firebaseappdistribution_v1 (0.3.0) + google-apis-core (>= 0.11.0, < 2.a) google-apis-iamcredentials_v1 (0.17.0) google-apis-core (>= 0.11.0, < 2.a) google-apis-playcustomapp_v1 (0.13.0) @@ -213,6 +217,7 @@ PLATFORMS DEPENDENCIES fastlane + fastlane-plugin-firebase_app_distribution BUNDLED WITH 2.4.10 diff --git a/ios/InitProject.xcodeproj/project.pbxproj b/ios/InitProject.xcodeproj/project.pbxproj index 91eb0c7..d90877e 100644 --- a/ios/InitProject.xcodeproj/project.pbxproj +++ b/ios/InitProject.xcodeproj/project.pbxproj @@ -433,6 +433,7 @@ baseConfigurationReference = 5B7EB9410499542E8C5724F5 /* Pods-InitProject-InitProjectTests.debug.xcconfig */; buildSettings = { BUNDLE_LOADER = "$(TEST_HOST)"; + DEVELOPMENT_TEAM = Y6P2NYW2G8; GCC_PREPROCESSOR_DEFINITIONS = ( "DEBUG=1", "$(inherited)", @@ -461,6 +462,7 @@ buildSettings = { BUNDLE_LOADER = "$(TEST_HOST)"; COPY_PHASE_STRIP = NO; + DEVELOPMENT_TEAM = Y6P2NYW2G8; INFOPLIST_FILE = InitProjectTests/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 12.4; LD_RUNPATH_SEARCH_PATHS = ( @@ -475,6 +477,8 @@ ); PRODUCT_BUNDLE_IDENTIFIER = "org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; + PROVISIONING_PROFILE = "6f52a894-60c1-4aff-9863-e6f5c719c29e"; + PROVISIONING_PROFILE_SPECIFIER = "CI Test Draft App Profile"; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/InitProject.app/InitProject"; }; name = Release; @@ -485,7 +489,10 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; + CODE_SIGN_STYLE = Manual; CURRENT_PROJECT_VERSION = 1; + DEVELOPMENT_TEAM = Y6P2NYW2G8; + "DEVELOPMENT_TEAM[sdk=iphoneos*]" = Y6P2NYW2G8; ENABLE_BITCODE = NO; INFOPLIST_FILE = InitProject/Info.plist; LD_RUNPATH_SEARCH_PATHS = ( @@ -498,8 +505,10 @@ "-ObjC", "-lc++", ); - PRODUCT_BUNDLE_IDENTIFIER = "org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier)"; + PRODUCT_BUNDLE_IDENTIFIER = test; PRODUCT_NAME = InitProject; + PROVISIONING_PROFILE_SPECIFIER = ""; + "PROVISIONING_PROFILE_SPECIFIER[sdk=iphoneos*]" = "Gergely Hegedus Development Profile"; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; SWIFT_VERSION = 5.0; VERSIONING_SYSTEM = "apple-generic"; @@ -512,7 +521,12 @@ buildSettings = { ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; + CODE_SIGN_IDENTITY = "Apple Development"; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Distribution"; + CODE_SIGN_STYLE = Manual; CURRENT_PROJECT_VERSION = 1; + DEVELOPMENT_TEAM = Y6P2NYW2G8; + "DEVELOPMENT_TEAM[sdk=iphoneos*]" = Y6P2NYW2G8; INFOPLIST_FILE = InitProject/Info.plist; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", @@ -524,8 +538,11 @@ "-ObjC", "-lc++", ); - PRODUCT_BUNDLE_IDENTIFIER = "org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier)"; + PRODUCT_BUNDLE_IDENTIFIER = test; PRODUCT_NAME = InitProject; + PROVISIONING_PROFILE = "6f52a894-60c1-4aff-9863-e6f5c719c29e"; + PROVISIONING_PROFILE_SPECIFIER = "CI Test Draft App Profile"; + "PROVISIONING_PROFILE_SPECIFIER[sdk=iphoneos*]" = "CI Test Draft App Profile"; SWIFT_VERSION = 5.0; VERSIONING_SYSTEM = "apple-generic"; }; diff --git a/ios/fastlane/Appfile b/ios/fastlane/Appfile index 4282947..1e6fb34 100644 --- a/ios/fastlane/Appfile +++ b/ios/fastlane/Appfile @@ -1,6 +1,6 @@ # app_identifier("[[APP_IDENTIFIER]]") # The bundle identifier of your app # apple_id("[[APPLE_ID]]") # Your Apple Developer Portal username - +team_id("Y6P2NYW2G8") # For more information about the Appfile, see: # https://docs.fastlane.tools/advanced/#appfile diff --git a/ios/fastlane/Fastfile b/ios/fastlane/Fastfile index 0f39ea6..475cd32 100644 --- a/ios/fastlane/Fastfile +++ b/ios/fastlane/Fastfile @@ -16,8 +16,87 @@ default_platform(:ios) platform :ios do - desc "Description of what the lane does" - lane :custom_lane do - # add actions here: https://docs.fastlane.tools/actions + + before_all do + FIREBASE_APP_DISTRIBUTION_APP_STAGING = "1:64659984801:ios:a9c4640d2a1960a5f43be0" + FIREBASE_APP_DISTRIBUTION_GROUPS_QA = "ios-qa" + FIREBASE_SERVICE_ACCOUNT_FILE = ENV['CI_EVALUATION_FIREBASE_SERVICE_ACCOUNT_FILE'] + KEYCHAIN_NAME = "temp_keychain" + PROVISIONING_PROFILE_FILE = ENV['CI_EVALUATION_PROVISIONING_PROFILE_FILE'] + CERTIFICATE_PASSWORD = ENV['CI_EVALUATION_CERTIFICATE_PASSWORD'].strip + PROVISIONING_PROFILE_FILE = "#{ENV['HOME']}/Library/MobileDevice/Provisioning Profiles/profile.mobileprovision" + IOS_CERT_FILE = ENV['CI_EVALUATION_IOS_CERT_FILE'] + APP_IDENTIFIER = ENV['CI_EVALUATION_APP_IDENTIFIER'] end -end + + lane :setupCodeSigning do + password = (0...50).map { ('a'..'z').to_a[rand(26)] }.join + cleanupKeyChain() + create_keychain( + name: KEYCHAIN_NAME, + default_keychain: false, + unlock: true, + timeout: 360000, + lock_when_sleeps: false, + add_to_search_list: true, + password: password + ) + import_certificate( + certificate_path: IOS_CERT_FILE, + keychain_name: KEYCHAIN_NAME, + keychain_password: password, + certificate_password: CERTIFICATE_PASSWORD, + log_output: true + ) + update_app_identifier( + plist_path: "InitProject/Info.plist", + app_identifier: APP_IDENTIFIER + ) + update_project_provisioning( + xcodeproj: "InitProject.xcodeproj", + target_filter: "InitProject", + profile: PROVISIONING_PROFILE_FILE, + build_configuration: "Release" + ) + update_project_team( # Set the right team on your project + teamid: CredentialsManager::AppfileConfig.try_fetch_value(:team_id) + ) + unlock_keychain( + path: KEYCHAIN_NAME, + password: password + ) + end + + desc "Description of what the lane does" + lane :deployInternalFirebase do + setupCodeSigning() + ipa_name = "Internal.ipa" + + build_app( + scheme: "InitProject", + export_method: "ad-hoc", + output_directory: "./builds", + output_name: ipa_name + ) + + firebase_app_distribution( + service_credentials_file: FIREBASE_SERVICE_ACCOUNT_FILE, + app: FIREBASE_APP_DISTRIBUTION_APP_STAGING, + groups: FIREBASE_APP_DISTRIBUTION_GROUPS_QA, + ipa_path: "builds/#{ipa_name}", + ) + cleanupKeyChain() + end + + lane :cleanupKeyChain do + begin + delete_keychain(name: KEYCHAIN_NAME) if File.exist? File.expand_path("/Users/runner/Library/Keychains/#{KEYCHAIN_NAME}-db") + rescue => ex + UI.important('Could not delete keychain!') + end + end + + after_all do + cleanupKeyChain() + end +end \ No newline at end of file diff --git a/ios/fastlane/Pluginfile b/ios/fastlane/Pluginfile new file mode 100644 index 0000000..b18539b --- /dev/null +++ b/ios/fastlane/Pluginfile @@ -0,0 +1,5 @@ +# Autogenerated by fastlane +# +# Ensure this file is checked in to source control! + +gem 'fastlane-plugin-firebase_app_distribution' diff --git a/ios/fastlane/README.md b/ios/fastlane/README.md new file mode 100644 index 0000000..a0d5955 --- /dev/null +++ b/ios/fastlane/README.md @@ -0,0 +1,48 @@ +fastlane documentation +---- + +# Installation + +Make sure you have the latest version of the Xcode command line tools installed: + +```sh +xcode-select --install +``` + +For _fastlane_ installation instructions, see [Installing _fastlane_](https://docs.fastlane.tools/#installing-fastlane) + +# Available Actions + +## iOS + +### ios setupCodeSigning + +```sh +[bundle exec] fastlane ios setupCodeSigning +``` + + + +### ios deployInternalFirebase + +```sh +[bundle exec] fastlane ios deployInternalFirebase +``` + +Description of what the lane does + +### ios cleanupKeyChain + +```sh +[bundle exec] fastlane ios cleanupKeyChain +``` + + + +---- + +This README.md is auto-generated and will be re-generated every time [_fastlane_](https://fastlane.tools) is run. + +More information about _fastlane_ can be found on [fastlane.tools](https://fastlane.tools). + +The documentation of _fastlane_ can be found on [docs.fastlane.tools](https://docs.fastlane.tools).