From d7c50a834af5ccd3fbcfd178c433eaddc559cd8d Mon Sep 17 00:00:00 2001 From: Bliss Pisit Wetcha Date: Mon, 10 Jul 2023 16:56:52 +0700 Subject: [PATCH 1/9] [#491] Migrate SetUpTestFirebase --- Scripts/Swift/SetUpTestFirebase.swift | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 Scripts/Swift/SetUpTestFirebase.swift diff --git a/Scripts/Swift/SetUpTestFirebase.swift b/Scripts/Swift/SetUpTestFirebase.swift new file mode 100644 index 00000000..dc4bc803 --- /dev/null +++ b/Scripts/Swift/SetUpTestFirebase.swift @@ -0,0 +1,18 @@ +static let ConstantTeamId = "<#teamId#>" +static let ConstantStagingFirebaseAppId = "<#stagingFirebaseAppId#>" +static let ConstantFirebaseTesterGroups = "<#group1#>, <#group2#>" +static let ConstantMatchRepo = "git@github.com:{organization}\/{repo}.git" + +let envMatchRepo = ProcessInfo.processInfo.environment["MATCH_REPO"] +let envStagingFirebaseAppId = ProcessInfo.processInfo.environment["STAGING_FIREBASE_APP_ID"] +let envTeamId = ProcessInfo.processInfo.environment["TEAM_ID"] +let matchRepoEscaped = envMatchRepo.replacingOccurrences(of: "/", with: "\/") +let firebaseTesterGroup = "nimble" + +let fileManager = FileManager.default +let workingDirectory = fileManager.currentDirectoryPath + +try? safeShell("LC_ALL=C find \(workingDirectory) -type f -exec sed -i \"\" \"s/\(ConstantTeamId)/\(envTeamId)/g\" {} +") +try? safeShell("LC_ALL=C find \(workingDirectory) -type f -exec sed -i \"\" \"s/\(ConstantStagingFirebaseAppId)/\(envStagingFirebaseAppId)/g\" {} +") +try? safeShell("LC_ALL=C find \(workingDirectory) -type f -exec sed -i \"\" \"s/\(ConstantFirebaseTesterGroups)/\(firebaseTesterGroup)/g\" {} +") +try? safeShell("LC_ALL=C find \(workingDirectory) -type f -exec sed -i \"\" \"s/\(ConstantMatchRepo)/\(matchRepoEscaped)/g\" {} +") From 4a661bce9ea50cbccdf9fafe94009a6de750a927 Mon Sep 17 00:00:00 2001 From: Bliss Pisit Wetcha Date: Mon, 10 Jul 2023 17:03:19 +0700 Subject: [PATCH 2/9] [#491] Use Swift in CICD --- .../test_upload_build_to_firebase.yml | 2 +- Scripts/Swift/SetUpTestFirebase.swift | 26 +++++++++---------- make.sh | 1 - set_up_test_firebase.sh | 12 --------- 4 files changed, 14 insertions(+), 27 deletions(-) delete mode 100644 set_up_test_firebase.sh diff --git a/.github/workflows/test_upload_build_to_firebase.yml b/.github/workflows/test_upload_build_to_firebase.yml index 39194acd..3961e6fb 100644 --- a/.github/workflows/test_upload_build_to_firebase.yml +++ b/.github/workflows/test_upload_build_to_firebase.yml @@ -50,7 +50,7 @@ jobs: run: sh make.sh --bundle-id co.nimblehq.ios.templates --bundle-id-staging co.nimblehq.ios.templates.staging --project-name TemplateApp --interface UIKit - name: Start Setup Script for Template App Firebase Upload - run: sh set_up_test_firebase.sh + run: cat Scripts/Swift/SetUpTestFirebase.swift Scripts/Swift/Extensions/FileManager+Utils.swift Scripts/Swift/Helpers/SafeShell.swift | swift - env: MATCH_REPO: ${{ secrets.MATCH_REPO }} STAGING_FIREBASE_APP_ID: ${{ secrets.STAGING_FIREBASE_APP_ID }} diff --git a/Scripts/Swift/SetUpTestFirebase.swift b/Scripts/Swift/SetUpTestFirebase.swift index dc4bc803..59664037 100644 --- a/Scripts/Swift/SetUpTestFirebase.swift +++ b/Scripts/Swift/SetUpTestFirebase.swift @@ -1,18 +1,18 @@ -static let ConstantTeamId = "<#teamId#>" -static let ConstantStagingFirebaseAppId = "<#stagingFirebaseAppId#>" -static let ConstantFirebaseTesterGroups = "<#group1#>, <#group2#>" -static let ConstantMatchRepo = "git@github.com:{organization}\/{repo}.git" +let ConstantTeamId = "<#teamId#>" +let ConstantStagingFirebaseAppId = "<#stagingFirebaseAppId#>" +let ConstantFirebaseTesterGroups = "<#group1#>, <#group2#>" +let ConstantMatchRepo = "git@github.com:{organization}\\/{repo}.git" -let envMatchRepo = ProcessInfo.processInfo.environment["MATCH_REPO"] -let envStagingFirebaseAppId = ProcessInfo.processInfo.environment["STAGING_FIREBASE_APP_ID"] -let envTeamId = ProcessInfo.processInfo.environment["TEAM_ID"] -let matchRepoEscaped = envMatchRepo.replacingOccurrences(of: "/", with: "\/") +let envMatchRepo = ProcessInfo.processInfo.environment["MATCH_REPO"] ?? "" +let envStagingFirebaseAppId = ProcessInfo.processInfo.environment["STAGING_FIREBASE_APP_ID"] ?? "" +let envTeamId = ProcessInfo.processInfo.environment["TEAM_ID"] ?? "" +let matchRepoEscaped = envMatchRepo.replacingOccurrences(of: "/", with: "\\/") let firebaseTesterGroup = "nimble" let fileManager = FileManager.default -let workingDirectory = fileManager.currentDirectoryPath +let workingDirectory = fileManager.currentDirectoryPath.replacingOccurrences(of: "/", with: "\\/") -try? safeShell("LC_ALL=C find \(workingDirectory) -type f -exec sed -i \"\" \"s/\(ConstantTeamId)/\(envTeamId)/g\" {} +") -try? safeShell("LC_ALL=C find \(workingDirectory) -type f -exec sed -i \"\" \"s/\(ConstantStagingFirebaseAppId)/\(envStagingFirebaseAppId)/g\" {} +") -try? safeShell("LC_ALL=C find \(workingDirectory) -type f -exec sed -i \"\" \"s/\(ConstantFirebaseTesterGroups)/\(firebaseTesterGroup)/g\" {} +") -try? safeShell("LC_ALL=C find \(workingDirectory) -type f -exec sed -i \"\" \"s/\(ConstantMatchRepo)/\(matchRepoEscaped)/g\" {} +") +try safeShell("LC_ALL=C find \(workingDirectory) -type f -exec sed -i \"\" \"s/\(ConstantTeamId)/\(envTeamId)/g\" {} +") +try safeShell("LC_ALL=C find \(workingDirectory) -type f -exec sed -i \"\" \"s/\(ConstantStagingFirebaseAppId)/\(envStagingFirebaseAppId)/g\" {} +") +try safeShell("LC_ALL=C find \(workingDirectory) -type f -exec sed -i \"\" \"s/\(ConstantFirebaseTesterGroups)/\(firebaseTesterGroup)/g\" {} +") +try safeShell("LC_ALL=C find \(workingDirectory) -type f -exec sed -i \"\" \"s/\(ConstantMatchRepo)/\(matchRepoEscaped)/g\" {} +") diff --git a/make.sh b/make.sh index 3f8b6ef3..542b8740 100644 --- a/make.sh +++ b/make.sh @@ -215,7 +215,6 @@ git reset if [[ -z "${CI}" ]]; then rm -rf fastlane/Tests - rm -f set_up_test_firebase.sh rm -f set_up_test_testflight.sh cat Scripts/Swift/SetUpCICDService.swift Scripts/Swift/Extensions/FileManager+Utils.swift Scripts/Swift/Helpers/SafeShell.swift > t.swift && swift t.swift && rm -rf 't.swift' cat Scripts/Swift/SetUpDeliveryConstants.swift Scripts/Swift/Extensions/FileManager+Utils.swift Scripts/Swift/Helpers/SafeShell.swift > t.swift && swift t.swift && rm -rf 't.swift' diff --git a/set_up_test_firebase.sh b/set_up_test_firebase.sh deleted file mode 100644 index e551f565..00000000 --- a/set_up_test_firebase.sh +++ /dev/null @@ -1,12 +0,0 @@ -readonly CONSTANT_TEAM_ID="<#teamId#>" -readonly CONSTANT_STAGING_FIREBASE_APP_ID="<#stagingFirebaseAppId#>" -readonly CONSTANT_FIREBASE_TESTER_GROUPS="<#group1#>, <#group2#>" -readonly CONSTANT_MATCH_REPO="git@github.com:{organization}\/{repo}.git" - -readonly WORKING_DIR=$(cd -P -- "$(dirname -- "$0")" && pwd -P) -MATCH_REPO_ESCAPED=$(echo "${MATCH_REPO//\//\\\/}") - -LC_ALL=C find $WORKING_DIR -type f -exec sed -i "" "s/$CONSTANT_TEAM_ID/$TEAM_ID/g" {} + -LC_ALL=C find $WORKING_DIR -type f -exec sed -i "" "s/$CONSTANT_STAGING_FIREBASE_APP_ID/$STAGING_FIREBASE_APP_ID/g" {} + -LC_ALL=C find $WORKING_DIR -type f -exec sed -i "" "s/$CONSTANT_FIREBASE_TESTER_GROUPS/nimble/g" {} + -LC_ALL=C find $WORKING_DIR -type f -exec sed -i "" "s/$CONSTANT_MATCH_REPO/$MATCH_REPO_ESCAPED/g" {} + From d4ef290e8fc342c3e91f52decb5c7f27bdf728b3 Mon Sep 17 00:00:00 2001 From: Bliss Pisit Wetcha Date: Mon, 10 Jul 2023 17:30:59 +0700 Subject: [PATCH 3/9] [#491] Migrate SetUpTestFirebase --- .github/workflows/test_upload_build_to_firebase.yml | 2 +- Scripts/Swift/Extensions/FileManager+Bash.swift | 8 ++++++++ Scripts/Swift/SetUpTestFirebase.swift | 9 ++++----- make.sh | 2 +- 4 files changed, 14 insertions(+), 7 deletions(-) create mode 100644 Scripts/Swift/Extensions/FileManager+Bash.swift diff --git a/.github/workflows/test_upload_build_to_firebase.yml b/.github/workflows/test_upload_build_to_firebase.yml index 3961e6fb..6a7b65b5 100644 --- a/.github/workflows/test_upload_build_to_firebase.yml +++ b/.github/workflows/test_upload_build_to_firebase.yml @@ -50,7 +50,7 @@ jobs: run: sh make.sh --bundle-id co.nimblehq.ios.templates --bundle-id-staging co.nimblehq.ios.templates.staging --project-name TemplateApp --interface UIKit - name: Start Setup Script for Template App Firebase Upload - run: cat Scripts/Swift/SetUpTestFirebase.swift Scripts/Swift/Extensions/FileManager+Utils.swift Scripts/Swift/Helpers/SafeShell.swift | swift - + run: cat Scripts/Swift/SetUpTestFirebase.swift Scripts/Swift/Extensions/FileManager+Bash.swift Scripts/Swift/Helpers/SafeShell.swift | swift - env: MATCH_REPO: ${{ secrets.MATCH_REPO }} STAGING_FIREBASE_APP_ID: ${{ secrets.STAGING_FIREBASE_APP_ID }} diff --git a/Scripts/Swift/Extensions/FileManager+Bash.swift b/Scripts/Swift/Extensions/FileManager+Bash.swift new file mode 100644 index 00000000..5dfb43e0 --- /dev/null +++ b/Scripts/Swift/Extensions/FileManager+Bash.swift @@ -0,0 +1,8 @@ +import Foundation + +extension FileManager { + + func replaceAllOccurrences(of original: String, to replacing: String) throws { + try safeShell("LC_ALL=C find \(currentDirectoryPath) -type f -exec sed -i \"\" \"s/\(original)/\(replacing)/g\" {} +") + } +} diff --git a/Scripts/Swift/SetUpTestFirebase.swift b/Scripts/Swift/SetUpTestFirebase.swift index 59664037..a67d4102 100644 --- a/Scripts/Swift/SetUpTestFirebase.swift +++ b/Scripts/Swift/SetUpTestFirebase.swift @@ -10,9 +10,8 @@ let matchRepoEscaped = envMatchRepo.replacingOccurrences(of: "/", with: "\\/") let firebaseTesterGroup = "nimble" let fileManager = FileManager.default -let workingDirectory = fileManager.currentDirectoryPath.replacingOccurrences(of: "/", with: "\\/") -try safeShell("LC_ALL=C find \(workingDirectory) -type f -exec sed -i \"\" \"s/\(ConstantTeamId)/\(envTeamId)/g\" {} +") -try safeShell("LC_ALL=C find \(workingDirectory) -type f -exec sed -i \"\" \"s/\(ConstantStagingFirebaseAppId)/\(envStagingFirebaseAppId)/g\" {} +") -try safeShell("LC_ALL=C find \(workingDirectory) -type f -exec sed -i \"\" \"s/\(ConstantFirebaseTesterGroups)/\(firebaseTesterGroup)/g\" {} +") -try safeShell("LC_ALL=C find \(workingDirectory) -type f -exec sed -i \"\" \"s/\(ConstantMatchRepo)/\(matchRepoEscaped)/g\" {} +") +try fileManager.replaceAllOccurrences(of: ConstantTeamId, to: envTeamId) +try fileManager.replaceAllOccurrences(of: ConstantStagingFirebaseAppId, to: envStagingFirebaseAppId) +try fileManager.replaceAllOccurrences(of: ConstantFirebaseTesterGroups, to: firebaseTesterGroup) +try fileManager.replaceAllOccurrences(of: ConstantMatchRepo, to: matchRepoEscaped) diff --git a/make.sh b/make.sh index 542b8740..e9162149 100644 --- a/make.sh +++ b/make.sh @@ -218,9 +218,9 @@ if [[ -z "${CI}" ]]; then rm -f set_up_test_testflight.sh cat Scripts/Swift/SetUpCICDService.swift Scripts/Swift/Extensions/FileManager+Utils.swift Scripts/Swift/Helpers/SafeShell.swift > t.swift && swift t.swift && rm -rf 't.swift' cat Scripts/Swift/SetUpDeliveryConstants.swift Scripts/Swift/Extensions/FileManager+Utils.swift Scripts/Swift/Helpers/SafeShell.swift > t.swift && swift t.swift && rm -rf 't.swift' + rm -rf Scripts fi -rm -rf Scripts echo "✅ Completed" From ac197e0bc8d9b0341753f5ba45109f03a7422faf Mon Sep 17 00:00:00 2001 From: Bliss Pisit Wetcha Date: Tue, 11 Jul 2023 16:13:24 +0700 Subject: [PATCH 4/9] [#491] Add swift function of replace all in --- .../test_upload_build_to_firebase.yml | 2 +- .../Swift/Extensions/FileManager+Bash.swift | 8 ----- .../Swift/Extensions/FileManager+Utils.swift | 32 +++++++++++++++++++ 3 files changed, 33 insertions(+), 9 deletions(-) delete mode 100644 Scripts/Swift/Extensions/FileManager+Bash.swift diff --git a/.github/workflows/test_upload_build_to_firebase.yml b/.github/workflows/test_upload_build_to_firebase.yml index 6a7b65b5..3961e6fb 100644 --- a/.github/workflows/test_upload_build_to_firebase.yml +++ b/.github/workflows/test_upload_build_to_firebase.yml @@ -50,7 +50,7 @@ jobs: run: sh make.sh --bundle-id co.nimblehq.ios.templates --bundle-id-staging co.nimblehq.ios.templates.staging --project-name TemplateApp --interface UIKit - name: Start Setup Script for Template App Firebase Upload - run: cat Scripts/Swift/SetUpTestFirebase.swift Scripts/Swift/Extensions/FileManager+Bash.swift Scripts/Swift/Helpers/SafeShell.swift | swift - + run: cat Scripts/Swift/SetUpTestFirebase.swift Scripts/Swift/Extensions/FileManager+Utils.swift Scripts/Swift/Helpers/SafeShell.swift | swift - env: MATCH_REPO: ${{ secrets.MATCH_REPO }} STAGING_FIREBASE_APP_ID: ${{ secrets.STAGING_FIREBASE_APP_ID }} diff --git a/Scripts/Swift/Extensions/FileManager+Bash.swift b/Scripts/Swift/Extensions/FileManager+Bash.swift deleted file mode 100644 index 5dfb43e0..00000000 --- a/Scripts/Swift/Extensions/FileManager+Bash.swift +++ /dev/null @@ -1,8 +0,0 @@ -import Foundation - -extension FileManager { - - func replaceAllOccurrences(of original: String, to replacing: String) throws { - try safeShell("LC_ALL=C find \(currentDirectoryPath) -type f -exec sed -i \"\" \"s/\(original)/\(replacing)/g\" {} +") - } -} diff --git a/Scripts/Swift/Extensions/FileManager+Utils.swift b/Scripts/Swift/Extensions/FileManager+Utils.swift index cda858de..aba5c4ed 100644 --- a/Scripts/Swift/Extensions/FileManager+Utils.swift +++ b/Scripts/Swift/Extensions/FileManager+Utils.swift @@ -42,4 +42,36 @@ extension FileManager { print("Error \(error)") } } + + func replaceAllOccurrences(of original: String, to replacing: String) throws { + let files = try allFiles(in: currentDirectoryPath) + for file in files { + do { + let text = try String(contentsOf: file, encoding: .utf8) + print(file) + let modifiedText = text.replacingOccurrences(of: original, with: replacing) + try modifiedText.write(to: file, atomically: true, encoding: .utf8) + } + catch { + print(error) + } + } + } + + private func allFiles(in directory: String) throws -> [URL] { + let url = URL(fileURLWithPath: directory) + var files = [URL]() + if let enumerator = enumerator(at: url, includingPropertiesForKeys: [.isRegularFileKey], options: [.skipsHiddenFiles, .skipsPackageDescendants]) { + for case let fileURL as URL in enumerator { + do { + let fileAttributes = try fileURL.resourceValues(forKeys:[.isRegularFileKey]) + guard fileAttributes.isRegularFile ?? false, + fileURL.pathExtension.count > 0 + else { continue } + files.append(fileURL) + } + } + } + return files + } } From f776ce0eb07af0a7061b0d4d0df973b1f0d40a34 Mon Sep 17 00:00:00 2001 From: Bliss Pisit Wetcha Date: Tue, 11 Jul 2023 16:28:24 +0700 Subject: [PATCH 5/9] [#491] Add swift function of replace all in --- .github/workflows/test_upload_build_to_firebase.yml | 2 +- Scripts/Swift/Extensions/FileManager+Utils.swift | 5 +---- Scripts/Swift/SetUpTestFirebase.swift | 5 ++--- 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/.github/workflows/test_upload_build_to_firebase.yml b/.github/workflows/test_upload_build_to_firebase.yml index 3961e6fb..3ccdfb6c 100644 --- a/.github/workflows/test_upload_build_to_firebase.yml +++ b/.github/workflows/test_upload_build_to_firebase.yml @@ -50,7 +50,7 @@ jobs: run: sh make.sh --bundle-id co.nimblehq.ios.templates --bundle-id-staging co.nimblehq.ios.templates.staging --project-name TemplateApp --interface UIKit - name: Start Setup Script for Template App Firebase Upload - run: cat Scripts/Swift/SetUpTestFirebase.swift Scripts/Swift/Extensions/FileManager+Utils.swift Scripts/Swift/Helpers/SafeShell.swift | swift - + run: cat Scripts/Swift/SetUpTestFirebase.swift Scripts/Swift/Extensions/FileManager+Utils.swift | swift - env: MATCH_REPO: ${{ secrets.MATCH_REPO }} STAGING_FIREBASE_APP_ID: ${{ secrets.STAGING_FIREBASE_APP_ID }} diff --git a/Scripts/Swift/Extensions/FileManager+Utils.swift b/Scripts/Swift/Extensions/FileManager+Utils.swift index aba5c4ed..3b4befa9 100644 --- a/Scripts/Swift/Extensions/FileManager+Utils.swift +++ b/Scripts/Swift/Extensions/FileManager+Utils.swift @@ -48,7 +48,6 @@ extension FileManager { for file in files { do { let text = try String(contentsOf: file, encoding: .utf8) - print(file) let modifiedText = text.replacingOccurrences(of: original, with: replacing) try modifiedText.write(to: file, atomically: true, encoding: .utf8) } @@ -65,9 +64,7 @@ extension FileManager { for case let fileURL as URL in enumerator { do { let fileAttributes = try fileURL.resourceValues(forKeys:[.isRegularFileKey]) - guard fileAttributes.isRegularFile ?? false, - fileURL.pathExtension.count > 0 - else { continue } + guard fileAttributes.isRegularFile ?? false else { continue } files.append(fileURL) } } diff --git a/Scripts/Swift/SetUpTestFirebase.swift b/Scripts/Swift/SetUpTestFirebase.swift index a67d4102..0f7e5faa 100644 --- a/Scripts/Swift/SetUpTestFirebase.swift +++ b/Scripts/Swift/SetUpTestFirebase.swift @@ -1,12 +1,11 @@ let ConstantTeamId = "<#teamId#>" let ConstantStagingFirebaseAppId = "<#stagingFirebaseAppId#>" let ConstantFirebaseTesterGroups = "<#group1#>, <#group2#>" -let ConstantMatchRepo = "git@github.com:{organization}\\/{repo}.git" +let ConstantMatchRepo = "git@github.com:{organization}/{repo}.git" let envMatchRepo = ProcessInfo.processInfo.environment["MATCH_REPO"] ?? "" let envStagingFirebaseAppId = ProcessInfo.processInfo.environment["STAGING_FIREBASE_APP_ID"] ?? "" let envTeamId = ProcessInfo.processInfo.environment["TEAM_ID"] ?? "" -let matchRepoEscaped = envMatchRepo.replacingOccurrences(of: "/", with: "\\/") let firebaseTesterGroup = "nimble" let fileManager = FileManager.default @@ -14,4 +13,4 @@ let fileManager = FileManager.default try fileManager.replaceAllOccurrences(of: ConstantTeamId, to: envTeamId) try fileManager.replaceAllOccurrences(of: ConstantStagingFirebaseAppId, to: envStagingFirebaseAppId) try fileManager.replaceAllOccurrences(of: ConstantFirebaseTesterGroups, to: firebaseTesterGroup) -try fileManager.replaceAllOccurrences(of: ConstantMatchRepo, to: matchRepoEscaped) +try fileManager.replaceAllOccurrences(of: ConstantMatchRepo, to: envMatchRepo) From 614371b9f48e2b3550604746895731d9e2c68126 Mon Sep 17 00:00:00 2001 From: Bliss Pisit Wetcha Date: Tue, 11 Jul 2023 16:41:53 +0700 Subject: [PATCH 6/9] [#491] Add swift function of replace all in --- Scripts/Swift/Extensions/FileManager+Utils.swift | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Scripts/Swift/Extensions/FileManager+Utils.swift b/Scripts/Swift/Extensions/FileManager+Utils.swift index 3b4befa9..56238b2a 100644 --- a/Scripts/Swift/Extensions/FileManager+Utils.swift +++ b/Scripts/Swift/Extensions/FileManager+Utils.swift @@ -51,9 +51,7 @@ extension FileManager { let modifiedText = text.replacingOccurrences(of: original, with: replacing) try modifiedText.write(to: file, atomically: true, encoding: .utf8) } - catch { - print(error) - } + catch {} } } From 9957516eb2c1a60c4e57c38c414eda9418d0ed1d Mon Sep 17 00:00:00 2001 From: Bliss Pisit Wetcha Date: Fri, 4 Aug 2023 11:23:09 +0700 Subject: [PATCH 7/9] [#491] Fix try blocks --- .../Swift/Extensions/FileManager+Utils.swift | 22 +++++++++++-------- Scripts/Swift/SetUpTestFirebase.swift | 16 +++++++------- 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/Scripts/Swift/Extensions/FileManager+Utils.swift b/Scripts/Swift/Extensions/FileManager+Utils.swift index 56238b2a..c55c4e4a 100644 --- a/Scripts/Swift/Extensions/FileManager+Utils.swift +++ b/Scripts/Swift/Extensions/FileManager+Utils.swift @@ -43,28 +43,32 @@ extension FileManager { } } - func replaceAllOccurrences(of original: String, to replacing: String) throws { - let files = try allFiles(in: currentDirectoryPath) + func replaceAllOccurrences(of original: String, to replacing: String) { + let files = try? allFiles(in: currentDirectoryPath) + guard let files else { return print("Cannot find any files in current directory") } for file in files { do { let text = try String(contentsOf: file, encoding: .utf8) let modifiedText = text.replacingOccurrences(of: original, with: replacing) try modifiedText.write(to: file, atomically: true, encoding: .utf8) + } catch { + print(error.localizedDescription) } - catch {} } } private func allFiles(in directory: String) throws -> [URL] { let url = URL(fileURLWithPath: directory) var files = [URL]() - if let enumerator = enumerator(at: url, includingPropertiesForKeys: [.isRegularFileKey], options: [.skipsHiddenFiles, .skipsPackageDescendants]) { + if let enumerator = enumerator( + at: url, + includingPropertiesForKeys: [.isRegularFileKey], + options: [.skipsHiddenFiles, .skipsPackageDescendants] + ) { for case let fileURL as URL in enumerator { - do { - let fileAttributes = try fileURL.resourceValues(forKeys:[.isRegularFileKey]) - guard fileAttributes.isRegularFile ?? false else { continue } - files.append(fileURL) - } + let fileAttributes = try? fileURL.resourceValues(forKeys:[.isRegularFileKey]) + guard fileAttributes?.isRegularFile ?? false else { continue } + files.append(fileURL) } } return files diff --git a/Scripts/Swift/SetUpTestFirebase.swift b/Scripts/Swift/SetUpTestFirebase.swift index 0f7e5faa..f7b36fbb 100644 --- a/Scripts/Swift/SetUpTestFirebase.swift +++ b/Scripts/Swift/SetUpTestFirebase.swift @@ -1,7 +1,7 @@ -let ConstantTeamId = "<#teamId#>" -let ConstantStagingFirebaseAppId = "<#stagingFirebaseAppId#>" -let ConstantFirebaseTesterGroups = "<#group1#>, <#group2#>" -let ConstantMatchRepo = "git@github.com:{organization}/{repo}.git" +let teamIdPlaceholder = "<#teamId#>" +let stagingFirebaseAppIdPlaceholder = "<#stagingFirebaseAppId#>" +let firebaseTesterGroupsPlaceholder = "<#group1#>, <#group2#>" +let matchRepoPlaceholder = "git@github.com:{organization}/{repo}.git" let envMatchRepo = ProcessInfo.processInfo.environment["MATCH_REPO"] ?? "" let envStagingFirebaseAppId = ProcessInfo.processInfo.environment["STAGING_FIREBASE_APP_ID"] ?? "" @@ -10,7 +10,7 @@ let firebaseTesterGroup = "nimble" let fileManager = FileManager.default -try fileManager.replaceAllOccurrences(of: ConstantTeamId, to: envTeamId) -try fileManager.replaceAllOccurrences(of: ConstantStagingFirebaseAppId, to: envStagingFirebaseAppId) -try fileManager.replaceAllOccurrences(of: ConstantFirebaseTesterGroups, to: firebaseTesterGroup) -try fileManager.replaceAllOccurrences(of: ConstantMatchRepo, to: envMatchRepo) +fileManager.replaceAllOccurrences(of: teamIdPlaceholder, to: envTeamId) +fileManager.replaceAllOccurrences(of: stagingFirebaseAppIdPlaceholder, to: envStagingFirebaseAppId) +fileManager.replaceAllOccurrences(of: firebaseTesterGroupsPlaceholder, to: firebaseTesterGroup) +fileManager.replaceAllOccurrences(of: matchRepoPlaceholder, to: envMatchRepo) From 27a283cce28f3f3e41561c7982c03297325f9ed1 Mon Sep 17 00:00:00 2001 From: Bliss Pisit Wetcha Date: Fri, 4 Aug 2023 11:28:45 +0700 Subject: [PATCH 8/9] [#491] Fix local build --- Scripts/Swift/SetUpCICDService.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Scripts/Swift/SetUpCICDService.swift b/Scripts/Swift/SetUpCICDService.swift index 35a22abb..bc8ab07b 100644 --- a/Scripts/Swift/SetUpCICDService.swift +++ b/Scripts/Swift/SetUpCICDService.swift @@ -43,7 +43,7 @@ case .codemagic: print("Setting template for CodeMagic") fileManager.removeItems(in: "bitrise.yml") fileManager.removeItems(in: ".github/workflows") -case .later: +case .later, .none: print("You can manually setup the template later.") } From 5020d934788bffd698a9b742164049a0d4ded6d9 Mon Sep 17 00:00:00 2001 From: Bliss Pisit Wetcha Date: Wed, 9 Aug 2023 10:06:49 +0700 Subject: [PATCH 9/9] Fix Danger import old files --- Dangerfile | 2 -- 1 file changed, 2 deletions(-) diff --git a/Dangerfile b/Dangerfile index 84cb7b02..c19fdcd9 100644 --- a/Dangerfile +++ b/Dangerfile @@ -1,7 +1,5 @@ # frozen_string_literal: true -require './fastlane/Constants/Constants' - # Warn when there is a big PR warn("This pull request is quite big (#{git.lines_of_code} lines changed), please consider splitting it into multiple pull requests.") if git.lines_of_code > 500