if_changed.sh 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. # Copyright 2018 Google
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. # Within Travis, runs the given command if the current project has changes
  15. # worth building.
  16. #
  17. # Examines the following Travis-supplied environment variables:
  18. # - TRAVIS_PULL_REQUEST - the PR number or false for full build
  19. # - TRAVIS_COMMIT_RANGE - the range of commits under test; empty on a new
  20. # branch
  21. #
  22. # Also examines the following configured environment variables that should be
  23. # specified in an env: block
  24. # - PROJECT - Firebase or Firestore
  25. # - METHOD - xcodebuild or cmake
  26. function check_changes() {
  27. if git diff --name-only "$TRAVIS_COMMIT_RANGE" | grep -Eq "$1"; then
  28. run=true
  29. fi
  30. }
  31. run=false
  32. # To force Travis to do a full run, change the "false" to "{PR number}" like
  33. # if [[ "$TRAVIS_PULL_REQUEST" == "904" ]]; then
  34. if [[ "$TRAVIS_PULL_REQUEST" == "false" ]]; then
  35. # Full builds should run everything
  36. run=true
  37. elif [[ -z "$TRAVIS_COMMIT_RANGE" ]]; then
  38. # First builds on a branch should also run everything
  39. run=true
  40. else
  41. case "$PROJECT-$METHOD" in
  42. Firebase-pod-lib-lint) # Combines Firebase-* and InAppMessaging*
  43. check_changes '^(Firebase/Auth|Firebase/Database|Firebase/DynamicLinks|'\
  44. 'Firebase/Messaging|Firebase/Storage|GoogleUtilities|Interop|Example|'\
  45. 'FirebaseAnalyticsInterop.podspec|FirebaseAuth.podspec|FirebaseAuthInterop.podspec|'\
  46. 'FirebaseCoreDiagnostics.podspec|FirebaseCoreDiagnosticsInterop.podspec|'\
  47. 'FirebaseDatabase.podspec|FirebaseDynamicLinks.podspec|FirebaseMessaging.podspec|'\
  48. 'FirebaseStorage.podspec|FirebaseStorage.podspec|Firebase/InAppMessagingDisplay|'\
  49. 'InAppMessagingDisplay|InAppMessaging|Firebase/InAppMessaging|'\
  50. 'FirebaseInAppMessaging.podspec|FirebaseInAppMessagingDisplay.podspec|'\
  51. 'Firebase/InstanceID|FirebaseInstanceID.podspec)'
  52. ;;
  53. Firebase-*)
  54. check_changes '^(Firebase/Auth|Firebase/Core|Firebase/Database|Firebase/DynamicLinks|'\
  55. 'Firebase/Messaging|Firebase/Storage|GoogleUtilities|Interop|Example|'\
  56. 'FirebaseAnalyticsIntop.podspec|FirebaseAuth.podspec|FirebaseAuthInterop.podspec|'\
  57. 'FirebaseCore.podspec|FirebaseCoreDiagnostics.podspec|FirebaseCoreDiagnosticsInterop.podspec|'\
  58. 'FirebaseDatabase.podspec|FirebaseDynamicLinks.podspec|FirebaseMessaging.podspec|'\
  59. 'FirebaseStorage.podspec|FirebaseStorage.podspec|Firebase/InstanceID|FirebaseInstanceID.podspec)'
  60. ;;
  61. FirebasePod-*)
  62. check_changes '^(CoreOnly|Firebase.podspec)'
  63. ;;
  64. Core-*)
  65. check_changes '^(Firebase/Core|Example/Core/Tests|GoogleUtilities|FirebaseCore.podspec'\
  66. 'FirebaseCoreDiagnostics.podspec|FirebaseCoreDiagnosticsInterop|FirebaseCoreDiagnosticsInterop.podspec)'
  67. ;;
  68. ABTesting-*)
  69. check_changes '^(Firebase/Core|FirebaseABTesting)'
  70. ;;
  71. Auth-*)
  72. check_changes '^(Firebase/Core|Firebase/Auth|Example/Auth|GoogleUtilities|FirebaseAuth.podspec)'
  73. ;;
  74. CoreDiagnostics-*)
  75. check_changes '^(Firebase/CoreDiagnostics|Example/CoreDiagnostics/Tests|FirebaseCoreDiagnostics.podspec|'\
  76. 'FirebaseCoreDiagnosticsInterop|FirebaseCoreDiagnosticsInterop.podspec)'
  77. ;;
  78. Database-*)
  79. check_changes '^(Firebase/Core|Firebase/Database|Example/Database|GoogleUtilities|FirebaseDatabase.podspec)'
  80. ;;
  81. DynamicLinks-*)
  82. check_changes '^(Firebase/Core|Firebase/DynamicLinks|Example/DynamicLinks|GoogleUtilities|FirebaseDynamicLinks.podspec)'
  83. ;;
  84. Functions-*)
  85. check_changes '^(Firebase/Core|Functions|GoogleUtilities|FirebaseFunctions.podspec)'
  86. ;;
  87. GoogleUtilities-*)
  88. check_changes '^(GoogleUtilities|GoogleUtilities.podspec)'
  89. ;;
  90. GoogleUtilitiesComponents-*)
  91. check_changes '^(GoogleUtilitiesComponents|GoogleUtilitiesComponents.podspec)'
  92. ;;
  93. InAppMessaging-*)
  94. check_changes '^(InAppMessaging|Firebase/InAppMessaging)'
  95. ;;
  96. InAppMessagingDisplay-*)
  97. check_changes '^(Firebase/InAppMessagingDisplay|InAppMessagingDisplay|InAppMessaging|'\
  98. 'Firebase/InAppMessaging)'
  99. ;;
  100. InstanceID-*)
  101. check_changes '^(Firebase/InstanceID|Example/InstanceID|Firebase/Core|GoogleUtilities|'\
  102. 'FirebaseInstanceID.podspec)'
  103. ;;
  104. Firestore-xcodebuild|Firestore-pod-lib-lint)
  105. check_changes '^(Firestore|FirebaseFirestore.podspec|FirebaseFirestoreSwift.podspec|'\
  106. 'GoogleUtilities)'
  107. ;;
  108. Firestore-cmake)
  109. check_changes '^(Firestore/(core|third_party)|cmake|GoogleUtilities)'
  110. ;;
  111. GoogleDataTransport-*)
  112. check_changes '^(GoogleDataTransport|GoogleDataTransport.podspec)'
  113. ;;
  114. GoogleDataTransportIntegrationTest-*)
  115. check_changes '^(GoogleDataTransport|GoogleDataTransport.podspec)'
  116. ;;
  117. GoogleDataTransportCCTSupport-*)
  118. check_changes '^(GoogleDataTransportCCTSupport|GoogleDataTransportCCTSupport.podspec|GoogleDataTransport|GoogleDataTransport.podspec)'
  119. ;;
  120. Messaging-*)
  121. check_changes '^(Firebase/Core|Firebase/Messaging|Example/Messaging|GoogleUtilities|FirebaseMessaging.podspec|Firebase/InstanceID)'
  122. ;;
  123. RemoteConfig-*)
  124. check_changes '^(Firebase/Core|FirebaseRemoteConfig)'
  125. ;;
  126. Storage-*)
  127. check_changes '^(Firebase/Core|Firebase/Storage|Example/Storage|GoogleUtilities|FirebaseStorage.podspec)'
  128. ;;
  129. Installations-*)
  130. check_changes '^(Firebase/Core|GoogleUtilities|FirebaseInstallations|FirebaseInstallations.podspec)'
  131. ;;
  132. *)
  133. echo "Unknown project-method combo" 1>&2
  134. echo " PROJECT=$PROJECT" 1>&2
  135. echo " METHOD=$METHOD" 1>&2
  136. exit 1
  137. ;;
  138. esac
  139. fi
  140. # Always rebuild if Travis configuration and/or build scripts changed.
  141. check_changes '^.travis.yml'
  142. check_changes '^Gemfile.lock'
  143. check_changes '^scripts/(build|install_prereqs|pod_lib_lint).(rb|sh)'
  144. if [[ "$run" == true ]]; then
  145. "$@"
  146. else
  147. echo "skipped $*"
  148. fi