test_coverage.yml 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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: [open, synchronize, closed]
  8. jobs:
  9. check:
  10. if: github.repository == 'Firebase/firebase-ios-sdk' && 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. # Don't run on private repo unless it is a PR.
  29. if: github.repository == 'Firebase/firebase-ios-sdk' && (needs.check.outputs.database_run_job == 'true' || github.event.pull_request.merged == true)
  30. needs: check
  31. runs-on: macOS-latest
  32. strategy:
  33. matrix:
  34. target: [ios]
  35. steps:
  36. - uses: actions/checkout@v2
  37. - name: Setup Bundler
  38. run: scripts/setup_bundler.sh
  39. - name: Build and test
  40. run: ./scripts/code_coverage_report/pod_test_code_coverage_report.sh FirebaseDatabase "${{ matrix.target }}"
  41. - uses: actions/upload-artifact@v2
  42. with:
  43. name: codecoverage
  44. path: /Users/runner/*.xcresult
  45. pod-lib-lint-functions:
  46. # Don't run on private repo unless it is a PR.
  47. if: github.repository == 'Firebase/firebase-ios-sdk' && (needs.check.outputs.functions_run_job == 'true' || github.event.pull_request.merged == true)
  48. needs: check
  49. runs-on: macOS-latest
  50. strategy:
  51. matrix:
  52. target: [ios]
  53. steps:
  54. - uses: actions/checkout@v2
  55. - name: Setup Bundler
  56. run: scripts/setup_bundler.sh
  57. - name: Build and test
  58. run: ./scripts/code_coverage_report/pod_test_code_coverage_report.sh FirebaseFunctions "${{ matrix.target }}"
  59. - uses: actions/upload-artifact@v2
  60. with:
  61. name: codecoverage
  62. path: /Users/runner/*.xcresult
  63. create_report:
  64. needs: [check, pod-lib-lint-functions, pod-lib-lint-database]
  65. env:
  66. metrics_service_secret: ${{ secrets.GHASecretsGPGPassphrase1 }}
  67. if: always()
  68. runs-on: macOS-latest
  69. steps:
  70. - uses: actions/checkout@v2
  71. - name: Access to Metrics Service
  72. run: |
  73. # Install gcloud sdk
  74. curl https://sdk.cloud.google.com > install.sh
  75. bash install.sh --disable-prompts
  76. echo "${HOME}/google-cloud-sdk/bin/" >> $GITHUB_PATH
  77. export PATH="${HOME}/google-cloud-sdk/bin/:${PATH}"
  78. # Activate the service account for Metrics Service.
  79. scripts/decrypt_gha_secret.sh scripts/gha-encrypted/metrics_service_access.json.gpg \
  80. metrics-access.json "$metrics_service_secret"
  81. gcloud auth activate-service-account --key-file metrics-access.json
  82. - uses: actions/download-artifact@v2
  83. id: download
  84. with:
  85. path: /Users/runner/test
  86. - name: Compare Diff and Post a Report
  87. if: github.event_name == 'pull_request'
  88. env:
  89. base_commit: ${{ needs.check.outputs.base_commit }}
  90. run: |
  91. # Get Head commit of the branch, instead of a merge commit created by actions/checkout.
  92. GITHUB_SHA=$(cat $GITHUB_EVENT_PATH | jq -r .pull_request.head.sha)
  93. if [ -d "${{steps.download.outputs.download-path}}" ]; then
  94. cd scripts/code_coverage_report/generate_code_coverage_report
  95. 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"
  96. fi
  97. - name: Update New Coverage Data
  98. if: github.event.pull_request.merged == true
  99. run: |
  100. if [ -d "${{steps.download.outputs.download-path}}" ]; then
  101. cd scripts/code_coverage_report/generate_code_coverage_report
  102. 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##*/}"
  103. fi