Skip to content

Commit e61d0b8

Browse files
authored
Tests against packaged SDK added to Nightly Test Report
1 parent b232cfe commit e61d0b8

File tree

4 files changed

+72
-30
lines changed

4 files changed

+72
-30
lines changed

.github/workflows/cpp-packaging.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -720,9 +720,13 @@ jobs:
720720
if [[ -z ${USE_EXPANDED_MATRIX} ]]; then
721721
USE_EXPANDED_MATRIX=0
722722
fi
723+
if [[ "${{ github.event_name }}" == "schedule" ]]; then
724+
# reuse flag --test_pull_request=sdk to generate report
725+
generate_report=(-p test_pull_request sdk)
726+
fi
723727
verbose_flag=
724728
if [[ -n "${{ github.event.inputs.verboseBuild }}" && "${{ github.event.inputs.verboseBuild }}" -ne 0 ]]; then
725729
verbose_flag=-v
726730
fi
727731
set -e
728-
python scripts/gha/trigger_workflow.py -t ${{ steps.generate-token.outputs.token }} -w integration_tests.yml -p test_packaged_sdk ${{ github.run_id }} -p use_expanded_matrix ${USE_EXPANDED_MATRIX} -s 10 -A ${verbose_flag}
732+
python scripts/gha/trigger_workflow.py -t ${{ steps.generate-token.outputs.token }} -w integration_tests.yml -p test_packaged_sdk ${{ github.run_id }} -p use_expanded_matrix ${USE_EXPANDED_MATRIX} ${generate_report[*]} -s 10 -A ${verbose_flag}

.github/workflows/integration_tests.yml

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ jobs:
5858
### subsequent steps to update the labels as well.
5959
runs-on: ubuntu-latest
6060
if: |
61-
github.event_name == 'pull_request' || github.event.inputs.test_pull_request != ''
61+
github.event_name == 'pull_request' || (github.event.inputs.test_pull_request != '' && github.event.inputs.test_pull_request != 'sdk')
6262
outputs:
6363
should_update_pr: ${{ steps.set_outputs.outputs.should_update_pr }}
6464
requested_tests: ${{ steps.set_outputs.outputs.requested_tests }}
@@ -166,7 +166,7 @@ jobs:
166166
if: needs.check_trigger.outputs.requested_tests == 'auto'
167167
run: |
168168
echo "Autodetecting which tests to run."
169-
if [[ -n "${{github.event.inputs.test_pull_request}}" ]]; then
169+
if [[ -n "${{github.event.inputs.test_pull_request}}" || "${{github.event.inputs.test_pull_request}}" == "sdk" ]]; then
170170
# If running this manually, diff against our common ancestor with main.
171171
MERGE_BASE=$(git merge-base HEAD origin/main)
172172
echo "::warning ::Auto-diff HEAD..${MERGE_BASE}"
@@ -203,7 +203,7 @@ jobs:
203203
echo "::set-output name=android_device::$( python scripts/gha/print_matrix_configuration.py -w integration_tests ${EXPANDED_MATRIX_PARAM} -k android_device -t ${mobile_test_on} )"
204204
echo "::set-output name=ios_device::$( python scripts/gha/print_matrix_configuration.py -w integration_tests ${EXPANDED_MATRIX_PARAM} -k ios_device -t ${mobile_test_on} )"
205205
echo "::set-output name=tvos_device::$( python scripts/gha/print_matrix_configuration.py -w integration_tests ${EXPANDED_MATRIX_PARAM} -k tvos_device -t ${mobile_test_on} )"
206-
if [[ -z "${{github.event.inputs.test_pull_request}}" ]]; then
206+
if [[ -z "${{github.event.inputs.test_pull_request}}" || "${{github.event.inputs.test_pull_request}}" == "sdk" ]]; then
207207
echo "::warning ::Running on https://github.com/${{github.repository}}/commits/$GITHUB_SHA"
208208
echo "::set-output name=github_ref::$GITHUB_SHA"
209209
elif [[ "${{github.event.inputs.test_pull_request}}" == *:* ]]; then
@@ -1062,12 +1062,19 @@ jobs:
10621062
--run_id ${{github.run_id}} \
10631063
--new_token ${{steps.generate-token.outputs.token}}
10641064
- name: Update Daily Report
1065-
if: ${{ github.event_name == 'schedule' }}
1065+
if: ${{ github.event_name == 'schedule' || github.event.inputs.test_pull_request == 'sdk'}}
1066+
shell: bash
10661067
run: |
1068+
if [[ "${{ github.event.inputs.test_pull_request }}" == "sdk" ]]; then
1069+
additional_flags=(--build_against sdk)
1070+
else
1071+
additional_flags=(--build_against repo)
1072+
fi
10671073
python scripts/gha/it_workflow.py --stage report \
10681074
--token ${{github.token}} \
10691075
--actor ${{github.actor}} \
10701076
--commit ${{needs.prepare_matrix.outputs.github_ref}} \
1071-
--run_id ${{github.run_id}}
1077+
--run_id ${{github.run_id}} \
1078+
${additional_flags[*]}
10721079
- name: Summarize results into GitHub log
10731080
run: python scripts/gha/summarize_test_results.py --dir test_results --github_log

scripts/gha/github.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,25 @@ def requests_retry_session(retries=RETRIES,
5252
session.mount('https://', adapter)
5353
return session
5454

55-
def create_issue(token, title, label):
55+
def create_issue(token, title, label, body):
5656
"""Create an issue: https://docs.github.com/en/rest/reference/issues#create-an-issue"""
5757
url = f'{FIREBASE_URL}/issues'
5858
headers = {'Accept': 'application/vnd.github.v3+json', 'Authorization': f'token {token}'}
59-
data = {'title': title, 'labels': [label]}
59+
data = {'title': title, 'labels': [label], 'body': body}
6060
with requests.post(url, headers=headers, data=json.dumps(data), timeout=TIMEOUT) as response:
6161
logging.info("create_issue: %s response: %s", url, response)
6262
return response.json()
6363

6464

65+
def get_issue_body(token, issue_number):
66+
"""https://docs.github.com/en/rest/reference/issues#get-an-issue-comment"""
67+
url = f'{FIREBASE_URL}/issues/{issue_number}'
68+
headers = {'Accept': 'application/vnd.github.v3+json', 'Authorization': f'token {token}'}
69+
with requests_retry_session().get(url, headers=headers, timeout=TIMEOUT) as response:
70+
logging.info("get_issue_body: %s response: %s", url, response)
71+
return response.json()["body"]
72+
73+
6574
def update_issue(token, issue_number, data):
6675
"""Update an issue: https://docs.github.com/en/rest/reference/issues#update-an-issue"""
6776
url = f'{FIREBASE_URL}/issues/{issue_number}'
@@ -192,3 +201,13 @@ def get_reviews(token, pull_number):
192201
# If exactly per_page results were retrieved, read the next page.
193202
keep_going = (len(response.json()) == per_page)
194203
return results
204+
205+
206+
def workflow_dispatch(token, workflow_id, ref, inputs):
207+
"""https://docs.github.com/en/rest/reference/actions#create-a-workflow-dispatch-event"""
208+
url = f'{FIREBASE_URL}/actions/workflows/{workflow_id}/dispatches'
209+
headers = {'Accept': 'application/vnd.github.v3+json', 'Authorization': f'token {token}'}
210+
data = {'ref': ref, 'inputs': inputs}
211+
with requests.post(url, headers=headers, data=json.dumps(data),
212+
stream=True, timeout=TIMEOUT) as response:
213+
logging.info("workflow_dispatch: %s response: %s", url, response)

scripts/gha/it_workflow.py

Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,15 @@
6161
_COMMENT_TITLE_PROGESS_FAIL = "### ❌  Integration test FAILED (but still ⏳  in progress)\n"
6262
_COMMENT_TITLE_FAIL = "### ❌  Integration test FAILED\n"
6363
_COMMENT_TITLE_SUCCEED = "### ✅  Integration test succeeded!\n"
64+
_COMMENT_TITLE_FAIL_SDK = "\n***\n### ❌  Integration test FAILED (build against SDK)\n"
65+
_COMMENT_TITLE_SUCCEED_SDK = "\n***\n### ✅  Integration test succeeded! (build against SDK)\n"
66+
_COMMENT_TITLE_FAIL_REPO = "### ❌  Integration test FAILED (build against repo)\n"
67+
_COMMENT_TITLE_SUCCEED_REPO = "### ✅  Integration test succeeded! (build against repo)\n"
6468

6569
_COMMENT_FLAKY_TRACKER = "\n\nAdd flaky tests to **[go/fpl-cpp-flake-tracker](http://go/fpl-cpp-flake-tracker)**\n"
6670

6771
_COMMENT_IDENTIFIER = "integration-test-status-comment"
68-
_COMMENT_SUFFIX = f'\n\n\n<hidden value="{_COMMENT_IDENTIFIER}"></hidden>'
72+
_COMMENT_SUFFIX = f'\n<hidden value="{_COMMENT_IDENTIFIER}"></hidden>'
6973

7074
_LOG_ARTIFACT_NAME = "log-artifact"
7175
_LOG_OUTPUT_DIR = "test_results"
@@ -76,6 +80,9 @@
7680
_BUILD_STAGES_REPORT = "report"
7781
_BUILD_STAGES = [_BUILD_STAGES_START, _BUILD_STAGES_PROGRESS, _BUILD_STAGES_END, _BUILD_STAGES_REPORT]
7882

83+
_BUILD_AGAINST_SDK = "sdk"
84+
_BUILD_AGAINST_REPO = "repo"
85+
7986
FLAGS = flags.FLAGS
8087

8188
flags.DEFINE_string(
@@ -105,7 +112,12 @@
105112
"new_token", None,
106113
"Only used with --stage end"
107114
"Use a different token to remove the \"in-progress\" label,"
108-
"to allow the removal to trigger the \"Check Labels\" workflow.")
115+
"to allow the removal to trigger the \"Check Labels\" workflow.")
116+
117+
flags.DEFINE_string(
118+
"build_against", None,
119+
"Integration testapps could either build against packaged SDK or repo")
120+
109121

110122
def test_start(token, issue_number, actor, commit, run_id):
111123
"""In PR, when start testing, add comment and label \"tests: in-progress\""""
@@ -158,33 +170,33 @@ def test_end(token, issue_number, actor, commit, run_id, new_token):
158170
github.delete_label(new_token, issue_number, _LABEL_PROGRESS)
159171

160172

161-
def test_report(token, actor, commit, run_id):
173+
def test_report(token, actor, commit, run_id, build_against):
162174
"""Update (create if not exist) a Daily Report in Issue.
163-
If test failed, add label \"tests: failed\" and open the Issue,
164-
If test succeed, add label \"tests: succeeded\" and close the Issue.
165175
The Issue with title _REPORT_TITLE and label _REPORT_LABEL:
166-
https://github.com/firebase/firebase-cpp-sdk/issues?q=is%3Aissue+is%3Aclosed+label%3Anightly-testing
176+
https://github.com/firebase/firebase-cpp-sdk/issues?q=is%3Aissue+label%3Anightly-testing
167177
"""
168178
issue_number = _get_issue_number(token, _REPORT_TITLE, _REPORT_LABEL)
179+
previous_comment = github.get_issue_body(token, issue_number)
180+
[previous_comment_repo, previous_comment_sdk] = previous_comment.split(_COMMENT_SUFFIX)
169181
log_summary = _get_summary_talbe(token, run_id)
170182
if log_summary == 0:
171-
# github.delete_label(token, issue_number, _LABEL_FAILED)
172-
# github.add_label(token, issue_number, _LABEL_SUCCEED)
183+
title = _COMMENT_TITLE_SUCCEED_REPO if build_against==_BUILD_AGAINST_REPO else _COMMENT_TITLE_SUCCEED_SDK
184+
comment = title + _get_description(actor, commit, run_id)
185+
else:
186+
title = _COMMENT_TITLE_FAIL_REPO if build_against==_BUILD_AGAINST_REPO else _COMMENT_TITLE_FAIL_SDK
187+
comment = title + _get_description(actor, commit, run_id) + log_summary + _COMMENT_FLAKY_TRACKER
188+
189+
if build_against==_BUILD_AGAINST_REPO:
190+
comment = comment + _COMMENT_SUFFIX + previous_comment_sdk
191+
else:
192+
comment = previous_comment_repo + _COMMENT_SUFFIX + comment
193+
194+
if (_COMMENT_TITLE_SUCCEED_REPO in comment) and (_COMMENT_TITLE_SUCCEED_SDK in comment):
173195
github.close_issue(token, issue_number)
174-
comment = (_COMMENT_TITLE_SUCCEED +
175-
_get_description(actor, commit, run_id) +
176-
_COMMENT_SUFFIX)
177-
github.update_issue_comment(token, issue_number, comment)
178196
else:
179-
# github.delete_label(token, issue_number, _LABEL_SUCCEED)
180-
# github.add_label(token, issue_number, _LABEL_FAILED)
181197
github.open_issue(token, issue_number)
182-
comment = (_COMMENT_TITLE_FAIL +
183-
_get_description(actor, commit, run_id) +
184-
log_summary +
185-
_COMMENT_FLAKY_TRACKER +
186-
_COMMENT_SUFFIX)
187-
github.update_issue_comment(token, issue_number, comment)
198+
199+
github.update_issue_comment(token, issue_number, comment)
188200

189201

190202
def _get_issue_number(token, title, label):
@@ -193,7 +205,7 @@ def _get_issue_number(token, title, label):
193205
if issue["title"] == title:
194206
return issue["number"]
195207

196-
return github.create_issue(token, title, label)["number"]
208+
return github.create_issue(token, title, label, _COMMENT_SUFFIX)["number"]
197209

198210

199211
def _update_comment(token, issue_number, comment):
@@ -255,7 +267,7 @@ def main(argv):
255267
elif FLAGS.stage == _BUILD_STAGES_END:
256268
test_end(FLAGS.token, FLAGS.issue_number, FLAGS.actor, FLAGS.commit, FLAGS.run_id, FLAGS.new_token)
257269
elif FLAGS.stage == _BUILD_STAGES_REPORT:
258-
test_report(FLAGS.token, FLAGS.actor, FLAGS.commit, FLAGS.run_id)
270+
test_report(FLAGS.token, FLAGS.actor, FLAGS.commit, FLAGS.run_id, FLAGS.build_against)
259271
else:
260272
print("Invalid stage value. Valid value: " + ",".join(_BUILD_STAGES))
261273

0 commit comments

Comments
 (0)