test_coverage.yml 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. name: test_coverage
  2. on:
  3. pull_request:
  4. # open will be triggered when a pull request is created.
  5. # synchronize will be triggered when a pull request has new commits.
  6. # closed will be triggered when a pull request is closed.
  7. types: [opened, synchronize, closed]
  8. jobs:
  9. check:
  10. if: github.repository == 'Firebase/firebase-ios-sdk' && (github.event.action == 'opened' || github.event.action == 'synchronize')
  11. name: Check changed files
  12. outputs:
  13. database_run_job: ${{ steps.check_files.outputs.database_run_job }}
  14. functions_run_job: ${{ steps.check_files.outputs.functions_run_job }}
  15. base_commit: ${{ steps.check_files.outputs.base_commit }}
  16. runs-on: ubuntu-latest
  17. steps:
  18. - name: Checkout code
  19. uses: actions/checkout@v2
  20. with:
  21. fetch-depth: 0
  22. - name: check files
  23. id: check_files
  24. env:
  25. pr_branch: ${{ github.event.pull_request.head.ref }}
  26. run: ./scripts/code_coverage_report/get_updated_files.sh
  27. pod-lib-lint-database:
  28. needs: check
  29. # Don't run on private repo unless it is a PR.
  30. # always() will trigger this job when `needs` are skipped in a `merge` pull_request event.
  31. if: always() && github.repository == 'Firebase/firebase-ios-sdk' && (needs.check.outputs.database_run_job == 'true' || github.event.pull_request.merged)
  32. runs-on: macOS-latest
  33. strategy:
  34. matrix:
  35. target: [ios]
  36. steps:
  37. - uses: actions/checkout@v2
  38. - name: Setup Bundler
  39. run: scripts/setup_bundler.sh
  40. - name: Build and test
  41. run: ./scripts/code_coverage_report/pod_test_code_coverage_report.sh FirebaseDatabase "${{ matrix.target }}"
  42. - uses: actions/upload-artifact@v2
  43. with:
  44. name: codecoverage
  45. path: /Users/runner/*.xcresult
  46. pod-lib-lint-functions:
  47. needs: check
  48. # Don't run on private repo unless it is a PR.
  49. if: always() && github.repository == 'Firebase/firebase-ios-sdk' && (needs.check.outputs.functions_run_job == 'true'|| github.event.pull_request.merged)
  50. runs-on: macOS-latest
  51. strategy:
  52. matrix:
  53. target: [ios]
  54. steps:
  55. - uses: actions/checkout@v2
  56. - name: Setup Bundler
  57. run: scripts/setup_bundler.sh
  58. - name: Build and test
  59. run: ./scripts/code_coverage_report/pod_test_code_coverage_report.sh FirebaseFunctions "${{ matrix.target }}"
  60. - uses: actions/upload-artifact@v2
  61. with:
  62. name: codecoverage
  63. path: /Users/runner/*.xcresult
  64. create_report:
  65. needs: [check, pod-lib-lint-functions, pod-lib-lint-database]
  66. env:
  67. metrics_service_secret: ${{ secrets.GHASecretsGPGPassphrase1 }}
  68. if: always()
  69. runs-on: macOS-latest
  70. steps:
  71. - uses: actions/checkout@v2
  72. - name: Access to Metrics Service
  73. run: |
  74. # Install gcloud sdk
  75. curl https://sdk.cloud.google.com > install.sh
  76. bash install.sh --disable-prompts
  77. echo "${HOME}/google-cloud-sdk/bin/" >> $GITHUB_PATH
  78. export PATH="${HOME}/google-cloud-sdk/bin/:${PATH}"
  79. # Activate the service account for Metrics Service.
  80. scripts/decrypt_gha_secret.sh scripts/gha-encrypted/metrics_service_access.json.gpg \
  81. metrics-access.json "$metrics_service_secret"
  82. gcloud auth activate-service-account --key-file metrics-access.json
  83. - uses: actions/download-artifact@v2
  84. id: download
  85. with:
  86. path: /Users/runner/test
  87. - name: Compare Diff and Post a Report
  88. if: github.event_name == 'pull_request'
  89. env:
  90. base_commit: ${{ needs.check.outputs.base_commit }}
  91. run: |
  92. # Get Head commit of the branch, instead of a merge commit created by actions/checkout.
  93. GITHUB_SHA=$(cat $GITHUB_EVENT_PATH | jq -r .pull_request.head.sha)
  94. if [ -d "${{steps.download.outputs.download-path}}" ]; then
  95. cd scripts/code_coverage_report/generate_code_coverage_report
  96. swift run CoverageReportGenerator --presubmit "firebase/firebase-ios-sdk" --commit "${GITHUB_SHA}" --token $(gcloud auth print-identity-token) --xcresult-dir "/Users/runner/test/codecoverage" --log-link "https://github.com/firebase/firebase-ios-sdk/actions/runs/${GITHUB_RUN_ID}" --pull-request-num ${{github.event.pull_request.number}} --base-commit "$base_commit"
  97. fi
  98. - name: Update New Coverage Data
  99. if: github.event.pull_request.merged == true
  100. run: |
  101. if [ -d "${{steps.download.outputs.download-path}}" ]; then
  102. cd scripts/code_coverage_report/generate_code_coverage_report
  103. swift run CoverageReportGenerator --merge "firebase/firebase-ios-sdk" --commit "${GITHUB_SHA}" --token $(gcloud auth print-identity-token) --xcresult-dir "/Users/runner/test/codecoverage" --log-link "https://github.com/firebase/firebase-ios-sdk/actions/runs/${GITHUB_RUN_ID}" --branch "${GITHUB_REF##*/}"
  104. fi