health-metrics-presubmit.yml 19 KB

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