get_updated_files.sh 1.5 KB

12345678910111213141516171819202122232425262728293031
  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. set -ex
  15. # Updated files in paths in code_coverage_file_list.json will trigger code coverage workflows.
  16. # Updates in a pull request will generate a code coverage report in a PR.
  17. # Get most rescent ancestor commit.
  18. common_commit=$(git merge-base remotes/origin/${pr_branch} remotes/origin/master)
  19. echo "The common commit is ${common_commit}."
  20. # Set base commit and this will be used to compare diffs of coverage to the current commit.
  21. echo "::set-output name=base_commit::${common_commit}"
  22. cd scripts/code_coverage_report/generate_code_coverage_report
  23. # List changed file from the base commit. This is generated by comparing the
  24. # head of the branch and the common commit from the master branch.
  25. git diff --name-only $common_commit remotes/origin/${pr_branch} > updated_files.txt
  26. swift run UpdatedFilesCollector --changed-file-paths updated_files.txt --code-coverage-file-patterns ../code_coverage_file_list.json