health-metrics-presubmit.yml 16 KB

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