From 902ad3cd572a7667f311ad28ff7ea2cea7fc7800 Mon Sep 17 00:00:00 2001 From: Doan Thieu Date: Tue, 1 Aug 2023 14:56:24 +0700 Subject: [PATCH] [#4] Set up CD pipeline for deploying iOS staging build to TestFlight --- .../ios_deploy_staging_to_firebase.yml | 61 ----------------- .../ios_deploy_staging_to_testflight.yml | 68 +++++++++++++++++++ .../workflows/ios_deploy_to_testflight.yml | 53 --------------- ios/.gitignore | 2 + ios/fastlane/Constants/Environments.rb | 16 +++++ ios/fastlane/Fastfile | 16 ++++- 6 files changed, 99 insertions(+), 117 deletions(-) delete mode 100644 .github/workflows/ios_deploy_staging_to_firebase.yml create mode 100644 .github/workflows/ios_deploy_staging_to_testflight.yml delete mode 100644 .github/workflows/ios_deploy_to_testflight.yml diff --git a/.github/workflows/ios_deploy_staging_to_firebase.yml b/.github/workflows/ios_deploy_staging_to_firebase.yml deleted file mode 100644 index ddf71cc..0000000 --- a/.github/workflows/ios_deploy_staging_to_firebase.yml +++ /dev/null @@ -1,61 +0,0 @@ -name: ios-deploy-to-staging -on: - # Trigger the workflow on push action - push: - branches: - - develop - -jobs: - build_and_upload_staging_app_to_firebase: - name: Build And Upload iOS Staging Application To Firebase - runs-on: macOS-latest - env: - TEAM_ID: ${{ secrets.TEAM_ID }} - FASTLANE_USER: ${{ secrets.FASTLANE_USER }} - FASTLANE_PASSWORD: ${{ secrets.FASTLANE_PASSWORD }} - FASTLANE_APPLE_APPLICATION_SPECIFIC_PASSWORD: ${{ secrets.FASTLANE_APPLE_APPLICATION_SPECIFIC_PASSWORD }} - FASTLANE_SESSION: ${{ secrets.FASTLANE_SESSION }} - MATCH_PASSWORD: ${{ secrets.MATCH_PASSWORD }} - KEYCHAIN_PASSWORD: ${{ secrets.KEYCHAIN_PASSWORD }} - FIREBASE_CLI_TOKEN: ${{ secrets.FIREBASE_CLI_TOKEN }} - FIREBASE_APP_ID_STAGING: ${{ secrets.FIREBASE_IOS_APP_ID_STAGING }} - FIREBASE_DISTRIBUTION_TESTER_GROUPS: ${{ vars.FIREBASE_DISTRIBUTION_TESTER_GROUPS }} - steps: - - name: Check out - uses: actions/checkout@v3 - - - name: Install SSH key - uses: webfactory/ssh-agent@v0.4.1 - with: - ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }} - - - name: Set up Flutter environment - uses: subosito/flutter-action@v1 - with: - channel: 'stable' - flutter-version: '3.10.5' - - - name: Get Flutter dependencies - run: flutter pub get - - - name: Set up .env.staging - env: - ENV_STAGING: ${{ secrets.ENV_STAGING }} - run: | - echo $ENV_STAGING > .env.staging - - - name: Run code generator - run: flutter packages pub run build_runner build --delete-conflicting-outputs - - - name: Bundle install - run: cd ./ios && bundle install - - - name: Pod install - run: cd ./ios && pod install - - - name: Match Adhoc - run: cd ./ios && bundle exec fastlane sync_adhoc_staging_signing - - - name: Deploy to Firebase - run: | - cd ./ios && bundle exec fastlane build_and_upload_staging_app diff --git a/.github/workflows/ios_deploy_staging_to_testflight.yml b/.github/workflows/ios_deploy_staging_to_testflight.yml new file mode 100644 index 0000000..bfffa3a --- /dev/null +++ b/.github/workflows/ios_deploy_staging_to_testflight.yml @@ -0,0 +1,68 @@ +name: iOS - Deploy Staging build to TestFlight +on: + push: + branches: + - develop + +jobs: + build_and_upload_staging_to_testflight: + name: Build and upload iOS Staging build to TestFlight + runs-on: macOS-latest + steps: + - name: Check out + uses: actions/checkout@v3 + + - name: Install SSH key + uses: webfactory/ssh-agent@v0.8.0 + with: + ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }} + + - name: Set up Flutter environment + uses: subosito/flutter-action@v2 + with: + channel: 'stable' + flutter-version: '3.10.5' + - run: flutter --version + + - name: Set up deployment environment + env: + ENV_STAGING: ${{ secrets.ENV_STAGING }} + run: echo "$ENV_STAGING" > .env.staging + + - name: Get Flutter dependencies + run: flutter pub get + + - name: Run code generator + run: flutter packages pub run build_runner build --delete-conflicting-outputs + + - name: Cache Ruby gems + uses: actions/cache@v3 + id: bunlderCache + with: + path: ios/vendor/bundle + key: ${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }} + restore-keys: ${{ runner.os }}-gems- + + - name: Cache Pods + uses: actions/cache@v3 + id: cocoapodCache + with: + path: ios/Pods + key: ${{ runner.os }}-pods-${{ hashFiles('**/Podfile.lock') }} + restore-keys: ${{ runner.os }}-pods- + + - name: Install iOS dependencies + run: cd ios && bundle install --path vendor/bundle && bundle exec pod install + + - name: Sync certificates and profiles + env: + MATCH_PASSWORD: ${{ secrets.MATCH_PASSPHRASE }} + run: cd ios && bundle exec fastlane sync_appstore_staging_signing + + - name: Build and Deploy to TestFlight + env: + TEAM_ID: ${{ secrets.APPLE_TEAM_ID }} + APPSTORE_CONNECT_API_KEY_ID: ${{ secrets.APPSTORE_CONNECT_API_KEY_ID }} + APPSTORE_CONNECT_ISSUER_ID: ${{ secrets.APPSTORE_CONNECT_ISSUER_ID }} + APPSTORE_CONNECT_API_KEY_CONTENT: ${{ secrets.APPSTORE_CONNECT_API_KEY_CONTENT }} + run: cd ios && bundle exec fastlane build_and_upload_staging_to_testflight diff --git a/.github/workflows/ios_deploy_to_testflight.yml b/.github/workflows/ios_deploy_to_testflight.yml deleted file mode 100644 index 51d1bef..0000000 --- a/.github/workflows/ios_deploy_to_testflight.yml +++ /dev/null @@ -1,53 +0,0 @@ -name: ios-deploy-to-testflight -on: - # Trigger the workflow on push action - push: - branches: - - develop - -jobs: - build_and_upload_to_testflight: - name: Build And Upload iOS Application To TestFlight - runs-on: macOS-latest - timeout-minutes: 30 - env: - TEAM_ID: ${{ secrets.TEAM_ID }} - FASTLANE_USER: ${{ secrets.FASTLANE_USER }} - FASTLANE_PASSWORD: ${{ secrets.FASTLANE_PASSWORD }} - FASTLANE_APPLE_APPLICATION_SPECIFIC_PASSWORD: ${{ secrets.FASTLANE_APPLE_APPLICATION_SPECIFIC_PASSWORD }} - FASTLANE_SESSION: ${{ secrets.FASTLANE_SESSION }} - MATCH_PASSWORD: ${{ secrets.MATCH_PASSWORD }} - KEYCHAIN_PASSWORD: ${{ secrets.KEYCHAIN_PASSWORD }} - steps: - - name: Check out - uses: actions/checkout@v3 - - - name: Install SSH key - uses: webfactory/ssh-agent@v0.4.1 - with: - ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }} - - - name: Set up Flutter environment - uses: subosito/flutter-action@v2 - with: - channel: 'stable' - flutter-version: '3.10.5' - - - name: Get Flutter dependencies - run: flutter pub get - - - name: Run code generator - run: flutter packages pub run build_runner build --delete-conflicting-outputs - - - name: Bundle install - run: cd ./ios && bundle install - - - name: Pod install - run: cd ./ios && pod install - - - name: Match AppStore - run: cd ./ios && bundle exec fastlane sync_appstore_staging_signing - - - name: Deploy to TestFlight - run: | - cd ./ios && bundle exec fastlane build_and_upload_testflight_app diff --git a/ios/.gitignore b/ios/.gitignore index 44f0aa3..aa44815 100644 --- a/ios/.gitignore +++ b/ios/.gitignore @@ -33,6 +33,8 @@ DerivedData/ fastlane/README.md fastlane/report.xml .envfile +.bundle +vendor/bundle # Exceptions to above rules. !default.mode1v3 diff --git a/ios/fastlane/Constants/Environments.rb b/ios/fastlane/Constants/Environments.rb index a7066d3..7aa5872 100644 --- a/ios/fastlane/Constants/Environments.rb +++ b/ios/fastlane/Constants/Environments.rb @@ -3,6 +3,10 @@ def self.CI ENV['CI'] end + def self.BUILD_NUMBER + ENV["BUILD_NUMBER"] + end + def self.MANUAL_VERSION ENV['MANUAL_VERSION'] end @@ -15,6 +19,18 @@ def self.TEAM_ID ENV['TEAM_ID'] end + def self.APPSTORE_CONNECT_API_KEY_ID + ENV['APPSTORE_CONNECT_API_KEY_ID'] + end + + def self.APPSTORE_CONNECT_ISSUER_ID + ENV['APPSTORE_CONNECT_ISSUER_ID'] + end + + def self.APPSTORE_CONNECT_API_KEY_CONTENT + ENV['APPSTORE_CONNECT_API_KEY_CONTENT'] + end + ################# ### Firebase ### ################# diff --git a/ios/fastlane/Fastfile b/ios/fastlane/Fastfile index d86dd00..d29d1b7 100644 --- a/ios/fastlane/Fastfile +++ b/ios/fastlane/Fastfile @@ -56,7 +56,7 @@ platform :ios do # Testflight desc 'Build and upload Staging app to Test Flight' - lane :build_and_upload_testflight_app do + lane :build_and_upload_staging_to_testflight_app do set_app_version bump_build builder.build_app_store( @@ -138,10 +138,10 @@ platform :ios do end end - desc 'set build number with number of commits' + desc 'set build number' private_lane :bump_build do increment_build_number( - build_number: number_of_commits, + build_number: Environments.BUILD_NUMBER, xcodeproj: Constants.PROJECT_PATH ) end @@ -155,4 +155,14 @@ platform :ios do notes: "" ) end + + desc 'set App Store Connect API Key' + private_lane :set_appstore_connect_api_key do + app_store_connect_api_key( + key_id: Environments.APPSTORE_CONNECT_API_KEY_ID, + issuer_id: Environments.APPSTORE_CONNECT_ISSUER_ID, + key_content: Environments.APPSTORE_CONNECT_API_KEY_CONTENT, + is_key_content_base64: true + ) + end end