if_changed.sh 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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-*)
  43. check_changes '^(Firebase/Auth|Firebase/Core|Firebase/Database|Firebase/DynamicLinks|'\
  44. 'Firebase/Messaging|Firebase/Storage|Functions|GoogleUtilities|Interop|Example|'\
  45. 'FirebaseAnalyticsIntop.podspec|FirebaseAuth.podspec|FirebaseAuthInterop.podspec|'\
  46. 'FirebaseCore.podspec|FirebaseDatabase.podspec|FirebaseDynamicLinks.podspec|'\
  47. 'FirebaseFunctions.podspec|FirebaseMessaging.podspec|FirebaseStorage.podspec|'\
  48. 'FirebaseStorage.podspec)'
  49. ;;
  50. InAppMessagingDisplay-*)
  51. check_changes '^(Firebase/InAppMessagingDisplay|InAppMessagingDisplay)'
  52. ;;
  53. Firestore-xcodebuild|Firestore-pod-lib-lint)
  54. check_changes '^(Firestore|FirebaseFirestore.podspec|FirebaseFirestoreSwift.podspec)'
  55. ;;
  56. Firestore-cmake)
  57. check_changes '^(Firestore/(core|third_party)|cmake)'
  58. ;;
  59. *)
  60. echo "Unknown project-method combo" 1>&2
  61. echo " PROJECT=$PROJECT" 1>&2
  62. echo " METHOD=$METHOD" 1>&2
  63. exit 1
  64. ;;
  65. esac
  66. fi
  67. # Always rebuild if Travis configuration and/or build scripts changed.
  68. check_changes '^.travis.yml'
  69. check_changes '^Gemfile.lock'
  70. check_changes '^scripts/(build|if_changed|install_prereqs).sh'
  71. if [[ "$run" == true ]]; then
  72. "$@"
  73. else
  74. echo "skipped $*"
  75. fi