get_updated_files.sh 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. # Copyright 2021 Google LLC
  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. DATABASE_PATHS=("FirebaseDatabase.*" \
  15. ".github/workflows/database\\.yml" \
  16. "Example/Database/" \
  17. "Interop/Auth/Public/\.\*.h")
  18. FUNCTIONS_PATHS=("Functions.*" \
  19. ".github/workflows/functions\\.yml" \
  20. "Interop/Auth/Public/\.\*.h" \
  21. "FirebaseMessaging/Sources/Interop/\.\*.h")
  22. # Set default flag variables which will determine if an sdk workflow will be triggererd.
  23. echo "::set-output name=database_run_job::false"
  24. echo "::set-output name=functions_run_job::false"
  25. # Get most rescent ancestor commit.
  26. common_commit=$(git merge-base remotes/origin/${pr_branch} remotes/origin/master)
  27. echo "The common commit is ${common_commit}."
  28. # List changed file from the base commit. This is generated by comparing the
  29. # head of the branch and the common commit from the master branch.
  30. echo "=============== list changed files ==============="
  31. cat < <(git diff --name-only $common_commit remotes/origin/${pr_branch})
  32. echo "============= paths of changed files ============="
  33. git diff --name-only $common_commit remotes/origin/${pr_branch} > updated_files.txt
  34. # Loop over updated files if their path match patterns then flags to trigger
  35. # SDK pod test workflow will be set to true.
  36. while IFS= read -r file
  37. do
  38. for path in "${DATABASE_PATHS[@]}"
  39. do
  40. if [[ "${file}" =~ $path ]]; then
  41. echo "This file is updated under the path, ${path}"
  42. echo "::set-output name=database_run_job::true"
  43. break
  44. fi
  45. done
  46. for path in "${FUNCTIONS_PATHS[@]}"
  47. do
  48. if [[ "${file}" =~ $path ]]; then
  49. echo "This file is updated under the path, ${path}"
  50. echo "::set-output name=functions_run_job::true"
  51. break
  52. fi
  53. done
  54. done < updated_files.txt