Skip to content

Commit

Permalink
Merge pull request #497 from nimblehq/chore/491-migrate-set-up-fireba…
Browse files Browse the repository at this point in the history
…se-test-swift-command

[#491] Migrate `set_up_test_firebase.sh` to Swift command
  • Loading branch information
blyscuit authored Aug 9, 2023
2 parents 1385fce + 5020d93 commit da4526d
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test_upload_build_to_firebase.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
2 changes: 0 additions & 2 deletions Dangerfile
Original file line number Diff line number Diff line change
@@ -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

Expand Down
31 changes: 31 additions & 0 deletions Scripts/Swift/Extensions/FileManager+Utils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
2 changes: 1 addition & 1 deletion Scripts/Swift/SetUpCICDService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
}

Expand Down
16 changes: 16 additions & 0 deletions Scripts/Swift/SetUpTestFirebase.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
let teamIdPlaceholder = "<#teamId#>"
let stagingFirebaseAppIdPlaceholder = "<#stagingFirebaseAppId#>"
let firebaseTesterGroupsPlaceholder = "<#group1#>, <#group2#>"
let matchRepoPlaceholder = "[email protected]:{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)
3 changes: 1 addition & 2 deletions make.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
12 changes: 0 additions & 12 deletions set_up_test_firebase.sh

This file was deleted.

0 comments on commit da4526d

Please sign in to comment.