-
Notifications
You must be signed in to change notification settings - Fork 2k
Split Python tests to reduce run time #8419
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
Open
pdabelf5
wants to merge
15
commits into
main
Choose a base branch
from
chore/policy-tests
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
259573a
Split Python policies tests
pdabelf5 dd95c63
Merge branch 'main' into chore/policy-tests
pdabelf5 41d7ff1
Split TS plus tests & VS OSS certmanager tests
pdabelf5 603dd4e
Merge branch 'main' into chore/policy-tests
pdabelf5 19815a3
re-shuffle tests
pdabelf5 7809578
Adjust rate limit test job
pdabelf5 d226f07
Split plus certmanager tests
pdabelf5 f19408a
Merge branch 'main' into chore/policy-tests
pdabelf5 34c2428
Update tests/scripts/longest_test_job.py
pdabelf5 51c8b1e
Merge branch 'main' into chore/policy-tests
pdabelf5 c10a7a4
address copilot feedback
pdabelf5 7eea260
Merge branch 'main' into chore/policy-tests
pdabelf5 5615898
Merge branch 'main' into chore/policy-tests
pdabelf5 ff2f99b
Merge branch 'main' into chore/policy-tests
pdabelf5 f2ea2dc
Merge branch 'main' into chore/policy-tests
pdabelf5 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,90 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import argparse | ||
|
||
from github import Auth, Github | ||
|
||
# parse args | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument("-t", "--token", required=True, help="GitHub access token") | ||
parser.add_argument("-o", "--owner", required=False, default="nginx", help="GitHub repository owner") | ||
parser.add_argument("-r", "--repo", help="GitHub repository name", required=False, default="kubernetes-ingress") | ||
parser.add_argument("-w", "--workflow", help="GitHub Actions workflow name", required=False, default="CI") | ||
parser.add_argument("-b", "--branch", help="GitHub repository branch", required=False, default="main") | ||
parser.add_argument( | ||
"-d", "--duration", help="Minimum duration of jobs in seconds", required=False, default=900, type=int | ||
) | ||
args = parser.parse_args() | ||
TOKEN = args.token | ||
OWNER = args.owner | ||
REPO = args.repo | ||
BRANCH = args.branch | ||
DURATION = args.duration | ||
WORKFLOW = args.workflow | ||
|
||
|
||
def get_github_handle(token): | ||
# Authenticate to GitHub | ||
auth = Auth.Token(token) | ||
g = Github(auth=auth) | ||
if g is None: | ||
return None | ||
return g | ||
|
||
|
||
def get_github_repo(owner, repo, handle): | ||
# Get the repository | ||
repository = handle.get_repo(f"{owner}/{repo}") | ||
return repository | ||
|
||
|
||
def get_workflow_runs(repo, workflow_name, branch=None): | ||
workflows = repo.get_workflows() | ||
for workflow in workflows: | ||
if workflow.name == workflow_name: | ||
return workflow.get_runs(branch=branch, status="completed") | ||
return None | ||
|
||
|
||
def get_run_branch_jobs(runs): | ||
results = {} | ||
for run in runs: | ||
results[run.id] = run.jobs() | ||
return results | ||
|
||
|
||
def get_run_durations(runs): | ||
results = {} | ||
for run in runs: | ||
results[run.id] = run.timing().run_duration_ms / 1000 | ||
pdabelf5 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return results | ||
|
||
|
||
def convert_seconds(seconds): | ||
minutes, remaining_seconds = divmod(seconds, 60) | ||
hour, minutes = divmod(minutes, 60) | ||
return "%d:%02d:%02d" % (hour, minutes, remaining_seconds) | ||
|
||
|
||
g = get_github_handle(TOKEN) | ||
if g is None: | ||
print("Failed to authenticate to GitHub") | ||
exit(1) | ||
r = get_github_repo(OWNER, REPO, g) | ||
|
||
# Get the latest workflow runs | ||
runs = get_workflow_runs(r, WORKFLOW, branch=BRANCH) | ||
if not runs: | ||
print("No workflow runs found.") | ||
exit(1) | ||
wj = get_run_branch_jobs(runs) | ||
wd = get_run_durations(runs) | ||
for run_id in sorted(wj.keys()): | ||
duration = wd.get(run_id) | ||
print(f"Workflow Run ID: {run_id}, Duration: {convert_seconds(duration)}") | ||
for job in wj[run_id]: | ||
job_duration = (job.completed_at - job.started_at).total_seconds() | ||
if job.status == "completed" and job.conclusion == "success" and job_duration > DURATION: | ||
print(f" Job: {job.name}, Duration: {convert_seconds(job_duration)}, URL: {job.html_url}") | ||
|
||
g.close() |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
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.
Uh oh!
There was an error while loading. Please reload this page.