Skip to content

Commit 126635d

Browse files
authored
Add update-tags release process (#6739)
1 parent 272ff4d commit 126635d

File tree

2 files changed

+47
-7
lines changed

2 files changed

+47
-7
lines changed

ZipBuilder/Sources/FirebaseReleaser/Tags.swift

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,12 @@ import FirebaseManifest
2020
import Utils
2121

2222
enum Tags {
23-
static func create(gitRoot: URL) {
23+
static func createTags(gitRoot: URL, deleteExistingTags: Bool = false) {
2424
let manifest = FirebaseManifest.shared
25-
createTag(gitRoot: gitRoot, tag: "CocoaPods-\(manifest.version)")
26-
createTag(gitRoot: gitRoot, tag: "CocoaPods-\(manifest.version)-beta")
25+
createTag(gitRoot: gitRoot, tag: "CocoaPods-\(manifest.version)",
26+
deleteExistingTags: deleteExistingTags)
27+
createTag(gitRoot: gitRoot, tag: "CocoaPods-\(manifest.version)-beta",
28+
deleteExistingTags: deleteExistingTags)
2729

2830
for pod in manifest.pods {
2931
if pod.isFirebase {
@@ -36,12 +38,43 @@ enum Tags {
3638
fatalError("Non-Firebase pod \(pod.name) is missing a version")
3739
}
3840
let tag = pod.name.replacingOccurrences(of: "Google", with: "") + "-" + version
39-
createTag(gitRoot: gitRoot, tag: tag)
41+
createTag(gitRoot: gitRoot, tag: tag, deleteExistingTags: deleteExistingTags)
4042
}
4143
}
4244

43-
private static func createTag(gitRoot: URL, tag: String) {
45+
static func updateTags(gitRoot: URL) {
46+
createTags(gitRoot: gitRoot, deleteExistingTags: true)
47+
}
48+
49+
private static func createTag(gitRoot: URL, tag: String, deleteExistingTags: Bool) {
50+
if deleteExistingTags {
51+
verifyTagsAreSafeToDelete()
52+
Shell.executeCommand("git tag --delete \(tag)", workingDir: gitRoot)
53+
Shell.executeCommand("git push --delete origin \(tag)", workingDir: gitRoot)
54+
}
4455
Shell.executeCommand("git tag \(tag)", workingDir: gitRoot)
4556
Shell.executeCommand("git push origin \(tag)", workingDir: gitRoot)
4657
}
58+
59+
private static func verifyTagsAreSafeToDelete() {
60+
var homeDirURL: URL
61+
if #available(OSX 10.12, *) {
62+
homeDirURL = FileManager.default.homeDirectoryForCurrentUser
63+
} else {
64+
fatalError("Run on at least macOS 10.12")
65+
}
66+
let manifest = FirebaseManifest.shared
67+
let firebasePublicURL = homeDirURL.appendingPathComponents(
68+
[".cocoapods", "repos", "cocoapods", "Specs", "0", "3", "5", "Firebase"]
69+
)
70+
71+
guard FileManager.default.fileExists(atPath: firebasePublicURL.path) else {
72+
fatalError("You must have the CocoaPods Spec repo installed to retag versions.")
73+
}
74+
75+
guard !FileManager.default.fileExists(atPath:
76+
firebasePublicURL.appendingPathComponent(manifest.version).path) else {
77+
fatalError("Do not remove tag of a published Firebase version.")
78+
}
79+
}
4780
}

ZipBuilder/Sources/FirebaseReleaser/main.swift

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,14 @@ struct FirebaseReleaser: ParsableCommand {
3838

3939
/// Set this option to update podspecs only.
4040
@Option(default: false,
41-
help: "Initialize the release branch")
41+
help: "Update the podspecs only")
4242
var pushOnly: Bool
4343

44+
/// Set this option to update tags only.
45+
@Option(default: false,
46+
help: "Update the tags only")
47+
var updateTagsOnly: Bool
48+
4449
mutating func validate() throws {
4550
guard FileManager.default.fileExists(atPath: gitRoot.path) else {
4651
throw ValidationError("git-root does not exist: \(gitRoot.path)")
@@ -59,10 +64,12 @@ struct FirebaseReleaser: ParsableCommand {
5964
Shell.executeCommand("git push origin \(branch)", workingDir: gitRoot)
6065
Shell.executeCommand("git branch --set-upstream-to=origin/\(branch) \(branch)",
6166
workingDir: gitRoot)
62-
Tags.create(gitRoot: gitRoot)
67+
Tags.createTags(gitRoot: gitRoot)
6368
Push.pushPodsToCPDC(gitRoot: gitRoot)
6469
} else if pushOnly {
6570
Push.pushPodsToCPDC(gitRoot: gitRoot)
71+
} else if updateTagsOnly {
72+
Tags.updateTags(gitRoot: gitRoot)
6673
}
6774
}
6875

0 commit comments

Comments
 (0)