Skip to content

Commit 01c1547

Browse files
cynthiajoanCynthia Jiangjonsimantov
authored
Add nightly test dashboard to Nightly issue (#778)
* add workflow for init * update install pre-request * some clean up * test in gha * tweak the condition for the run * get run logs * update test workflow to add previous build run * fix the error in test workflow * tweak test workflow output * test output * only do short now * remove extended * test workflow * fix the left from the refactor * one more * clean up * clean up for PR * Fix fetching of package run ID from test run ID. * Fix logfile download. * Fix app_check testapp name. * Add the whole build report. * Update build report to have the full report. * Remove extraneous print. * Some output cleanup. * Modify header row. * Fix log error. --------- Co-authored-by: Cynthia Jiang <[email protected]> Co-authored-by: Jon Simantov <[email protected]>
1 parent 8762f70 commit 01c1547

13 files changed

+893
-31
lines changed

.github/workflows/build-report.yml

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,34 +29,39 @@ jobs:
2929
path: firebase-cpp-sdk
3030
submodules: true
3131
fetch-depth: 0
32-
- name: Install Desktop SDK prerequisites
33-
uses: nick-invision/retry@v2
32+
- name: Setup python
33+
uses: actions/setup-python@v4
3434
with:
35-
timeout_minutes: 15
36-
max_attempts: 3
37-
command: |
38-
python3 firebase-cpp-sdk/scripts/gha/install_prereqs_desktop.py --gha_build
39-
python3 -m pip install requests python-dateutil progress attrs
35+
python-version: '3.7'
36+
37+
- name: Install prerequisites
38+
shell: bash
39+
run: |
40+
echo "FIREBASE_CPP_SDK_DIR=${{ github.workspace }}/firebase-cpp-sdk" >> $GITHUB_ENV
41+
cd firebase-cpp-sdk
42+
python3 scripts/gha/install_prereqs_desktop.py --gha_build
43+
python3 -m pip install requests python-dateutil progress attrs
44+
cd ..
4045
- name: Fetch GitHub jobs (with retry)
4146
uses: nick-invision/retry@v2
4247
with:
4348
timeout_minutes: 20
4449
max_attempts: 3
4550
shell: bash
46-
command: python3 firebase-cpp-sdk/scripts/gha/report_build_status.py --token ${{ github.token }} --days ${{ env.numDays }} --write_cache build_status_short.cache
51+
command: python3 scripts/gha/report_build_status.py --token ${{ github.token }} --days ${{ env.numDays }} --write_cache build_status_short.cache
4752
- name: Fetch extended GitHub jobs (with retry)
4853
uses: nick-invision/retry@v2
4954
with:
5055
timeout_minutes: 80
5156
max_attempts: 3
5257
shell: bash
53-
command: python3 firebase-cpp-sdk/scripts/gha/report_build_status.py --token ${{ github.token }} --days ${{ env.numDaysExtended }} --write_cache build_status.cache
58+
command: python3 scripts/gha/report_build_status.py --token ${{ github.token }} --days ${{ env.numDaysExtended }} --write_cache build_status.cache
5459
- name: Generate report files
5560
run: |
56-
python3 firebase-cpp-sdk/scripts/gha/report_build_status.py --token ${{ github.token }} --days ${{ env.numDays }} --output_markdown --read_cache build_status_short.cache > report_short.md
57-
python3 firebase-cpp-sdk/scripts/gha/report_build_status.py --token ${{ github.token }} --days ${{ env.numDaysExtended }} --output_markdown --read_cache build_status.cache > report_extended.md
58-
python3 firebase-cpp-sdk/scripts/gha/report_build_status.py --token ${{ github.token }} --days ${{ env.numDaysExtended }} --output_markdown --read_cache build_status.cache --report=test_summary --summary_count=${{ env.numTestsSummary }} > test_summary.md
59-
python3 firebase-cpp-sdk/scripts/gha/report_build_status.py --token ${{ github.token }} --days ${{ env.numDays }} --nooutput_header --read_cache build_status_short.cache > report.txt
61+
python3 scripts/gha/report_build_status.py --token ${{ github.token }} --days ${{ env.numDays }} --output_markdown --read_cache build_status_short.cache > report_short.md
62+
python3 scripts/gha/report_build_status.py --token ${{ github.token }} --days ${{ env.numDaysExtended }} --output_markdown --read_cache build_status.cache > report_extended.md
63+
python3 scripts/gha/report_build_status.py --token ${{ github.token }} --days ${{ env.numDaysExtended }} --output_markdown --read_cache build_status.cache --report=test_summary --summary_count=${{ env.numTestsSummary }} > test_summary.md
64+
python3 scripts/gha/report_build_status.py --token ${{ github.token }} --days ${{ env.numDays }} --nooutput_header --read_cache build_status_short.cache > report.txt
6065
- name: Generate comment string
6166
run: |
6267
echo -n > comment.md
@@ -95,4 +100,4 @@ jobs:
95100
timeout_minutes: 5
96101
max_attempts: 3
97102
shell: bash
98-
command: python3 firebase-cpp-sdk/scripts/gha/update_issue_comment.py --token ${{ github.token }} --issue_title '[Unity] Nightly Integration Testing Report' --start_tag build-dashboard-comment-start --end_tag build-dashboard-comment-end < comment.md
103+
command: python3 scripts/gha/update_issue_comment.py --token ${{ github.token }} --issue_title '[Unity] Nightly Integration Testing Report' --start_tag build-dashboard-comment-start --end_tag build-dashboard-comment-end < comment.md

.github/workflows/build_android.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ jobs:
5050
with:
5151
submodules: true
5252
ref: ${{ inputs.unity_branch }}
53+
fetch-depth: 0
5354

5455
- name: Checkout CPP Repo
5556
uses: actions/checkout@v3
@@ -58,6 +59,7 @@ jobs:
5859
path: firebase-cpp-sdk
5960
ref: ${{ inputs.firebase_cpp_sdk_version }}
6061
submodules: true
62+
fetch-depth: 0
6163

6264
- name: Setup python
6365
uses: actions/setup-python@v4

.github/workflows/build_ios.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ jobs:
5151
with:
5252
submodules: true
5353
ref: ${{ inputs.unity_branch }}
54+
fetch-depth: 0
5455

5556
- name: Checkout CPP Repo
5657
uses: actions/checkout@v3
@@ -59,6 +60,7 @@ jobs:
5960
path: firebase-cpp-sdk
6061
ref: ${{ inputs.firebase_cpp_sdk_version }}
6162
submodules: true
63+
fetch-depth: 0
6264

6365
- name: Setup python
6466
uses: actions/setup-python@v4

.github/workflows/build_linux.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,15 @@ jobs:
4747
with:
4848
submodules: true
4949
ref: ${{ inputs.unity_branch }}
50+
fetch-depth: 0
5051

5152
- uses: actions/checkout@v3
5253
with:
5354
repository: firebase/firebase-cpp-sdk
5455
path: firebase-cpp-sdk
5556
submodules: true
5657
ref: ${{ inputs.firebase_cpp_sdk_version }}
58+
fetch-depth: 0
5759

5860
- name: Setup python
5961
uses: actions/setup-python@v4

.github/workflows/build_macos.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,15 @@ jobs:
4747
with:
4848
submodules: true
4949
ref: ${{ inputs.unity_branch }}
50+
fetch-depth: 0
5051

5152
- uses: actions/checkout@v3
5253
with:
5354
repository: firebase/firebase-cpp-sdk
5455
path: firebase-cpp-sdk
5556
submodules: true
5657
ref: ${{ inputs.firebase_cpp_sdk_version }}
58+
fetch-depth: 0
5759

5860
# Remove other python installs before installing the version we want
5961
- name: Remove other pythons

.github/workflows/build_tvos.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ jobs:
7272
with:
7373
submodules: true
7474
ref: ${{ inputs.unity_branch }}
75+
fetch-depth: 0
7576

7677
- name: Checkout CPP Repo
7778
uses: actions/checkout@v3
@@ -80,6 +81,7 @@ jobs:
8081
path: firebase-cpp-sdk
8182
ref: ${{ inputs.firebase_cpp_sdk_version }}
8283
submodules: true
84+
fetch-depth: 0
8385

8486
- name: Setup python
8587
uses: actions/setup-python@v4

.github/workflows/build_windows.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,15 @@ jobs:
4747
with:
4848
submodules: true
4949
ref: ${{ inputs.unity_branch }}
50+
fetch-depth: 0
5051

5152
- uses: actions/checkout@v3
5253
with:
5354
repository: firebase/firebase-cpp-sdk
5455
path: firebase-cpp-sdk
5556
submodules: true
5657
ref: ${{ inputs.firebase_cpp_sdk_version }}
58+
fetch-depth: 0
5759

5860
- name: Support longpaths
5961
run: git config --system core.longpaths true

.github/workflows/integration_tests.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ jobs:
6161
### trigger value: manual_trigger, scheduled_trigger, label_trigger, postsubmit_trigger
6262
- id: set_outputs
6363
run: |
64+
if [[ "${{ github.event.inputs.packaged_sdk_run_id }}" != "" ]]; then
65+
echo "::warning ::Downloading SDK package from previous run: https://github.com/${{github.repository}}/actions/runs/${{ github.event.inputs.packaged_sdk_run_id }}"
66+
fi
6467
if [[ "${{ github.event.inputs.test_pull_request }}" == *"label-quick-packaging" ]]; then
6568
# Triggered by build_starter SDK workflow.
6669
echo "trigger=label_trigger" >> $GITHUB_OUTPUT

scripts/gha/firebase_github.py

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
BACKOFF = 5
3232
RETRY_STATUS = (403, 500, 502, 504)
3333
TIMEOUT = 5
34+
TIMEOUT_LONG = 20
3435

3536
OWNER = 'firebase'
3637
REPO = 'firebase-unity-sdk'
@@ -40,7 +41,7 @@
4041
logging.set_verbosity(logging.INFO)
4142

4243

43-
def set_repo_url(repo):
44+
def set_repo_url(repo):
4445
match = re.match(r'https://github\.com/([^/]+)/([^/.]+)', repo)
4546
if not match:
4647
logging.info('Error, only pattern https://github.com/\{repo_owner\}/\{repo_name\} are allowed.')
@@ -178,14 +179,18 @@ def list_artifacts(token, run_id):
178179
return response.json()["artifacts"]
179180

180181

181-
def download_artifact(token, artifact_id, output_path):
182+
def download_artifact(token, artifact_id, output_path=None):
182183
"""https://docs.github.com/en/rest/reference/actions#download-an-artifact"""
183184
url = f'{GITHUB_API_URL}/actions/artifacts/{artifact_id}/zip'
184185
headers = {'Accept': 'application/vnd.github.v3+json', 'Authorization': f'token {token}'}
185-
with requests.get(url, headers=headers, stream=True, timeout=TIMEOUT) as response:
186+
with requests_retry_session().get(url, headers=headers, stream=True, timeout=TIMEOUT_LONG) as response:
186187
logging.info("download_artifact: %s response: %s", url, response)
187-
with open(output_path, 'wb') as file:
188-
shutil.copyfileobj(response.raw, file)
188+
if output_path:
189+
with open(output_path, 'wb') as file:
190+
shutil.copyfileobj(response.raw, file)
191+
elif response.status_code == 200:
192+
return response.content
193+
return None
189194

190195

191196
def dismiss_review(token, pull_number, review_id, message):
@@ -238,7 +243,7 @@ def list_workflows(token, workflow_id, branch):
238243
headers = {'Accept': 'application/vnd.github.v3+json', 'Authorization': f'token {token}'}
239244
data = {'event': 'workflow_dispatch', 'branch': branch}
240245
with requests.get(url, headers=headers, data=json.dumps(data),
241-
stream=True, timeout=TIMEOUT) as response:
246+
stream=True, timeout=TIMEOUT_LONG) as response:
242247
logging.info("list_workflows: %s response: %s", url, response)
243248
return response.json()
244249

@@ -272,9 +277,36 @@ def list_pull_requests(token, state, head, base):
272277
keep_going = False
273278
with requests_retry_session().get(url, headers=headers, params=params,
274279
stream=True, timeout=TIMEOUT) as response:
275-
logging.info("get_reviews: %s response: %s", url, response)
280+
logging.info("list_pull_requests: %s response: %s", url, response)
276281
results = results + response.json()
277282
# If exactly per_page results were retrieved, read the next page.
278283
keep_going = (len(response.json()) == per_page)
279284
return results
280285

286+
def list_workflow_runs(token, workflow_id, branch=None, event=None, limit=200):
287+
"""https://docs.github.com/en/rest/actions/workflow-runs?list-workflow-runs-for-a-required-workflow"""
288+
url = f'{GITHUB_API_URL}/actions/workflows/{workflow_id}/runs'
289+
headers = {'Accept': 'application/vnd.github.v3+json', 'Authorization': f'token {token}'}
290+
page = 1
291+
per_page = 100
292+
results = []
293+
keep_going = True
294+
while keep_going:
295+
params = {'per_page': per_page, 'page': page}
296+
if branch: params.update({'branch': branch})
297+
if event: params.update({'event': event})
298+
page = page + 1
299+
keep_going = False
300+
with requests_retry_session().get(url, headers=headers, params=params,
301+
stream=True, timeout=TIMEOUT) as response:
302+
logging.info("list_workflow_runs: %s page %d, response: %s", url, params['page'], response)
303+
if 'workflow_runs' not in response.json():
304+
break
305+
run_list_results = response.json()['workflow_runs']
306+
results = results + run_list_results
307+
# If exactly per_page results were retrieved, read the next page.
308+
keep_going = (len(run_list_results) == per_page)
309+
if limit > 0 and len(results) >= limit:
310+
keep_going = False
311+
results = results[:limit]
312+
return results

scripts/gha/it_workflow.py

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444

4545
from absl import app
4646
from absl import flags
47+
from absl import logging
4748

4849
import firebase_github
4950
import summarize_test_results as summarize
@@ -65,7 +66,11 @@
6566
_COMMENT_TITLE_SUCCEED = "### ✅&nbsp; Integration test succeeded!\n"
6667

6768
_COMMENT_IDENTIFIER = "integration-test-status-comment"
68-
_COMMENT_SUFFIX = f'\n<hidden value="{_COMMENT_IDENTIFIER}"></hidden>'
69+
_COMMENT_HIDDEN_DIVIDER = f'\r\n<hidden value="{_COMMENT_IDENTIFIER}"></hidden>\r\n'
70+
71+
_COMMENT_IDENTIFIER_DASHBOARD = "build-dashboard-comment"
72+
_COMMENT_DASHBOARD_START = f'\r\n<hidden value="{_COMMENT_IDENTIFIER_DASHBOARD}-start"></hidden>\r\n'
73+
_COMMENT_DASHBOARD_END = f'\r\n<hidden value="{_COMMENT_IDENTIFIER_DASHBOARD}-end"></hidden>\r\n'
6974

7075
_LOG_ARTIFACT_NAME = "log-artifact"
7176
_LOG_OUTPUT_DIR = "test_results"
@@ -116,7 +121,7 @@ def test_start(token, issue_number, actor, commit, run_id):
116121

117122
comment = (_COMMENT_TITLE_PROGESS +
118123
_get_description(actor, commit, run_id) +
119-
_COMMENT_SUFFIX)
124+
_COMMENT_HIDDEN_DIVIDER)
120125
_update_comment(token, issue_number, comment)
121126

122127

@@ -138,7 +143,7 @@ def test_progress(token, issue_number, actor, commit, run_id):
138143
comment = (title +
139144
_get_description(actor, commit, run_id) +
140145
log_summary +
141-
_COMMENT_SUFFIX)
146+
_COMMENT_HIDDEN_DIVIDER)
142147
_update_comment(token, issue_number, comment)
143148

144149

@@ -152,7 +157,7 @@ def test_end(token, issue_number, actor, commit, run_id, new_token):
152157
firebase_github.add_label(token, issue_number, _LABEL_SUCCEED)
153158
comment = (_COMMENT_TITLE_SUCCEED +
154159
_get_description(actor, commit, run_id) +
155-
_COMMENT_SUFFIX)
160+
_COMMENT_HIDDEN_DIVIDER)
156161
_update_comment(token, issue_number, comment)
157162
else:
158163
if success_or_only_flakiness:
@@ -166,7 +171,7 @@ def test_end(token, issue_number, actor, commit, run_id, new_token):
166171
comment = (title +
167172
_get_description(actor, commit, run_id) +
168173
log_summary +
169-
_COMMENT_SUFFIX)
174+
_COMMENT_HIDDEN_DIVIDER)
170175
_update_comment(token, issue_number, comment)
171176

172177
firebase_github.delete_label(new_token, issue_number, _LABEL_PROGRESS)
@@ -178,18 +183,34 @@ def test_report(token, actor, commit, run_id):
178183
https://github.com/firebase/firebase-unity-sdk/issues?q=is%3Aissue+label%3Anightly-testing
179184
"""
180185
issue_number = _get_issue_number(token, _REPORT_TITLE, _REPORT_LABEL)
186+
previous_comment = firebase_github.get_issue_body(token, issue_number)
187+
[previous_prefix, previous_comment_test_result] = previous_comment.split(_COMMENT_HIDDEN_DIVIDER) # TODO add more content
188+
logging.info("Previous prefix: %s", previous_prefix)
189+
# If there is a build dashboard, preserve it.
190+
if (_COMMENT_DASHBOARD_START in previous_prefix and
191+
_COMMENT_DASHBOARD_END in previous_prefix):
192+
logging.info("Found dashboard comment, preserving.")
193+
[_, previous_dashboard_plus_the_rest] = previous_prefix.split(_COMMENT_DASHBOARD_START)
194+
[previous_dashboard, _] = previous_dashboard_plus_the_rest.split(_COMMENT_DASHBOARD_END)
195+
prefix = prefix + _COMMENT_DASHBOARD_START + previous_dashboard + _COMMENT_DASHBOARD_END
196+
logging.info("New prefix: %s", prefix)
197+
else:
198+
logging.info("No dashboard comment '%s' or '%s'", _COMMENT_DASHBOARD_START, _COMMENT_DASHBOARD_END)
199+
181200
success_or_only_flakiness, log_summary = _get_summary_table(token, run_id)
182201
if success_or_only_flakiness:
183202
if not log_summary:
184203
# succeeded (without flakiness)
185204
title = _COMMENT_TITLE_SUCCEED
186-
comment = title + _get_description(actor, commit, run_id)
205+
test_result = title + _get_description(actor, commit, run_id)
187206
else:
188207
title = _COMMENT_TITLE_FLAKY
189-
comment = title + _get_description(actor, commit, run_id) + log_summary
208+
test_result = title + _get_description(actor, commit, run_id) + log_summary
190209
else:
191210
title = _COMMENT_TITLE_FAIL
192-
comment = title + _get_description(actor, commit, run_id) + log_summary
211+
test_result = title + _get_description(actor, commit, run_id) + log_summary
212+
213+
comment = prefix + _COMMENT_HIDDEN_DIVIDER + test_result
193214

194215
if title == _COMMENT_TITLE_SUCCEED:
195216
firebase_github.close_issue(token, issue_number)

0 commit comments

Comments
 (0)