test_coverage.yml 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  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. env:
  9. METRICS_SERVICE_SECRET: ${{ secrets.GHASecretsGPGPassphrase1 }}
  10. jobs:
  11. check:
  12. if: github.repository == 'Firebase/firebase-ios-sdk' && (github.event.action == 'opened' || github.event.action == 'synchronize')
  13. name: Check changed files
  14. outputs:
  15. abtesting_run_job: ${{ steps.check_files.outputs.abtesting_run_job }}
  16. auth_run_job: ${{ steps.check_files.outputs.auth_run_job }}
  17. database_run_job: ${{ steps.check_files.outputs.database_run_job }}
  18. dynamiclinks_run_job: ${{ steps.check_files.outputs.dynamiclinks_run_job }}
  19. firestore_run_job: ${{ steps.check_files.outputs.firestore_run_job }}
  20. functions_run_job: ${{ steps.check_files.outputs.functions_run_job }}
  21. inappmessaging_run_job: ${{ steps.check_files.outputs.inappmessaging_run_job }}
  22. messaging_run_job: ${{ steps.check_files.outputs.messaging_run_job }}
  23. performance_run_job: ${{ steps.check_files.outputs.performance_run_job }}
  24. remoteconfig_run_job: ${{ steps.check_files.outputs.remoteconfig_run_job }}
  25. storage_run_job: ${{ steps.check_files.outputs.storage_run_job }}
  26. base_commit: ${{ steps.check_files.outputs.base_commit }}
  27. runs-on: ubuntu-latest
  28. steps:
  29. - name: Checkout code
  30. uses: actions/checkout@v2
  31. with:
  32. fetch-depth: 0
  33. - name: check files
  34. id: check_files
  35. env:
  36. pr_branch: ${{ github.event.pull_request.head.ref }}
  37. run: |
  38. if [ ! -z "${{ env.METRICS_SERVICE_SECRET }}" ]; then
  39. ./scripts/code_coverage_report/get_updated_files.sh
  40. fi
  41. pod-lib-lint-abtesting:
  42. needs: check
  43. # Don't run on private repo unless it is a PR.
  44. # always() will trigger this job when `needs` are skipped in a `merge` pull_request event.
  45. if: always() && github.repository == 'Firebase/firebase-ios-sdk' && (needs.check.outputs.abtesting_run_job == 'true'|| github.event.pull_request.merged)
  46. runs-on: macOS-latest
  47. strategy:
  48. matrix:
  49. target: [iOS]
  50. steps:
  51. - uses: actions/checkout@v2
  52. - name: Setup Bundler
  53. run: scripts/setup_bundler.sh
  54. - name: Build and test
  55. run: ./scripts/code_coverage_report/pod_test_code_coverage_report.sh --sdk=FirebaseABTesting --platform=${{ matrix.target }}
  56. - uses: actions/upload-artifact@v2
  57. with:
  58. name: codecoverage
  59. path: /Users/runner/*.xcresult
  60. pod-lib-lint-auth:
  61. needs: check
  62. # Don't run on private repo unless it is a PR.
  63. if: always() && github.repository == 'Firebase/firebase-ios-sdk' && (needs.check.outputs.auth_run_job == 'true'|| github.event.pull_request.merged)
  64. runs-on: macOS-latest
  65. strategy:
  66. matrix:
  67. target: [iOS]
  68. steps:
  69. - uses: actions/checkout@v2
  70. - name: Setup Bundler
  71. run: scripts/setup_bundler.sh
  72. - name: Build and test
  73. run: ./scripts/code_coverage_report/pod_test_code_coverage_report.sh --sdk=FirebaseAuth --platform=${{ matrix.target }}
  74. - uses: actions/upload-artifact@v2
  75. with:
  76. name: codecoverage
  77. path: /Users/runner/*.xcresult
  78. pod-lib-lint-database:
  79. needs: check
  80. # Don't run on private repo unless it is a PR.
  81. if: always() && github.repository == 'Firebase/firebase-ios-sdk' && (needs.check.outputs.database_run_job == 'true' || github.event.pull_request.merged)
  82. runs-on: macOS-latest
  83. strategy:
  84. matrix:
  85. target: [iOS]
  86. steps:
  87. - uses: actions/checkout@v2
  88. - name: Setup Bundler
  89. run: scripts/setup_bundler.sh
  90. - name: Build and test
  91. run: ./scripts/code_coverage_report/pod_test_code_coverage_report.sh --sdk=FirebaseDatabase --platform=${{ matrix.target }}
  92. - uses: actions/upload-artifact@v2
  93. with:
  94. name: codecoverage
  95. path: /Users/runner/*.xcresult
  96. pod-lib-lint-dynamiclinks:
  97. needs: check
  98. # Don't run on private repo unless it is a PR.
  99. if: always() && github.repository == 'Firebase/firebase-ios-sdk' && (needs.check.outputs.dynamiclinks_run_job == 'true'|| github.event.pull_request.merged)
  100. runs-on: macOS-latest
  101. strategy:
  102. matrix:
  103. target: [iOS]
  104. steps:
  105. - uses: actions/checkout@v2
  106. - name: Setup Bundler
  107. run: scripts/setup_bundler.sh
  108. - name: Build and test
  109. run: ./scripts/code_coverage_report/pod_test_code_coverage_report.sh --sdk=FirebaseDynamicLinks --platform=${{ matrix.target }}
  110. - uses: actions/upload-artifact@v2
  111. with:
  112. name: codecoverage
  113. path: /Users/runner/*.xcresult
  114. pod-lib-lint-firestore:
  115. needs: check
  116. # Don't run on private repo unless it is a PR.
  117. # Disable Firestore for now since Firestore currently does not have unit tests in podspecs.
  118. if: always() && github.repository == 'Firebase/firebase-ios-sdk' && (needs.check.outputs.firestore_run_job == 'true'|| github.event.pull_request.merged)
  119. runs-on: macOS-latest
  120. strategy:
  121. matrix:
  122. target: [iOS]
  123. steps:
  124. - uses: actions/checkout@v2
  125. - name: Setup Bundler
  126. run: scripts/setup_bundler.sh
  127. - name: Build and test
  128. run: ./scripts/code_coverage_report/pod_test_code_coverage_report.sh --sdk=FirebaseFirestore --platform=${{ matrix.target }}
  129. - uses: actions/upload-artifact@v2
  130. with:
  131. name: codecoverage
  132. path: /Users/runner/*.xcresult
  133. pod-lib-lint-functions:
  134. needs: check
  135. # Don't run on private repo unless it is a PR.
  136. if: always() && github.repository == 'Firebase/firebase-ios-sdk' && (needs.check.outputs.functions_run_job == 'true'|| github.event.pull_request.merged)
  137. runs-on: macOS-latest
  138. strategy:
  139. matrix:
  140. target: [iOS]
  141. steps:
  142. - uses: actions/checkout@v2
  143. - name: Setup Bundler
  144. run: scripts/setup_bundler.sh
  145. - name: Build and test
  146. run: ./scripts/code_coverage_report/pod_test_code_coverage_report.sh --sdk=FirebaseFunctions --platform=${{ matrix.target }}
  147. - uses: actions/upload-artifact@v2
  148. with:
  149. name: codecoverage
  150. path: /Users/runner/*.xcresult
  151. pod-lib-lint-inappmessaging:
  152. needs: check
  153. # Don't run on private repo unless it is a PR.
  154. if: always() && github.repository == 'Firebase/firebase-ios-sdk' && (needs.check.outputs.inappmessaging_run_job == 'true'|| github.event.pull_request.merged)
  155. runs-on: macOS-latest
  156. strategy:
  157. matrix:
  158. target: [iOS]
  159. steps:
  160. - uses: actions/checkout@v2
  161. - name: Setup Bundler
  162. run: scripts/setup_bundler.sh
  163. - name: Build and test
  164. run: ./scripts/code_coverage_report/pod_test_code_coverage_report.sh --sdk=FirebaseInAppMessaging --platform=${{ matrix.target }}
  165. - uses: actions/upload-artifact@v2
  166. with:
  167. name: codecoverage
  168. path: /Users/runner/*.xcresult
  169. pod-lib-lint-messaging:
  170. needs: check
  171. # Don't run on private repo unless it is a PR.
  172. if: always() && github.repository == 'Firebase/firebase-ios-sdk' && (needs.check.outputs.messaging_run_job == 'true'|| github.event.pull_request.merged)
  173. runs-on: macOS-latest
  174. strategy:
  175. matrix:
  176. target: [iOS]
  177. steps:
  178. - uses: actions/checkout@v2
  179. - name: Setup Bundler
  180. run: scripts/setup_bundler.sh
  181. - name: Build and test
  182. run: ./scripts/code_coverage_report/pod_test_code_coverage_report.sh --sdk=FirebaseMessaging --platform=${{ matrix.target }}
  183. - uses: actions/upload-artifact@v2
  184. with:
  185. name: codecoverage
  186. path: /Users/runner/*.xcresult
  187. pod-lib-lint-performance:
  188. needs: check
  189. # Don't run on private repo unless it is a PR.
  190. if: always() && github.repository == 'Firebase/firebase-ios-sdk' && (needs.check.outputs.performance_run_job == 'true'|| github.event.pull_request.merged)
  191. runs-on: macOS-latest
  192. strategy:
  193. matrix:
  194. target: [iOS]
  195. steps:
  196. - uses: actions/checkout@v2
  197. - name: Setup Bundler
  198. run: scripts/setup_bundler.sh
  199. - name: Build and test
  200. run: ./scripts/code_coverage_report/pod_test_code_coverage_report.sh --sdk=FirebasePerformance --platform=${{ matrix.target }}
  201. - uses: actions/upload-artifact@v2
  202. with:
  203. name: codecoverage
  204. path: /Users/runner/*.xcresult
  205. pod-lib-lint-remoteconfig:
  206. needs: check
  207. # Don't run on private repo unless it is a PR.
  208. if: always() && github.repository == 'Firebase/firebase-ios-sdk' && (needs.check.outputs.remoteconfig_run_job == 'true'|| github.event.pull_request.merged)
  209. runs-on: macOS-latest
  210. strategy:
  211. matrix:
  212. target: [iOS]
  213. steps:
  214. - uses: actions/checkout@v2
  215. - name: Setup Bundler
  216. run: scripts/setup_bundler.sh
  217. - name: Build and test
  218. run: ./scripts/code_coverage_report/pod_test_code_coverage_report.sh --sdk=FirebaseRemoteConfig --platform=${{ matrix.target }}
  219. - uses: actions/upload-artifact@v2
  220. with:
  221. name: codecoverage
  222. path: /Users/runner/*.xcresult
  223. pod-lib-lint-storage:
  224. needs: check
  225. # Don't run on private repo unless it is a PR.
  226. if: always() && github.repository == 'Firebase/firebase-ios-sdk' && (needs.check.outputs.storage_run_job == 'true'|| github.event.pull_request.merged)
  227. runs-on: macOS-latest
  228. strategy:
  229. matrix:
  230. target: [iOS]
  231. steps:
  232. - uses: actions/checkout@v2
  233. - name: Setup Bundler
  234. run: scripts/setup_bundler.sh
  235. - name: Build and test
  236. run: ./scripts/code_coverage_report/pod_test_code_coverage_report.sh --sdk=FirebaseStorage --platform=${{ matrix.target }}
  237. - uses: actions/upload-artifact@v2
  238. with:
  239. name: codecoverage
  240. path: /Users/runner/*.xcresult
  241. create_report:
  242. needs: [check, pod-lib-lint-abtesting, pod-lib-lint-auth, pod-lib-lint-database, pod-lib-lint-dynamiclinks, pod-lib-lint-firestore, pod-lib-lint-functions, pod-lib-lint-inappmessaging, pod-lib-lint-messaging, pod-lib-lint-performance, pod-lib-lint-remoteconfig, pod-lib-lint-storage]
  243. if: always()
  244. runs-on: macOS-latest
  245. steps:
  246. - name: Checkout code
  247. uses: actions/checkout@v2
  248. with:
  249. fetch-depth: 0
  250. - name: Access to Metrics Service
  251. if: ${{ env.METRICS_SERVICE_SECRET != '' }} && (github.event.action != 'closed' || github.event.pull_request.merged)
  252. run: |
  253. # Install gcloud sdk
  254. curl https://sdk.cloud.google.com > install.sh
  255. bash install.sh --disable-prompts
  256. echo "${HOME}/google-cloud-sdk/bin/" >> $GITHUB_PATH
  257. export PATH="${HOME}/google-cloud-sdk/bin/:${PATH}"
  258. # Activate the service account for Metrics Service.
  259. scripts/decrypt_gha_secret.sh scripts/gha-encrypted/metrics_service_access.json.gpg \
  260. metrics-access.json "${{ env.METRICS_SERVICE_SECRET }}"
  261. gcloud auth activate-service-account --key-file metrics-access.json
  262. - uses: actions/download-artifact@v2
  263. id: download
  264. with:
  265. path: /Users/runner/test
  266. - name: Compare Diff and Post a Report
  267. if: github.event.pull_request.merged != true && github.event.action != 'closed' && env.METRICS_SERVICE_SECRET != ''
  268. env:
  269. base_commit: ${{ needs.check.outputs.base_commit }}
  270. run: |
  271. # Get Head commit of the branch, instead of a merge commit created by actions/checkout.
  272. GITHUB_SHA=$(cat $GITHUB_EVENT_PATH | jq -r .pull_request.head.sha)
  273. if [ -d "${{steps.download.outputs.download-path}}" ]; then
  274. cd scripts/code_coverage_report/generate_code_coverage_report
  275. swift run CoverageReportGenerator --presubmit "firebase/firebase-ios-sdk" --head-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"
  276. fi
  277. - name: Incremental Code Coverage
  278. if: github.event.pull_request.merged != true && github.event.action != 'closed'
  279. env:
  280. base_commit: ${{ needs.check.outputs.base_commit }}
  281. run: |
  282. # Get Head commit of the branch, instead of a merge commit created by actions/checkout.
  283. GITHUB_SHA=$(cat $GITHUB_EVENT_PATH | jq -r .pull_request.head.sha)
  284. # Get a JSON of `git diff` from the base commit.
  285. git diff -U0 ${base_commit} "${GITHUB_SHA}" | scripts/code_coverage_report/git_diff_to_json.sh > scripts/code_coverage_report/generate_code_coverage_report/git_diff.json
  286. cat "scripts/code_coverage_report/generate_code_coverage_report/git_diff.json"
  287. if [ -d "${{steps.download.outputs.download-path}}" ]; then
  288. # Create an uncovered_file_lines.json including code lines not covered by tests.
  289. cd scripts/code_coverage_report/generate_code_coverage_report
  290. swift run IncrementalCoverageReportGenerator --changed-files "git_diff.json" --file-archive-root-path "${GITHUB_WORKSPACE}" --xcresult-dir "${{steps.download.outputs.download-path}}" --uncovered-line-file-json "uncovered_file_lines.json"
  291. # Post uncovered lines to PRs.
  292. pull_number=$(jq --raw-output .pull_request.number "$GITHUB_EVENT_PATH")
  293. cd ..
  294. bundle install
  295. INPUT_ACCESS_TOKEN=${{ secrets.GITHUB_TOKEN }} \
  296. GITHUB_REPOSITORY="${GITHUB_REPOSITORY}" \
  297. UNCOVERED_LINE_FILE="generate_code_coverage_report/uncovered_file_lines.json" \
  298. TESTING_COMMIT="${GITHUB_SHA}" \
  299. PULL_REQUEST="${pull_number}" \
  300. bundle exec ruby post_incremental_coverage_in_pr.rb
  301. fi
  302. - name: Update New Coverage Data
  303. if: github.event.pull_request.merged && env.METRICS_SERVICE_SECRET != ''
  304. run: |
  305. if [ -d "${{steps.download.outputs.download-path}}" ]; then
  306. cd scripts/code_coverage_report/generate_code_coverage_report
  307. swift run CoverageReportGenerator --merge "firebase/firebase-ios-sdk" --head-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}" --source-branch "${{ github.base_ref }}"
  308. fi