Skip to content

Commit 8162044

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

File tree

2 files changed

+93
-4
lines changed

2 files changed

+93
-4
lines changed

.github/workflows/health-metrics.yml

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

3-
on: [ pull_request, push ]
3+
on:
4+
pull_request:
5+
types:
6+
- labeled
7+
- opened
8+
- reopened
9+
- synchronize
10+
push:
11+
branches:
12+
- master
13+
# add other feature branches here
14+
# TODO(yifany): support workflow_dispatch for metric tests (or only for startup time test)
415

516
env:
617
GITHUB_PULL_REQUEST_NUMBER: ${{ github.event.pull_request.number }}
718

819
jobs:
920
coverage:
1021
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)
22+
if: |
23+
(github.event_name == 'push' && github.repository == 'firebase/firebase-android-sdk')
24+
|| (github.event_name == 'pull_request'
25+
&& github.event.pull_request.head.repo.full_name == github.repository)
1226
runs-on: ubuntu-latest
1327
steps:
1428
- uses: actions/checkout@v3
@@ -40,7 +54,10 @@ jobs:
4054

4155
size:
4256
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)
57+
if: |
58+
(github.event_name == 'push' && github.repository == 'firebase/firebase-android-sdk')
59+
|| (github.event_name == 'pull_request'
60+
&& github.event.pull_request.head.repo.full_name == github.repository)
4461
runs-on: ubuntu-latest
4562
steps:
4663
- uses: actions/checkout@v3
@@ -69,3 +86,39 @@ jobs:
6986
- name: Run size tests (post-submit)
7087
if: ${{ github.event_name == 'push' }}
7188
run: fireci binary_size
89+
90+
startup_time:
91+
name: Startup Time
92+
if: | # In case of pull requests, label "startup-time" is required to trigger
93+
(github.event_name == 'push' && github.repository == 'firebase/firebase-android-sdk')
94+
|| (github.event_name == 'pull_request'
95+
&& github.event.label.name == 'health-metric-test: startup-time'
96+
&& github.event.pull_request.head.repo.full_name == github.repository)
97+
runs-on: ubuntu-latest
98+
steps:
99+
- uses: actions/checkout@v3
100+
with:
101+
fetch-depth: 2
102+
submodules: true
103+
- name: Set up JDK 11
104+
uses: actions/setup-java@v2
105+
with:
106+
java-version: 11
107+
distribution: temurin
108+
cache: gradle
109+
- name: Set up Python 3.10
110+
uses: actions/setup-python@v4
111+
with:
112+
python-version: '3.10'
113+
- uses: google-github-actions/auth@v0
114+
with:
115+
credentials_json: '${{ secrets.GCP_SERVICE_ACCOUNT }}'
116+
- uses: google-github-actions/setup-gcloud@v0
117+
- name: Set up fireci
118+
run: pip3 install -e ci/fireci
119+
- name: Run startup-time tests (presubmit)
120+
if: ${{ github.event_name == 'pull_request' }}
121+
run: fireci macrobenchmark ci --pull-request
122+
- name: Run startup-time tests (post-submit)
123+
if: ${{ github.event_name == 'push' }}
124+
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)