2023-01-02 16:57:07 +00:00
|
|
|
#!/usr/bin/env python3
|
2023-07-14 09:57:10 +00:00
|
|
|
|
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
import json
|
|
|
|
import subprocess
|
|
|
|
from typing import Iterable
|
|
|
|
|
2023-01-27 14:13:12 +00:00
|
|
|
import click
|
2023-01-02 16:57:07 +00:00
|
|
|
|
2023-07-14 09:57:10 +00:00
|
|
|
from gitlab import UI_JOB_NAMES, get_branch_ui_fixtures_results, get_jobs_of_interest
|
2023-01-27 14:13:12 +00:00
|
|
|
from ui_tests import update_fixtures
|
2023-07-14 09:57:10 +00:00
|
|
|
from ui_tests.common import FIXTURES_FILE, get_current_fixtures
|
|
|
|
|
|
|
|
|
|
|
|
@click.group()
|
|
|
|
def cli():
|
|
|
|
pass
|
2023-01-02 16:57:07 +00:00
|
|
|
|
|
|
|
|
2023-07-14 09:57:10 +00:00
|
|
|
@cli.command()
|
2023-01-27 14:13:12 +00:00
|
|
|
@click.option("-r", "--remove-missing", is_flag=True, help="Remove missing tests")
|
2023-07-14 09:57:10 +00:00
|
|
|
def local(remove_missing: bool) -> None:
|
|
|
|
"""Update fixtures file with results from latest local test run."""
|
|
|
|
print("Updating from local test run...")
|
2023-01-27 14:13:12 +00:00
|
|
|
changes_amount = update_fixtures(remove_missing)
|
|
|
|
print(f"Updated fixtures.json with data from {changes_amount} tests.")
|
|
|
|
|
|
|
|
|
2023-07-14 09:57:10 +00:00
|
|
|
def _get_current_git_branch() -> str:
|
|
|
|
return (
|
|
|
|
subprocess.check_output(["git", "branch", "--show-current"])
|
|
|
|
.decode("ascii")
|
|
|
|
.strip()
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
@cli.command()
|
|
|
|
@click.option("-b", "--branch", help="Branch name")
|
|
|
|
@click.option(
|
|
|
|
"-o",
|
|
|
|
"--only-jobs",
|
|
|
|
type=click.Choice(UI_JOB_NAMES),
|
|
|
|
help="Job names which to process",
|
|
|
|
multiple=True,
|
|
|
|
)
|
|
|
|
@click.option(
|
|
|
|
"-e",
|
|
|
|
"--exclude-jobs",
|
|
|
|
type=click.Choice(UI_JOB_NAMES),
|
|
|
|
help="Not take these jobs",
|
|
|
|
multiple=True,
|
|
|
|
)
|
|
|
|
def ci(
|
|
|
|
branch: str | None,
|
|
|
|
only_jobs: Iterable[str] | None,
|
|
|
|
exclude_jobs: Iterable[str] | None,
|
|
|
|
) -> None:
|
|
|
|
"""Update fixtures file with results from CI."""
|
|
|
|
print("Updating from CI...")
|
|
|
|
|
|
|
|
if only_jobs and exclude_jobs:
|
|
|
|
raise click.UsageError("Cannot use both --only-jobs and --exclude-jobs")
|
|
|
|
|
|
|
|
if branch is None:
|
|
|
|
branch = _get_current_git_branch()
|
|
|
|
|
|
|
|
print(f"Branch: {branch}")
|
|
|
|
if only_jobs:
|
|
|
|
print(f"Only jobs: {only_jobs}")
|
|
|
|
if exclude_jobs:
|
|
|
|
print(f"Exclude jobs: {exclude_jobs}")
|
|
|
|
|
|
|
|
jobs_of_interest = get_jobs_of_interest(only_jobs, exclude_jobs)
|
|
|
|
ui_results = get_branch_ui_fixtures_results(branch, jobs_of_interest)
|
|
|
|
|
|
|
|
current_fixtures = get_current_fixtures()
|
|
|
|
|
2023-08-09 11:20:43 +00:00
|
|
|
is_error = False
|
2023-07-14 09:57:10 +00:00
|
|
|
differing_total = 0
|
|
|
|
for job_name, ui_res_dict in ui_results.items():
|
|
|
|
print(f"Updating results from {job_name}...")
|
|
|
|
if not ui_res_dict:
|
2023-08-09 11:20:43 +00:00
|
|
|
is_error = True
|
2023-07-14 09:57:10 +00:00
|
|
|
print("No results found.")
|
|
|
|
continue
|
|
|
|
model = next(iter(ui_res_dict.keys()))
|
|
|
|
group = next(iter(ui_res_dict[model].keys()))
|
|
|
|
current_model = current_fixtures.setdefault(model, {})
|
|
|
|
current_group = current_model.setdefault(group, {}) # type: ignore
|
|
|
|
|
|
|
|
differing = 0
|
|
|
|
for test_name, res in ui_res_dict[model][group].items():
|
|
|
|
if current_group.get(test_name) != res:
|
|
|
|
differing += 1
|
|
|
|
current_group[test_name] = res
|
|
|
|
|
|
|
|
print(f"Updated {differing} tests.")
|
|
|
|
differing_total += differing
|
|
|
|
|
|
|
|
print(80 * "-")
|
|
|
|
print(f"Updated {differing_total} tests in total.")
|
|
|
|
|
|
|
|
FIXTURES_FILE.write_text(
|
|
|
|
json.dumps(current_fixtures, indent=0, sort_keys=True) + "\n"
|
|
|
|
)
|
|
|
|
print("Updated fixtures.json with data from CI.")
|
2023-08-09 11:20:43 +00:00
|
|
|
if is_error:
|
|
|
|
print(80 * "-")
|
|
|
|
raise click.ClickException("Some jobs did not have any results.")
|
2023-07-14 09:57:10 +00:00
|
|
|
|
|
|
|
|
2023-01-27 14:13:12 +00:00
|
|
|
if __name__ == "__main__":
|
2023-07-14 09:57:10 +00:00
|
|
|
cli()
|