-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Move UpdateFirebasePod to Swift's ArgumentParser library. #4993
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
2d2a2be
Move UpdateFirebasePod to Swift's ArgumentParser library.
ryanwilson 77e9007
Removed unnecessary file.
ryanwilson 60d4c2c
Fixed formatting.
ryanwilson 04da350
Use existing argument name for currentRelease.
ryanwilson 5b8708c
Sorted package dependencies.
ryanwilson 82e6bec
Pin to exact version.
ryanwilson 8e83ecd
Rename UpdateFirebasePod to firebase-pod-updater
ryanwilson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,99 +16,120 @@ | |
|
|
||
| import Foundation | ||
|
|
||
| import ArgumentParser | ||
| import ManifestReader | ||
|
|
||
| // Get the launch arguments, parsed by user defaults. | ||
| let args = LaunchArgs.shared | ||
| struct FirebasePodUpdater: ParsableCommand { | ||
|
|
||
| // Keep timing for how long it takes to change the Firebase pod versions. | ||
| let buildStart = Date() | ||
| var cocoaPodsUpdateMessage: String = "" | ||
| /// The root of the Firebase git repo. | ||
| @Option(help: "The root of the firebase-ios-sdk checked out git repo.", | ||
| transform: URL.init(fileURLWithPath:)) | ||
| var gitRoot: URL | ||
|
|
||
| var paths = FirebasePod.FilesystemPaths(currentReleasePath: args.currentReleasePath, | ||
| gitRootPath: args.gitRootPath) | ||
| /// A file URL to a textproto with the contents of a `FirebasePod_Release` object. Used to verify | ||
| /// expected version numbers. | ||
| @Option(help: "The file path to a textproto file containing all the releasing Pods, of type `FirebasePod_Release`.", | ||
| transform: URL.init(fileURLWithPath:)) | ||
| var currentRelease: URL | ||
|
|
||
| /// Assembles the expected versions based on the release manifest passed in. | ||
| /// Returns an array with the pod name as the key and version as the value, | ||
| private func getExpectedVersions() -> [String: String] { | ||
| // Merge the versions from the current release and the known public versions. | ||
| var releasingVersions: [String: String] = [:] | ||
| mutating func validate() throws { | ||
| guard FileManager.default.fileExists(atPath: gitRoot.path) else { | ||
| throw ValidationError("git-root does not exist: \(gitRoot.path)") | ||
| } | ||
|
|
||
| // Override any of the expected versions with the current release manifest, if it exists. | ||
| let currentRelease = ManifestReader.loadCurrentRelease(fromTextproto: paths.currentReleasePath) | ||
| print("Overriding the following Pod versions, taken from the current release manifest:") | ||
| for pod in currentRelease.sdk { | ||
| releasingVersions[pod.sdkName] = pod.sdkVersion | ||
| print("\(pod.sdkName): \(pod.sdkVersion)") | ||
| guard FileManager.default.fileExists(atPath: currentRelease.path) else { | ||
| throw ValidationError("current-release does not exist: \(currentRelease.path). Do you need " + | ||
| "to run `prodaccess`?") | ||
| } | ||
| } | ||
|
|
||
| if !releasingVersions.isEmpty { | ||
| print("Updating Firebase Pod in git installation at \(paths.gitRootPath)) " + | ||
| "with the following versions: \(releasingVersions)") | ||
| func run() throws { | ||
| // Keep timing for how long it takes to change the Firebase pod versions. | ||
| let buildStart = Date() | ||
|
|
||
| let newVersions = getExpectedVersions() | ||
| updateFirebasePod(newVersions: newVersions) | ||
| print("Updating Firebase pod for version \(String(describing: newVersions["Firebase"]!))") | ||
|
|
||
| // Get the time since the tool start. | ||
| let secondsSinceStart = -Int(buildStart.timeIntervalSinceNow) | ||
| print(""" | ||
| Time profile: | ||
| It took \(secondsSinceStart) seconds (~\(secondsSinceStart / 60)m) to update the Firebase pod. | ||
| """) | ||
| } | ||
|
|
||
| return releasingVersions | ||
| } | ||
| /// Assembles the expected versions based on the release manifest passed in. | ||
| /// Returns an array with the pod name as the key and version as the value, | ||
| private func getExpectedVersions() -> [String: String] { | ||
| // Merge the versions from the current release and the known public versions. | ||
| var releasingVersions: [String: String] = [:] | ||
|
|
||
| private func updateFirebasePod(newVersions: [String: String]) { | ||
| let podspecFile = paths.gitRootPath + "/Firebase.podspec" | ||
| var contents = "" | ||
| do { | ||
| contents = try String(contentsOfFile: podspecFile, encoding: .utf8) | ||
| } catch { | ||
| fatalError("Could not read Firebase podspec. \(error)") | ||
| // Override any of the expected versions with the current release manifest, if it exists. | ||
| let loadedRelease = ManifestReader.loadCurrentRelease(fromTextproto: self.currentRelease) | ||
| print("Overriding the following Pod versions, taken from the current release manifest:") | ||
| for pod in loadedRelease.sdk { | ||
| releasingVersions[pod.sdkName] = pod.sdkVersion | ||
| print("\(pod.sdkName): \(pod.sdkVersion)") | ||
| } | ||
|
|
||
| if !releasingVersions.isEmpty { | ||
| print("Updating Firebase Pod in git installation at \(gitRoot.path)) " + | ||
| "with the following versions: \(releasingVersions)") | ||
| } | ||
|
|
||
| return releasingVersions | ||
| } | ||
| for (pod, version) in newVersions { | ||
| if pod == "Firebase" { | ||
| // Replace version in string like s.version = '6.9.0' | ||
| guard let range = contents.range(of: "s.version") else { | ||
| fatalError("Could not find version of Firebase pod in podspec at \(podspecFile)") | ||
| } | ||
| var versionStartIndex = contents.index(range.upperBound, offsetBy: 1) | ||
| while contents[versionStartIndex] != "'" { | ||
| versionStartIndex = contents.index(versionStartIndex, offsetBy: 1) | ||
| } | ||
| var versionEndIndex = contents.index(versionStartIndex, offsetBy: 1) | ||
| while contents[versionEndIndex] != "'" { | ||
| versionEndIndex = contents.index(versionEndIndex, offsetBy: 1) | ||
| } | ||
| contents.removeSubrange(versionStartIndex ... versionEndIndex) | ||
| contents.insert(contentsOf: "'" + version + "'", at: versionStartIndex) | ||
| } else { | ||
| // Replace version in string like ss.dependency 'FirebaseCore', '6.3.0' | ||
| guard let range = contents.range(of: pod) else { | ||
| // This pod is not a top-level Firebase pod dependency. | ||
| continue | ||
| } | ||
| var versionStartIndex = contents.index(range.upperBound, offsetBy: 2) | ||
| while !contents[versionStartIndex].isWholeNumber { | ||
| versionStartIndex = contents.index(versionStartIndex, offsetBy: 1) | ||
| } | ||
| var versionEndIndex = contents.index(versionStartIndex, offsetBy: 1) | ||
| while contents[versionEndIndex] != "'" { | ||
| versionEndIndex = contents.index(versionEndIndex, offsetBy: 1) | ||
|
|
||
| private func updateFirebasePod(newVersions: [String: String]) { | ||
| let podspecFile = gitRoot.appendingPathComponent("Firebase.podspec") | ||
| var contents = "" | ||
| do { | ||
| contents = try String(contentsOfFile: podspecFile.path, encoding: .utf8) | ||
| } catch { | ||
| fatalError("Could not read Firebase podspec. \(error)") | ||
| } | ||
| for (pod, version) in newVersions { | ||
| if pod == "Firebase" { | ||
| // Replace version in string like s.version = '6.9.0' | ||
| guard let range = contents.range(of: "s.version") else { | ||
| fatalError("Could not find version of Firebase pod in podspec at \(podspecFile)") | ||
| } | ||
| var versionStartIndex = contents.index(range.upperBound, offsetBy: 1) | ||
| while contents[versionStartIndex] != "'" { | ||
| versionStartIndex = contents.index(versionStartIndex, offsetBy: 1) | ||
| } | ||
| var versionEndIndex = contents.index(versionStartIndex, offsetBy: 1) | ||
| while contents[versionEndIndex] != "'" { | ||
| versionEndIndex = contents.index(versionEndIndex, offsetBy: 1) | ||
| } | ||
| contents.removeSubrange(versionStartIndex ... versionEndIndex) | ||
| contents.insert(contentsOf: "'" + version + "'", at: versionStartIndex) | ||
| } else { | ||
| // Replace version in string like ss.dependency 'FirebaseCore', '6.3.0' | ||
| guard let range = contents.range(of: pod) else { | ||
| // This pod is not a top-level Firebase pod dependency. | ||
| continue | ||
| } | ||
| var versionStartIndex = contents.index(range.upperBound, offsetBy: 2) | ||
| while !contents[versionStartIndex].isWholeNumber { | ||
| versionStartIndex = contents.index(versionStartIndex, offsetBy: 1) | ||
| } | ||
| var versionEndIndex = contents.index(versionStartIndex, offsetBy: 1) | ||
| while contents[versionEndIndex] != "'" { | ||
| versionEndIndex = contents.index(versionEndIndex, offsetBy: 1) | ||
| } | ||
| contents.removeSubrange(versionStartIndex ... versionEndIndex) | ||
| contents.insert(contentsOf: version + "'", at: versionStartIndex) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This just moved from the root of the file to inside the new type, along with not using the |
||
| } | ||
| contents.removeSubrange(versionStartIndex ... versionEndIndex) | ||
| contents.insert(contentsOf: version + "'", at: versionStartIndex) | ||
| } | ||
| } | ||
| do { | ||
| try contents.write(toFile: podspecFile, atomically: false, encoding: String.Encoding.utf8) | ||
| } catch { | ||
| fatalError("Failed to write \(podspecFile). \(error)") | ||
| do { | ||
| try contents.write(to: podspecFile, atomically: false, encoding: .utf8) | ||
| } catch { | ||
| fatalError("Failed to write \(podspecFile.path). \(error)") | ||
| } | ||
| } | ||
| } | ||
|
|
||
| do { | ||
| let newVersions = getExpectedVersions() | ||
| updateFirebasePod(newVersions: newVersions) | ||
| print("Updating Firebase pod for version \(String(describing: newVersions["Firebase"]!))") | ||
|
|
||
| // Get the time since the tool start. | ||
| let secondsSinceStart = -Int(buildStart.timeIntervalSinceNow) | ||
| print(""" | ||
| Time profile: | ||
| It took \(secondsSinceStart) seconds (~\(secondsSinceStart / 60)m) to update the Firebase pod. | ||
| \(cocoaPodsUpdateMessage) | ||
| """) | ||
| } | ||
| // Start the parsing and run the tool. | ||
| FirebasePodUpdater.main() | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This moved from the bottom of the file to the
run()block.