Skip to content

Commit 505f41d

Browse files
committed
Add workflow triggers for startup time test
1 parent 07dec7a commit 505f41d

File tree

2 files changed

+88
-4
lines changed

2 files changed

+88
-4
lines changed

.github/workflows/health-metrics.yml

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,23 @@
11
name: Health Metrics
22

3-
on: [ pull_request, push ]
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- master
8+
# add other feature branches here
9+
# TODO(yifany): support workflow_dispatch for metric tests (or only for startup time test)
410

511
env:
612
GITHUB_PULL_REQUEST_NUMBER: ${{ github.event.pull_request.number }}
713

814
jobs:
915
coverage:
1016
name: Coverage
11-
if: (github.repository == 'Firebase/firebase-android-sdk' && github.event_name == 'push') || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository)
17+
if: |
18+
(github.event_name == 'push' && github.repository == 'firebase/firebase-android-sdk')
19+
|| (github.event_name == 'pull_request'
20+
&& github.event.pull_request.head.repo.full_name == github.repository)
1221
runs-on: ubuntu-latest
1322
steps:
1423
- uses: actions/checkout@v3
@@ -40,7 +49,10 @@ jobs:
4049

4150
size:
4251
name: Size
43-
if: (github.repository == 'Firebase/firebase-android-sdk' && github.event_name == 'push') || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository)
52+
if: |
53+
(github.event_name == 'push' && github.repository == 'firebase/firebase-android-sdk')
54+
|| (github.event_name == 'pull_request'
55+
&& github.event.pull_request.head.repo.full_name == github.repository)
4456
runs-on: ubuntu-latest
4557
steps:
4658
- uses: actions/checkout@v3
@@ -69,3 +81,39 @@ jobs:
6981
- name: Run size tests (post-submit)
7082
if: ${{ github.event_name == 'push' }}
7183
run: fireci binary_size
84+
85+
startup_time:
86+
name: Startup Time
87+
if: | # In case of pull requests, label "startup-time" is required to trigger
88+
(github.event_name == 'push' && github.repository == 'firebase/firebase-android-sdk')
89+
|| (github.event_name == 'pull_request'
90+
&& github.event.label.name == 'startup-time'
91+
&& github.event.pull_request.head.repo.full_name == github.repository)
92+
runs-on: ubuntu-latest
93+
steps:
94+
- uses: actions/checkout@v3
95+
with:
96+
fetch-depth: 2
97+
submodules: true
98+
- name: Set up JDK 11
99+
uses: actions/setup-java@v2
100+
with:
101+
java-version: 11
102+
distribution: temurin
103+
cache: gradle
104+
- name: Set up Python 3.10
105+
uses: actions/setup-python@v4
106+
with:
107+
python-version: '3.10'
108+
- uses: google-github-actions/auth@v0
109+
with:
110+
credentials_json: '${{ secrets.GCP_SERVICE_ACCOUNT }}'
111+
- uses: google-github-actions/setup-gcloud@v0
112+
- name: Set up fireci
113+
run: pip3 install -e ci/fireci
114+
- name: Run startup-time tests (presubmit)
115+
if: ${{ github.event_name == 'pull_request' }}
116+
run: fireci macrobenchmark ci --pull-request
117+
- name: Run startup-time tests (post-submit)
118+
if: ${{ github.event_name == 'push' }}
119+
run: fireci macrobenchmark ci --push

ci/fireci/fireciplugins/macrobenchmark/commands.py

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@
1414

1515
import asyncio
1616
import click
17+
import json
1718

1819
from .analyze import analyzer
1920
from .run import runner
20-
from fireci import ci_command
21+
from fireci import ci_command, ci_utils, uploader
2122
from pathlib import Path
2223
from typing import List
2324

@@ -125,4 +126,39 @@ def analyze(
125126
output_dir,
126127
)
127128

129+
130+
@click.option(
131+
'--pull-request/--push',
132+
required=True,
133+
help='Whether the test is running for a pull request or a push event.'
134+
)
135+
@click.option(
136+
'--repeat',
137+
default=10,
138+
show_default=True,
139+
help='Number of times to repeat the test (for obtaining more data points).'
140+
)
141+
@ci_command(group=macrobenchmark)
142+
def ci(pull_request, repeat):
143+
"""Run tests in CI and upload results to the metric service."""
144+
145+
# TODO(yifany): run tests only for affected product in pull requests
146+
147+
output_path = Path("macrobenchmark-test-output.json")
148+
asyncio.run(runner.start(build_only=False, local=False, repeat=repeat, output=output_path))
149+
150+
with open(output_path) as output_file:
151+
output = json.load(output_file)
152+
ftl_dirs = list(filter(lambda x: x['project'] == 'all-included', output))[0]['successful_runs']
153+
ftl_bucket_name = 'fireescape-benchmark-results'
154+
155+
log = ci_utils.ci_log_link()
156+
ftl_results = list(map(lambda x: {'bucket': ftl_bucket_name, 'dir': x}, ftl_dirs))
157+
startup_time_data = {'log': log, 'ftlResults': ftl_results}
158+
159+
metric_service_url = 'https://api.firebase-sdk-health-metrics.com'
160+
access_token = ci_utils.gcloud_identity_token()
161+
uploader.post_report(startup_time_data, metric_service_url, access_token, 'startup-time')
162+
163+
128164
# TODO(yifany): support of command chaining

0 commit comments

Comments
 (0)