get_updated_files.sh 2.5 KB

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