From fa4a6812f7693fb84f424badcb84d6fa9170a875 Mon Sep 17 00:00:00 2001 From: David Date: Tue, 22 Aug 2023 09:35:22 +0700 Subject: [PATCH] [#510] Add function remove in Keychain to remove keychain in case the runner is self-hosted Add new fastlane lane removeKeychain Add remove keychain step in github action workflow Add continue-on-error: true for step remove keychain --- .github/workflows/deploy_app_store.yml | 5 +++++ .github/workflows/deploy_production_firebase.yml | 5 +++++ .github/workflows/deploy_staging_firebase.yml | 5 +++++ .github/workflows/test_upload_build_to_firebase.yml | 5 +++++ .../workflows/test_upload_build_to_test_flight.yml | 5 +++++ fastlane/Constants/Constant.swift | 1 + fastlane/Fastfile.swift | 5 +++++ fastlane/Helpers/Keychain.swift | 11 +++++++++++ 8 files changed, 42 insertions(+) diff --git a/.github/workflows/deploy_app_store.yml b/.github/workflows/deploy_app_store.yml index c065d75b..a054675e 100644 --- a/.github/workflows/deploy_app_store.yml +++ b/.github/workflows/deploy_app_store.yml @@ -97,3 +97,8 @@ jobs: ${{ env.DSYM_OUTPUT_PATH }} env: TAG_TYPE: App_Store + + - name: Remove keychain + if: ${{ always() }} + run: bundle exec fastlane removeKeychain + continue-on-error: true diff --git a/.github/workflows/deploy_production_firebase.yml b/.github/workflows/deploy_production_firebase.yml index 2b9209c9..ad71aed9 100644 --- a/.github/workflows/deploy_production_firebase.yml +++ b/.github/workflows/deploy_production_firebase.yml @@ -91,3 +91,8 @@ jobs: ${{ env.DSYM_OUTPUT_PATH }} env: TAG_TYPE: Production_Firebase + + - name: Remove keychain + if: ${{ always() }} + run: bundle exec fastlane removeKeychain + continue-on-error: true diff --git a/.github/workflows/deploy_staging_firebase.yml b/.github/workflows/deploy_staging_firebase.yml index d5ac0b71..fff0630a 100644 --- a/.github/workflows/deploy_staging_firebase.yml +++ b/.github/workflows/deploy_staging_firebase.yml @@ -97,3 +97,8 @@ jobs: ${{ env.DSYM_OUTPUT_PATH }} env: TAG_TYPE: Staging_Firebase + + - name: Remove keychain + if: ${{ always() }} + run: bundle exec fastlane removeKeychain + continue-on-error: true diff --git a/.github/workflows/test_upload_build_to_firebase.yml b/.github/workflows/test_upload_build_to_firebase.yml index 3ccdfb6c..5f8d2655 100644 --- a/.github/workflows/test_upload_build_to_firebase.yml +++ b/.github/workflows/test_upload_build_to_firebase.yml @@ -78,3 +78,8 @@ jobs: ${{ env.DSYM_OUTPUT_PATH }} env: TAG_TYPE: Staging_Firebase + + - name: Remove keychain + if: ${{ always() }} + run: bundle exec fastlane removeKeychain + continue-on-error: true diff --git a/.github/workflows/test_upload_build_to_test_flight.yml b/.github/workflows/test_upload_build_to_test_flight.yml index 387c835b..28baf490 100644 --- a/.github/workflows/test_upload_build_to_test_flight.yml +++ b/.github/workflows/test_upload_build_to_test_flight.yml @@ -70,3 +70,8 @@ jobs: ISSUER_ID: ${{ secrets.ISSUER_ID }} SKIP_FIREBASE_DSYM: "true" BUMP_APP_STORE_BUILD_NUMBER: "true" + + - name: Remove keychain + if: ${{ always() }} + run: bundle exec fastlane removeKeychain + continue-on-error: true diff --git a/fastlane/Constants/Constant.swift b/fastlane/Constants/Constant.swift index ae8ddf83..2b434f4f 100644 --- a/fastlane/Constants/Constant.swift +++ b/fastlane/Constants/Constant.swift @@ -37,6 +37,7 @@ enum Constant { static let projectPath: String = "./\(projectName).xcodeproj" static let testOutputDirectoryPath = "./fastlane/test_output" static let infoPlistPath = "\(projectName)/Configurations/Plists/Info.plist" + static let keychainPath = "~/Library/Keychains/\(keychainName)-db" // MARK: Platform diff --git a/fastlane/Fastfile.swift b/fastlane/Fastfile.swift index ccba6fe1..a5377234 100644 --- a/fastlane/Fastfile.swift +++ b/fastlane/Fastfile.swift @@ -51,6 +51,11 @@ class Fastfile: LaneFile { environment: .production ) } + + func removeKeychainLane() { + desc("Delete keychain") + Keychain.remove() + } // MARK: - Build diff --git a/fastlane/Helpers/Keychain.swift b/fastlane/Helpers/Keychain.swift index 4482c788..e06f24a3 100644 --- a/fastlane/Helpers/Keychain.swift +++ b/fastlane/Helpers/Keychain.swift @@ -6,6 +6,8 @@ // Copyright © 2022 Nimble. All rights reserved. // +import Foundation + enum Keychain { static func create() { @@ -17,4 +19,13 @@ enum Keychain { timeout: 3600 ) } + + static func remove() { + guard FileManager.default.fileExists(atPath: Constant.keychainPath) else { + return log(message: "Couldn't find the Keychain") + } + deleteKeychain( + name: .userDefined(Constant.keychainName) + ) + } }