diff --git a/.github/workflows/test_upload_build_to_firebase.yml b/.github/workflows/test_upload_build_to_firebase.yml index 39194acd..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: sh set_up_test_firebase.sh + 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/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 diff --git a/Scripts/Swift/Extensions/FileManager+Utils.swift b/Scripts/Swift/Extensions/FileManager+Utils.swift index cda858de..c55c4e4a 100644 --- a/Scripts/Swift/Extensions/FileManager+Utils.swift +++ b/Scripts/Swift/Extensions/FileManager+Utils.swift @@ -42,4 +42,35 @@ extension FileManager { print("Error \(error)") } } + + 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) + } + } + } + + 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 { + let fileAttributes = try? fileURL.resourceValues(forKeys:[.isRegularFileKey]) + guard fileAttributes?.isRegularFile ?? false else { continue } + files.append(fileURL) + } + } + return files + } } 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.") } diff --git a/Scripts/Swift/SetUpTestFirebase.swift b/Scripts/Swift/SetUpTestFirebase.swift new file mode 100644 index 00000000..f7b36fbb --- /dev/null +++ b/Scripts/Swift/SetUpTestFirebase.swift @@ -0,0 +1,16 @@ +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"] ?? "" +let envTeamId = ProcessInfo.processInfo.environment["TEAM_ID"] ?? "" +let firebaseTesterGroup = "nimble" + +let fileManager = FileManager.default + +fileManager.replaceAllOccurrences(of: teamIdPlaceholder, to: envTeamId) +fileManager.replaceAllOccurrences(of: stagingFirebaseAppIdPlaceholder, to: envStagingFirebaseAppId) +fileManager.replaceAllOccurrences(of: firebaseTesterGroupsPlaceholder, to: firebaseTesterGroup) +fileManager.replaceAllOccurrences(of: matchRepoPlaceholder, to: envMatchRepo) diff --git a/make.sh b/make.sh index 3f8b6ef3..e9162149 100644 --- a/make.sh +++ b/make.sh @@ -215,13 +215,12 @@ 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' + rm -rf Scripts fi -rm -rf Scripts echo "✅ Completed" 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" {} +