Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 38 additions & 5 deletions ZipBuilder/Sources/FirebaseReleaser/Tags.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ import FirebaseManifest
import Utils

enum Tags {
static func create(gitRoot: URL) {
static func createTags(gitRoot: URL, deleteExistingTags: Bool = false) {
let manifest = FirebaseManifest.shared
createTag(gitRoot: gitRoot, tag: "CocoaPods-\(manifest.version)")
createTag(gitRoot: gitRoot, tag: "CocoaPods-\(manifest.version)-beta")
createTag(gitRoot: gitRoot, tag: "CocoaPods-\(manifest.version)",
deleteExistingTags: deleteExistingTags)
createTag(gitRoot: gitRoot, tag: "CocoaPods-\(manifest.version)-beta",
deleteExistingTags: deleteExistingTags)

for pod in manifest.pods {
if pod.isFirebase {
Expand All @@ -36,12 +38,43 @@ enum Tags {
fatalError("Non-Firebase pod \(pod.name) is missing a version")
}
let tag = pod.name.replacingOccurrences(of: "Google", with: "") + "-" + version
createTag(gitRoot: gitRoot, tag: tag)
createTag(gitRoot: gitRoot, tag: tag, deleteExistingTags: deleteExistingTags)
}
}

private static func createTag(gitRoot: URL, tag: String) {
static func updateTags(gitRoot: URL) {
createTags(gitRoot: gitRoot, deleteExistingTags: true)
}

private static func createTag(gitRoot: URL, tag: String, deleteExistingTags: Bool) {
if deleteExistingTags {
verifyTagsAreSafeToDelete()
Shell.executeCommand("git tag --delete \(tag)", workingDir: gitRoot)
Shell.executeCommand("git push --delete origin \(tag)", workingDir: gitRoot)
}
Shell.executeCommand("git tag \(tag)", workingDir: gitRoot)
Shell.executeCommand("git push origin \(tag)", workingDir: gitRoot)
}

private static func verifyTagsAreSafeToDelete() {
var homeDirURL: URL
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we be extra safe and run a pod update here first to be sure that the local repo is up to date? I imagine it's a very very edge case but maybe something worth doing.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! See #6774

if #available(OSX 10.12, *) {
homeDirURL = FileManager.default.homeDirectoryForCurrentUser
} else {
fatalError("Run on at least macOS 10.12")
}
let manifest = FirebaseManifest.shared
let firebasePublicURL = homeDirURL.appendingPathComponents(
[".cocoapods", "repos", "cocoapods", "Specs", "0", "3", "5", "Firebase"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I curious where the number components come from?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's the CocoaPods hash of the word Firebase. It's how CocoaPods does sharding.

)

guard FileManager.default.fileExists(atPath: firebasePublicURL.path) else {
fatalError("You must have the CocoaPods Spec repo installed to retag versions.")
}

guard !FileManager.default.fileExists(atPath:
firebasePublicURL.appendingPathComponent(manifest.version).path) else {
fatalError("Do not remove tag of a published Firebase version.")
}
}
}
11 changes: 9 additions & 2 deletions ZipBuilder/Sources/FirebaseReleaser/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,14 @@ struct FirebaseReleaser: ParsableCommand {

/// Set this option to update podspecs only.
@Option(default: false,
help: "Initialize the release branch")
help: "Update the podspecs only")
var pushOnly: Bool

/// Set this option to update tags only.
@Option(default: false,
help: "Update the tags only")
var updateTagsOnly: Bool

mutating func validate() throws {
guard FileManager.default.fileExists(atPath: gitRoot.path) else {
throw ValidationError("git-root does not exist: \(gitRoot.path)")
Expand All @@ -59,10 +64,12 @@ struct FirebaseReleaser: ParsableCommand {
Shell.executeCommand("git push origin \(branch)", workingDir: gitRoot)
Shell.executeCommand("git branch --set-upstream-to=origin/\(branch) \(branch)",
workingDir: gitRoot)
Tags.create(gitRoot: gitRoot)
Tags.createTags(gitRoot: gitRoot)
Push.pushPodsToCPDC(gitRoot: gitRoot)
} else if pushOnly {
Push.pushPodsToCPDC(gitRoot: gitRoot)
} else if updateTagsOnly {
Tags.updateTags(gitRoot: gitRoot)
}
}

Expand Down