@@ -75,38 +75,19 @@ struct InitializeRelease {
75
75
let pod = firebasePod. name
76
76
let version = firebasePod. isBeta ? firebaseVersion + " -beta " : firebaseVersion
77
77
if pod == " Firebase " {
78
- // TODO: This then block is redundant with the updatePodspecs function above and is left
79
- // until we decide to go with Swift or sed.
80
- // Replace version in string like s.version = '6.9.0'
78
+ // TODO: This block is redundant with `updatePodspecs`. Decide to go with Swift or sed.
81
79
guard let range = contents. range ( of: " s.version " ) else {
82
80
fatalError ( " Could not find version of Firebase pod in podspec at \( podspecFile) " )
83
81
}
84
- var versionStartIndex = contents. index ( range. upperBound, offsetBy: 1 )
85
- while contents [ versionStartIndex] != " ' " {
86
- versionStartIndex = contents. index ( versionStartIndex, offsetBy: 1 )
87
- }
88
- var versionEndIndex = contents. index ( versionStartIndex, offsetBy: 1 )
89
- while contents [ versionEndIndex] != " ' " {
90
- versionEndIndex = contents. index ( versionEndIndex, offsetBy: 1 )
91
- }
92
- contents. removeSubrange ( versionStartIndex ... versionEndIndex)
93
- contents. insert ( contentsOf: " ' " + version + " ' " , at: versionStartIndex)
82
+ // Replace version in string like s.version = '6.9.0'
83
+ updateVersion ( & contents, in: range, to: version)
84
+
94
85
} else {
95
- // Replace version in string like ss.dependency 'FirebaseCore', '6.3.0'
96
- guard let range = contents. range ( of: pod) else {
97
- // This pod is not a top-level Firebase pod dependency.
98
- continue
99
- }
100
- var versionStartIndex = contents. index ( range. upperBound, offsetBy: 2 )
101
- while !contents[ versionStartIndex] . isWholeNumber {
102
- versionStartIndex = contents. index ( versionStartIndex, offsetBy: 1 )
86
+ // Iterate through all the ranges of `pod`'s occurrences.
87
+ for range in contents. ranges ( of: pod) {
88
+ // Replace version in string like ss.dependency 'FirebaseCore', '6.3.0'.
89
+ updateVersion ( & contents, in: range, to: version)
103
90
}
104
- var versionEndIndex = contents. index ( versionStartIndex, offsetBy: 1 )
105
- while contents [ versionEndIndex] != " ' " {
106
- versionEndIndex = contents. index ( versionEndIndex, offsetBy: 1 )
107
- }
108
- contents. removeSubrange ( versionStartIndex ... versionEndIndex)
109
- contents. insert ( contentsOf: version + " ' " , at: versionStartIndex)
110
91
}
111
92
}
112
93
do {
@@ -116,6 +97,24 @@ struct InitializeRelease {
116
97
}
117
98
}
118
99
100
+ /// Update the existing version to the given version by writing to a given string using the provided range.
101
+ /// - Parameters:
102
+ /// - contents: A reference to a String containing a version that will be updated.
103
+ /// - range: The range containing a version substring that will be updated.
104
+ /// - version: The version string to update to.
105
+ private static func updateVersion( _ contents: inout String , in range: Range < String . Index > ,
106
+ to version: String ) {
107
+ var versionStartIndex = contents. index ( after: range. upperBound)
108
+ while !contents[ versionStartIndex] . isWholeNumber {
109
+ versionStartIndex = contents. index ( after: versionStartIndex)
110
+ }
111
+ var versionEndIndex = contents. index ( after: versionStartIndex)
112
+ while contents [ versionEndIndex] != " ' " {
113
+ versionEndIndex = contents. index ( after: versionEndIndex)
114
+ }
115
+ contents. replaceSubrange ( versionStartIndex ..< versionEndIndex, with: version)
116
+ }
117
+
119
118
private static func updatePodfiles( path: URL , version: String ) {
120
119
// Update the Podfiles across the repo.
121
120
let firestorePodfile = path. appendingPathComponent ( " Firestore " )
0 commit comments