Push.swift 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. * Copyright 2020 Google LLC
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. import Foundation
  17. import FirebaseManifest
  18. import Utils
  19. private enum Destination {
  20. case cpdc, trunk
  21. }
  22. enum Push {
  23. static func pushPodsToCPDC(gitRoot: URL) {
  24. push(to: .cpdc, gitRoot: gitRoot)
  25. }
  26. static func publishPodsToTrunk(gitRoot: URL) {
  27. push(to: .trunk, gitRoot: gitRoot)
  28. }
  29. private static func push(to destination: Destination, gitRoot: URL) {
  30. let cpdcLocation = findCpdc(gitRoot: gitRoot)
  31. let manifest = FirebaseManifest.shared
  32. for pod in manifest.pods.filter({ $0.releasing }) {
  33. let warningsOK = pod.allowWarnings ? "--allow-warnings" : ""
  34. let command: String = {
  35. switch destination {
  36. case .cpdc:
  37. return "pod repo push --skip-tests --use-json \(warningsOK) \(cpdcLocation) " +
  38. pod.skipImportValidation() + " \(pod.podspecName()) " +
  39. "--sources=sso://cpdc-internal/firebase.git,https://cdn.cocoapods.org"
  40. case .trunk:
  41. return "pod trunk push --skip-tests --synchronous \(warningsOK) " +
  42. pod.skipImportValidation() + " ~/.cocoapods/repos/\(cpdcLocation)/Specs/\(pod.name)/" +
  43. "\(manifest.versionString(pod))/\(pod.name).podspec.json"
  44. }
  45. }()
  46. Shell.executeCommand(command, workingDir: gitRoot)
  47. }
  48. }
  49. private static func findCpdc(gitRoot: URL) -> String {
  50. let command = "pod repo list | grep -B2 sso://cpdc-internal/firebase | head -1"
  51. let result = Shell.executeCommandFromScript(command, workingDir: gitRoot)
  52. switch result {
  53. case let .error(code, output):
  54. fatalError("""
  55. `pod --version` failed with exit code \(code)
  56. Output from `pod repo list`:
  57. \(output)
  58. """)
  59. case let .success(output):
  60. print(output)
  61. return output.trimmingCharacters(in: .whitespacesAndNewlines)
  62. }
  63. }
  64. }