-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Retry test failures on Unity #1028
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
35bb3f9
Add retry workflow
jonsimantov 60f48db
Add script for retrying tests under any conditions.
jonsimantov c1c9e7c
Add to integration test workflow (currently unconditional, will chang…
jonsimantov 304d865
Temporarily enable retry on cancelled workflow.
jonsimantov 56d2b70
Fix script.
jonsimantov e7c9ca3
Duplicate the C++ trigger workflow script.
jonsimantov 80a1650
Make sure to revert this, set the branch for triggering the test.
jonsimantov f5212fc
Spacing.
jonsimantov 4134768
Test with a forced-failing test.
jonsimantov 9933161
Format.
jonsimantov 5817016
Put the workflow back the way it should be for merging.
jonsimantov 7505cac
Remove unused branch sha check.
jonsimantov f677984
Fix comment.
jonsimantov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
# Copyright 2023 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
"""A utility to retry failed jobs in a workflow run. | ||
|
||
USAGE: | ||
python3 scripts/gha/retry_test_failures.py \ | ||
--token ${{github.token}} \ | ||
--run_id <github_workflow_run_id> | ||
""" | ||
|
||
import datetime | ||
import json | ||
import re | ||
import shutil | ||
|
||
from absl import app | ||
from absl import flags | ||
from absl import logging | ||
|
||
import firebase_github | ||
|
||
FLAGS = flags.FLAGS | ||
MAX_RETRIES=2 | ||
|
||
flags.DEFINE_string( | ||
"token", None, | ||
"github.token: A token to authenticate on your repository.") | ||
|
||
flags.DEFINE_string( | ||
"run_id", None, | ||
"Github's workflow run ID.") | ||
|
||
|
||
def get_log_group(log_text, group_name): | ||
group_log = [] | ||
in_group = False | ||
for line in log_text.split("\n"): | ||
line_no_ts = line[29:] | ||
if line_no_ts.startswith('##[group]'): | ||
if group_name in line_no_ts: | ||
print("got group %s" % group_name) | ||
in_group = True | ||
if in_group: | ||
group_log.append(line_no_ts) | ||
if line_no_ts.startswith('##[error])'): | ||
print("end group %s" % group_name) | ||
in_group = False | ||
break | ||
return group_log | ||
|
||
def main(argv): | ||
if len(argv) > 1: | ||
raise app.UsageError("Too many command-line arguments.") | ||
# Get list of workflow jobs. | ||
workflow_jobs = firebase_github.list_jobs_for_workflow_run( | ||
FLAGS.token, FLAGS.run_id, attempt='all') | ||
if not workflow_jobs or len(workflow_jobs) == 0: | ||
logging.error("No jobs found for workflow run %s", FLAGS.run_id) | ||
exit(1) | ||
|
||
failed_jobs = {} | ||
all_jobs = {} | ||
for job in workflow_jobs: | ||
all_jobs[job['id']] = job | ||
if job['conclusion'] != 'success' and job['conclusion'] != 'skipped': | ||
if job['name'] in failed_jobs: | ||
other_run = failed_jobs[job['name']] | ||
if job['run_attempt'] > other_run['run_attempt']: | ||
# This is a later run than the one that's already there | ||
failed_jobs[job['name']] = job | ||
else: | ||
failed_jobs[job['name']] = job | ||
|
||
should_rerun_jobs = False | ||
for job_name in failed_jobs: | ||
job = failed_jobs[job_name] | ||
logging.info('Considering job %s attempt %d: %s (%s)', | ||
job['conclusion'] if job['conclusion'] else job['status'], | ||
job['run_attempt'], job['name'], job['id']) | ||
if job['status'] != 'completed': | ||
# Don't retry a job that is already in progress or queued | ||
logging.info("Not retrying, as %s is already %s", | ||
job['name'], job['status'].replace("_", " ")) | ||
should_rerun_jobs = False | ||
break | ||
if job['run_attempt'] > MAX_RETRIES: | ||
# Don't retry a job more than MAX_RETRIES times. | ||
logging.info("Not retrying, as %s has already been attempted %d times", | ||
job['name'], job['run_attempt']) | ||
should_rerun_jobs = False | ||
break | ||
if job['conclusion'] == 'failure': | ||
job_logs = firebase_github.download_job_logs(FLAGS.token, job['id']) | ||
if job['name'].startswith('build-'): | ||
# Retry build jobs that timed out | ||
if re.search(r'timed? ?out|network error|maximum execution time', | ||
job_logs, re.IGNORECASE): | ||
should_rerun_jobs = True | ||
elif job['name'].startswith('test-'): | ||
# Tests should always be retried (for now). | ||
should_rerun_jobs = True | ||
|
||
if should_rerun_jobs: | ||
logging.info("Re-running failed jobs in workflow run %s", FLAGS.run_id) | ||
if not firebase_github.rerun_failed_jobs_for_workflow_run( | ||
FLAGS.token, FLAGS.run_id): | ||
logging.error("Error submitting GitHub API request") | ||
exit(1) | ||
else: | ||
logging.info("Not re-running jobs.") | ||
|
||
|
||
if __name__ == "__main__": | ||
flags.mark_flag_as_required("token") | ||
flags.mark_flag_as_required("run_id") | ||
app.run(main) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2024
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Eh, this is mostly a copy of the script from C++ that was written in 2023, should it still be 2024?