if_changed.sh 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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 '^(FirebaseAuth|FirebaseDatabase|Firebase/DynamicLinks|'\
  44. 'FirebaseMessaging|FirebaseStorage|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|'\
  49. 'InAppMessaging|Firebase/InAppMessaging|'\
  50. 'FirebaseInAppMessaging.podspec|'\
  51. 'FirebaseInstallations|'\
  52. 'FirebaseCrashlytics.podspec)'\
  53. ;;
  54. FirebasePod-*)
  55. check_changes '^(CoreOnly|Firebase.podspec)'
  56. ;;
  57. Core-*)
  58. check_changes '^(FirebaseCore|Example/Core/Tests|GoogleUtilities|FirebaseCore.podspec'\
  59. 'Firebase/CoreDiagnostics|Example/CoreDiagnostics/Tests|FirebaseCoreDiagnostics.podspec|'\
  60. 'FirebaseCoreDiagnosticsInterop|FirebaseCoreDiagnosticsInterop.podspec)'
  61. ;;
  62. ABTesting-*)
  63. check_changes '^(FirebaseCore|FirebaseABTesting)'
  64. ;;
  65. Auth-*)
  66. check_changes '^(FirebaseCore|FirebaseAuth|GoogleUtilities|FirebaseAuth.podspec)'
  67. ;;
  68. Crashlytics-*)
  69. check_changes '^(FirebaseCore|GoogleUtilities|Crashlytics|FirebaseCrashlytics.podspec|'\
  70. 'FirebaseInstallations|GoogleDataTransport|GoogleDataTransport.podspec)'
  71. ;;
  72. Database-*)
  73. check_changes '^(FirebaseCore|FirebaseDatabase|GoogleUtilities|FirebaseDatabase.podspec|'\
  74. 'scripts/run_database_emulator.sh)'
  75. ;;
  76. DynamicLinks-*)
  77. check_changes '^(FirebaseCore|Firebase/DynamicLinks|Example/DynamicLinks|GoogleUtilities|FirebaseDynamicLinks.podspec)'
  78. ;;
  79. Functions-*)
  80. check_changes '^(FirebaseCore|Functions|GoogleUtilities|FirebaseFunctions.podspec)'
  81. ;;
  82. GoogleUtilities-*)
  83. check_changes '^(GoogleUtilities|GoogleUtilities.podspec)'
  84. ;;
  85. GoogleUtilitiesComponents-*)
  86. check_changes '^(GoogleUtilities|GoogleUtilitiesComponents|GoogleUtilitiesComponents.podspec)'
  87. ;;
  88. InAppMessaging-*)
  89. check_changes '^(FirebaseInAppMessaging|'\
  90. 'FirebaseInAppMessaging.podspec|'\
  91. 'FirebaseInstallations)'
  92. ;;
  93. Firestore-xcodebuild|Firestore-pod-lib-lint)
  94. check_changes '^(Firestore|FirebaseFirestore.podspec|FirebaseFirestoreSwift.podspec|'\
  95. 'GoogleUtilities|scripts/run_firestore_emulator.sh)'
  96. ;;
  97. Firestore-cmake)
  98. check_changes '^(Firestore/(core|third_party)|cmake|FirebaseCore|GoogleUtilities|)'\
  99. 'scripts/run_firestore_emulator.sh)'
  100. ;;
  101. GoogleDataTransport-*)
  102. check_changes '^(GoogleDataTransport|GoogleDataTransport.podspec)'
  103. ;;
  104. Messaging-*)
  105. check_changes '^(FirebaseCore|FirebaseMessaging|GoogleUtilities|FirebaseMessaging.podspec|'\
  106. 'FirebaseInstallations)'
  107. ;;
  108. RemoteConfig-*)
  109. check_changes '^(FirebaseCore|FirebaseRemoteConfig|FirebaseRemoteConfig.podspec|'\
  110. 'FirebaseInstallations)'
  111. ;;
  112. Storage-*)
  113. check_changes '^(FirebaseCore|FirebaseStorage|GoogleUtilities|FirebaseStorage.podspec)'
  114. ;;
  115. Installations-*)
  116. check_changes '^(FirebaseCore|GoogleUtilities|FirebaseInstallations)'
  117. ;;
  118. *)
  119. echo "Unknown project-method combo" 1>&2
  120. echo " PROJECT=$PROJECT" 1>&2
  121. echo " METHOD=$METHOD" 1>&2
  122. exit 1
  123. ;;
  124. esac
  125. fi
  126. # Always rebuild if Travis configuration and/or build scripts changed.
  127. check_changes '^.travis.yml'
  128. check_changes '^Gemfile.lock'
  129. check_changes '^scripts/(build|install_prereqs|pod_lib_lint).(rb|sh)'
  130. check_changes '^scripts/xcresult_logs.py'
  131. if [[ "$run" == true ]]; then
  132. "$@"
  133. else
  134. echo "skipped $*"
  135. fi