From c530bd4e059d8e040102dbe9201cdc72dcef7ee7 Mon Sep 17 00:00:00 2001 From: nkhanh44 Date: Fri, 29 Dec 2023 17:36:11 +0700 Subject: [PATCH 1/6] [#552] Fix the issue --- .../iOSTemplateMaker/SetUpCICDService.swift | 50 ++++++++++++------- 1 file changed, 31 insertions(+), 19 deletions(-) diff --git a/Scripts/Swift/iOSTemplateMaker/Sources/iOSTemplateMaker/SetUpCICDService.swift b/Scripts/Swift/iOSTemplateMaker/Sources/iOSTemplateMaker/SetUpCICDService.swift index 972e9250..774b9f09 100644 --- a/Scripts/Swift/iOSTemplateMaker/Sources/iOSTemplateMaker/SetUpCICDService.swift +++ b/Scripts/Swift/iOSTemplateMaker/Sources/iOSTemplateMaker/SetUpCICDService.swift @@ -7,34 +7,44 @@ struct SetUpCICDService { case github, bitrise, codemagic, later init?(_ name: String) { - switch name.lowercased() { - case "g", "github": - self = .github - case "b", "bitrise": - self = .bitrise - case "c", "codemagic": - self = .codemagic - case "l", "later": - self = .later - default: + let name = name.lowercased() + let mappings: [String: Self] = [ + "g": .github, + "github": .github, + "b": .bitrise, + "bitrise": .bitrise, + "c": .codemagic, + "codemagic": .codemagic, + "l": .later, + "later": .later + ] + + if let matchedCase = mappings[name] { + self = matchedCase + } else { return nil } } } - + enum GithubRunnerType { case macOSLatest, selfHosted, later init?(_ name: String) { - switch name.lowercased() { - case "m", "macOS": - self = .macOSLatest - case "s", "self-hosted": - self = .selfHosted - case "l", "later": - self = .later - default: + let mappings: [String: Self] = [ + "m": .macOSLatest, + "macos": .macOSLatest, + "s": .selfHosted, + "self-hosted": .selfHosted, + "l": .later, + "later": .later + ] + + let name = name.lowercased() + if let matchedCase = mappings[name] { + self = matchedCase + } else { return nil } } @@ -63,10 +73,12 @@ struct SetUpCICDService { fileManager.createDirectory(path: ".github/workflows") switch runnerType { case .macOSLatest: + print("Configured to run on the latest macOS.") fileManager.moveFiles(in: ".github/project_workflows", to: ".github/workflows") fileManager.removeItems(in: ".github/project_workflows") fileManager.removeItems(in: ".github/self_hosted_project_workflows") case .selfHosted: + print("Configured to run on self-hosted.") fileManager.moveFiles(in: ".github/self_hosted_project_workflows", to: ".github/workflows") fileManager.removeItems(in: ".github/project_workflows") fileManager.removeItems(in: ".github/self_hosted_project_workflows") From a18df67fbd89b8a576b0d38fc84c77756ba827d8 Mon Sep 17 00:00:00 2001 From: MarkG Date: Wed, 13 Mar 2024 13:54:03 +0700 Subject: [PATCH 2/6] [#546] Support adding new devices directly from Github Action --- .../project_workflows/add_device_profile.yml | 67 +++++++++++++++++++ fastlane/Constants/Constant.swift | 20 ++++-- fastlane/Constants/Secret.swift | 4 ++ fastlane/Fastfile.swift | 18 +++++ .../xcschemes/FastlaneRunner.xcscheme | 2 +- 5 files changed, 104 insertions(+), 7 deletions(-) create mode 100644 .github/project_workflows/add_device_profile.yml diff --git a/.github/project_workflows/add_device_profile.yml b/.github/project_workflows/add_device_profile.yml new file mode 100644 index 00000000..6bbce033 --- /dev/null +++ b/.github/project_workflows/add_device_profile.yml @@ -0,0 +1,67 @@ +name: Test Add device and regenerate profiles with fastlane match + +# SECRETS needed: +### SSH_PRIVATE_KEY for the match Repo +### MATCH_PASSWORD +### APPSTORE_CONNECT_API_KEY +### API_KEY_ID +### ISSUER_ID + +on: + pull_request: + workflow_dispatch: + inputs: + devices: + description: 'JSON of devices. `{"Luka iPhone 6": "1234567890123456789012345678901234567890","Felix iPad Air 2": "abcdefghijklmnopqrstvuwxyzabcdefghijklmn"}`' + required: true + type: string + platform: + description: 'The platform' + required: true + default: 'ios' + type: choice + options: + - ios + - mac + +jobs: + create_files: + name: Create certificates and profiles + runs-on: macOS-latest + steps: + - name: Checkout the repository + uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: Install SSH key + uses: webfactory/ssh-agent@v0.5.4 + with: + ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }} + + - name: Cache Pods + uses: actions/cache@v3 + id: cocoapodCache + with: + path: Pods + key: ${{ runner.os }}-pods-${{ hashFiles('**/Podfile.lock') }} + restore-keys: | + ${{ runner.os }}-pods- + + - name: Bundle install + run: bundle install + + - name: Add device and regenerate profiles with match + run: bundle exec fastlane addDevicesGenerateProfiles + env: + MATCH_PASSWORD: ${{ secrets.MATCH_PASS }} + DEVICES: ${{ inputs.devices }} + APPSTORE_CONNECT_API_KEY: ${{ secrets.APPSTORE_CONNECT_API_KEY }} + API_KEY_ID: ${{ secrets.API_KEY_ID }} + ISSUER_ID: ${{ secrets.ISSUER_ID }} + PLATFORM: ${{ inputs.platform }} + + - name: Clean up keychain + if: ${{ always() }} + run: bundle exec fastlane remove_keychain + continue-on-error: true diff --git a/fastlane/Constants/Constant.swift b/fastlane/Constants/Constant.swift index 110dde40..83c64f58 100644 --- a/fastlane/Constants/Constant.swift +++ b/fastlane/Constants/Constant.swift @@ -28,12 +28,20 @@ enum Constant { static let appleProductionTeamId = "<#teamId#>" static let keychainName = "{PROJECT_NAME}_keychain" static let matchURL = "git@github.com:{organization}/{repo}.git" - static let apiKey: [String: Any] = [ - "key_id" : Secret.appStoreKeyIdKey, - "issuer_id": Secret.appStoreIssuerIdKey, - "key": Secret.appstoreConnectAPIKey, - "in_house": false - ] + static let apiKey: [String: Any] = { + var key = Secret.appstoreConnectAPIKey + if let data = Data(base64Encoded: Secret.appstoreConnectAPIKey), + let decodedKey = String(data: data, encoding: .utf8) { + key = decodedKey + } + + return [ + "key_id" : Secret.appStoreKeyIdKey, + "issuer_id": Secret.appStoreIssuerIdKey, + "key": key, + "in_house": false + ] + }() // MARK: - Path diff --git a/fastlane/Constants/Secret.swift b/fastlane/Constants/Secret.swift index 12f37911..6bc1ed25 100644 --- a/fastlane/Constants/Secret.swift +++ b/fastlane/Constants/Secret.swift @@ -18,4 +18,8 @@ enum Secret { static let appStoreIssuerIdKey = EnvironmentParser.string(key: "ISSUER_ID") static let bumpAppStoreBuildNumber = EnvironmentParser.bool(key: "BUMP_APP_STORE_BUILD_NUMBER") + + static let devices = EnvironmentParser.string(key: "DEVICES") + + static let platform = EnvironmentParser.string(key: "PLATFORM") } diff --git a/fastlane/Fastfile.swift b/fastlane/Fastfile.swift index 5052b7ad..d8e1f09d 100644 --- a/fastlane/Fastfile.swift +++ b/fastlane/Fastfile.swift @@ -176,6 +176,24 @@ class Fastfile: LaneFile { Match.syncCodeSigning(type: .adHoc, environment: .staging, isForce: true) } + func addDevicesGenerateProfilesLane() { + desc("Add device and regenerate profiles with match") + + guard let data = Secret.devices.data(using: .utf8), + let devices = try? JSONSerialization.jsonObject(with: data, options: []) as? [String: Any] else { + return + } + registerDevices( + devices: .userDefined(devices), + apiKey: .userDefined(Constant.apiKey), + teamId: .userDefined(Constant.appleStagingTeamId), + platform: Secret.platform + ) + + Match.syncCodeSigning(type: .development, environment: .staging, isForce: true) + Match.syncCodeSigning(type: .adHoc, environment: .staging, isForce: true) + } + // MARK: - Utilities func cleanUpOutputLane() { diff --git a/fastlane/swift/FastlaneSwiftRunner/FastlaneSwiftRunner.xcodeproj/xcshareddata/xcschemes/FastlaneRunner.xcscheme b/fastlane/swift/FastlaneSwiftRunner/FastlaneSwiftRunner.xcodeproj/xcshareddata/xcschemes/FastlaneRunner.xcscheme index 94572138..5c4ae769 100644 --- a/fastlane/swift/FastlaneSwiftRunner/FastlaneSwiftRunner.xcodeproj/xcshareddata/xcschemes/FastlaneRunner.xcscheme +++ b/fastlane/swift/FastlaneSwiftRunner/FastlaneSwiftRunner.xcodeproj/xcshareddata/xcschemes/FastlaneRunner.xcscheme @@ -61,7 +61,7 @@ Date: Tue, 9 Jul 2024 14:36:07 +0700 Subject: [PATCH 3/6] [#546] Remove cache pod step --- .github/project_workflows/add_device_profile.yml | 9 --------- 1 file changed, 9 deletions(-) diff --git a/.github/project_workflows/add_device_profile.yml b/.github/project_workflows/add_device_profile.yml index 6bbce033..fb7594bd 100644 --- a/.github/project_workflows/add_device_profile.yml +++ b/.github/project_workflows/add_device_profile.yml @@ -39,15 +39,6 @@ jobs: with: ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }} - - name: Cache Pods - uses: actions/cache@v3 - id: cocoapodCache - with: - path: Pods - key: ${{ runner.os }}-pods-${{ hashFiles('**/Podfile.lock') }} - restore-keys: | - ${{ runner.os }}-pods- - - name: Bundle install run: bundle install From 7c8758fb71218d0879d83d55e1248791853e41de Mon Sep 17 00:00:00 2001 From: MarkG Date: Tue, 9 Jul 2024 14:52:02 +0700 Subject: [PATCH 4/6] [#546] Revert FastlaneRunner changes --- .../xcshareddata/xcschemes/FastlaneRunner.xcscheme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fastlane/swift/FastlaneSwiftRunner/FastlaneSwiftRunner.xcodeproj/xcshareddata/xcschemes/FastlaneRunner.xcscheme b/fastlane/swift/FastlaneSwiftRunner/FastlaneSwiftRunner.xcodeproj/xcshareddata/xcschemes/FastlaneRunner.xcscheme index 5c4ae769..94572138 100644 --- a/fastlane/swift/FastlaneSwiftRunner/FastlaneSwiftRunner.xcodeproj/xcshareddata/xcschemes/FastlaneRunner.xcscheme +++ b/fastlane/swift/FastlaneSwiftRunner/FastlaneSwiftRunner.xcodeproj/xcshareddata/xcschemes/FastlaneRunner.xcscheme @@ -61,7 +61,7 @@ Date: Thu, 18 Jul 2024 14:04:17 +0700 Subject: [PATCH 5/6] [#546] Fix CI/CD failure --- .github/workflows/test_swiftui_install_script.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test_swiftui_install_script.yml b/.github/workflows/test_swiftui_install_script.yml index bded91e1..f9566740 100644 --- a/.github/workflows/test_swiftui_install_script.yml +++ b/.github/workflows/test_swiftui_install_script.yml @@ -11,7 +11,7 @@ concurrency: jobs: Test: name: Test - runs-on: macOS-12 + runs-on: macOS-latest steps: - uses: actions/checkout@v3 From 711068fa61ac3dd2b8b68ee92fba6d2089e85013 Mon Sep 17 00:00:00 2001 From: MarkG Date: Thu, 25 Jul 2024 14:34:03 +0700 Subject: [PATCH 6/6] [#546] Shortent text --- .github/project_workflows/add_device_profile.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/project_workflows/add_device_profile.yml b/.github/project_workflows/add_device_profile.yml index fb7594bd..e3bfa5d4 100644 --- a/.github/project_workflows/add_device_profile.yml +++ b/.github/project_workflows/add_device_profile.yml @@ -12,7 +12,7 @@ on: workflow_dispatch: inputs: devices: - description: 'JSON of devices. `{"Luka iPhone 6": "1234567890123456789012345678901234567890","Felix iPad Air 2": "abcdefghijklmnopqrstvuwxyzabcdefghijklmn"}`' + description: 'JSON of devices. `{"Luka iPhone 6":"1234567890123456789012345678901234567890","Felix iPad Air 2":"abcdefghijklmnopqrstvuwxyzabcdefghijklmn"}`' required: true type: string platform: