get_updated_files.sh 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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 file_patterns.json will trigger code coverage workflows.
  16. # Updates in a pull request will generate a code coverage report in a PR.
  17. exclude_specs=""
  18. while getopts "p:e:" flag
  19. do
  20. case "${flag}" in
  21. p) spec_output_file=${OPTARG};;
  22. e) exclude_specs=${OPTARG[*]};;
  23. esac
  24. done
  25. dir=$(pwd)
  26. target_branch_head=$(git rev-parse remotes/origin/${GITHUB_BASE_REF})
  27. echo "The target branch head commit is ${target_branch_head}."
  28. # Set target branch head and this will be used to compare diffs of coverage to the current commit.
  29. echo "::set-output name=target_branch_head::${target_branch_head}"
  30. cd scripts/health_metrics/generate_code_coverage_report
  31. # List changed file from the merged commit. This is generated by comparing the
  32. # merge commit to the head commit from the target branch.
  33. git diff --name-only remotes/origin/${GITHUB_BASE_REF} ${GITHUB_SHA} > updated_files.txt
  34. if [ -z $spec_output_file ] ; then
  35. swift run UpdatedFilesCollector --changed-file-paths updated_files.txt --code-coverage-file-patterns ../file_patterns.json
  36. else
  37. swift run UpdatedFilesCollector --changed-file-paths updated_files.txt --code-coverage-file-patterns ../file_patterns.json --output-sdk-file-url "${spec_output_file}" --exclude-podspecs ${exclude_specs}
  38. mv "${spec_output_file}" "${dir}"
  39. fi