-
Notifications
You must be signed in to change notification settings - Fork 10
fedora-review: allow skipping checks #34
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -9,6 +9,10 @@ | |||||||||||||||||||||||||||||
| from enum import Enum | ||||||||||||||||||||||||||||||
| import json | ||||||||||||||||||||||||||||||
| import yaml | ||||||||||||||||||||||||||||||
| import utils | ||||||||||||||||||||||||||||||
| import tomli_w | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| CI_CONFIG_SECTION = "fedora-review" | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| # Expose these to the users | ||||||||||||||||||||||||||||||
| FEDORA_REVIEW_RESULTS = [ | ||||||||||||||||||||||||||||||
|
|
@@ -27,7 +31,7 @@ class Result(Enum): | |||||||||||||||||||||||||||||
| PASS = "pass" | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| def dump_results_yaml(issues: int): | ||||||||||||||||||||||||||||||
| def dump_results_yaml(issues: int, skipped: int): | ||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||
| https://tmt.readthedocs.io/en/stable/spec/results.html | ||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||
|
|
@@ -36,8 +40,11 @@ def dump_results_yaml(issues: int): | |||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||
| "name": "/", | ||||||||||||||||||||||||||||||
| "result": result.value, | ||||||||||||||||||||||||||||||
| "note": [f"{issues} issues"], | ||||||||||||||||||||||||||||||
| "log": ["viewer.html"] + FEDORA_REVIEW_RESULTS, | ||||||||||||||||||||||||||||||
| "note": [ | ||||||||||||||||||||||||||||||
| f"{skipped} skipped", | ||||||||||||||||||||||||||||||
| f"{issues} issues", | ||||||||||||||||||||||||||||||
| ], | ||||||||||||||||||||||||||||||
| "log": ["viewer.html", "fedora-review.toml"] + FEDORA_REVIEW_RESULTS, | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
| ] | ||||||||||||||||||||||||||||||
| path = os.path.join(os.environ.get("TMT_TEST_DATA"), "results.yaml") | ||||||||||||||||||||||||||||||
|
|
@@ -72,20 +79,17 @@ def copy_viewer_html(): | |||||||||||||||||||||||||||||
| shutil.copy(viewer, Path(os.environ["TMT_TEST_DATA"]) / viewer) | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| def copy_data_into_data(): | ||||||||||||||||||||||||||||||
| def copy_mock_fedora_ci_toml(): | ||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||
| There is a weird bug that we discovered with @LecrisUT. For some reason, | ||||||||||||||||||||||||||||||
| when a plan has `result: custom`, the `viewer.html` stops rendering in | ||||||||||||||||||||||||||||||
| Testing Farm. It is because for some reason, Oculus starts looking for it | ||||||||||||||||||||||||||||||
| in `data/data/viewer.html` instead of just `data/viewer.html`. | ||||||||||||||||||||||||||||||
| This is IMHO a bug but either way, until it gets resolved, we can copy the | ||||||||||||||||||||||||||||||
| data there as well. | ||||||||||||||||||||||||||||||
| See https://gitlab.com/testing-farm/general/-/work_items/111 | ||||||||||||||||||||||||||||||
| Copy a mock fedora-ci.toml to the plan data directory | ||||||||||||||||||||||||||||||
| This is only for development purposes. In production a package either has | ||||||||||||||||||||||||||||||
| a fedora-ci.toml configuration in its repository or it doesn't. Either way, | ||||||||||||||||||||||||||||||
| we don't want to copy it from anywhere else. | ||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||
| shutil.copytree( | ||||||||||||||||||||||||||||||
| Path(os.environ["TMT_TEST_DATA"]), | ||||||||||||||||||||||||||||||
| Path(os.environ["TMT_TEST_DATA"]) / "data", | ||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||
| filename = "fedora-ci.toml" | ||||||||||||||||||||||||||||||
| print(f"Copying {filename} to the plan data") | ||||||||||||||||||||||||||||||
| dst = Path(os.environ["TMT_PLAN_DATA"]) / "dist-git" / filename | ||||||||||||||||||||||||||||||
| shutil.copy(filename, dst) | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| def fedora_review(spec_file, workdir): | ||||||||||||||||||||||||||||||
|
|
@@ -96,9 +100,20 @@ def fedora_review(spec_file, workdir): | |||||||||||||||||||||||||||||
| env["REVIEW_NO_MOCKGROUP_CHECK"] = "true" | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| name = Path(spec_file).stem | ||||||||||||||||||||||||||||||
| cmd = ["fedora-review", "--prebuilt", "-n", name] | ||||||||||||||||||||||||||||||
| config = str(args.workdir / "fedora-review.toml") | ||||||||||||||||||||||||||||||
| cmd = ["fedora-review", "--config", config, "--prebuilt", "-n", name] | ||||||||||||||||||||||||||||||
| print(f"Running: {" ".join(cmd)}") | ||||||||||||||||||||||||||||||
| subprocess.run(cmd, cwd=workdir, env=env, check=True) | ||||||||||||||||||||||||||||||
| proc = subprocess.run( | ||||||||||||||||||||||||||||||
| cmd, | ||||||||||||||||||||||||||||||
| cwd=workdir, | ||||||||||||||||||||||||||||||
| env=env, | ||||||||||||||||||||||||||||||
| stdout=subprocess.PIPE, | ||||||||||||||||||||||||||||||
| stderr=subprocess.PIPE, | ||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||
| print(proc.stdout.decode("utf-8")) | ||||||||||||||||||||||||||||||
| print(proc.stderr.decode("utf-8")) | ||||||||||||||||||||||||||||||
| if proc.returncode: | ||||||||||||||||||||||||||||||
| raise RuntimeError("The fedora-review command failed") | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| path = os.path.join(workdir, "review-" + name, "review.json") | ||||||||||||||||||||||||||||||
| if not os.path.exists(path): | ||||||||||||||||||||||||||||||
|
|
@@ -110,9 +125,46 @@ def fedora_review(spec_file, workdir): | |||||||||||||||||||||||||||||
| return review | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| def count_issues(review): | ||||||||||||||||||||||||||||||
| issues = review.get("issues", []) | ||||||||||||||||||||||||||||||
| return len(issues) | ||||||||||||||||||||||||||||||
| def skip_checks(config): | ||||||||||||||||||||||||||||||
| skip_for_all = [ | ||||||||||||||||||||||||||||||
| # A package with this name obviously already exists in the Fedora | ||||||||||||||||||||||||||||||
| # repositories and this is that package. Check for a name conflict only | ||||||||||||||||||||||||||||||
| # makes sense during the initial Package Review Process, but it does't | ||||||||||||||||||||||||||||||
| # make any sense for CI on existing packages. | ||||||||||||||||||||||||||||||
| "CheckNoNameConflict", | ||||||||||||||||||||||||||||||
| # The licensecheck implementation within the `fedora-review` tool is | ||||||||||||||||||||||||||||||
| # not up to modern standards and produces far to many false-positives | ||||||||||||||||||||||||||||||
| # which would be too annoying for our users. We discussed this with | ||||||||||||||||||||||||||||||
| # @msuchy and agreed that it would be better to have a dedicate service | ||||||||||||||||||||||||||||||
| # for checking licenses. It should be based around ScanCode Toolkit, | ||||||||||||||||||||||||||||||
| # FOSSology, or anything that succeeds them. | ||||||||||||||||||||||||||||||
| "CheckLicensInDoc", | ||||||||||||||||||||||||||||||
| "CheckLicenseField", | ||||||||||||||||||||||||||||||
| ] | ||||||||||||||||||||||||||||||
|
Comment on lines
+129
to
+143
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we put these in a
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So we would run something like I am not opposed to it but it would require some additional changes on the |
||||||||||||||||||||||||||||||
| skip_for_package = [] | ||||||||||||||||||||||||||||||
| if exclude := config.get("exclude"): | ||||||||||||||||||||||||||||||
| skip_for_package = [x.strip() for x in exclude.split(",")] | ||||||||||||||||||||||||||||||
| skip_for_package = [x for x in skip_for_package if x] | ||||||||||||||||||||||||||||||
| return skip_for_all + skip_for_package | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| def parse_fedora_review_toml(workdir: Path): | ||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||
| Parse the fedora-review.toml out of the fedora-ci.toml | ||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||
| dist_git_path = args.workdir / "dist-git" | ||||||||||||||||||||||||||||||
| if config := utils.get_config(dist_git_path, CI_CONFIG_SECTION): | ||||||||||||||||||||||||||||||
| return config["toml"] | ||||||||||||||||||||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we can drop the Then this is just a one-liner return utils.get_config(args.workdir / "dist-git", CI_CONFIG_SECTION) or {}
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we can because the {'toml': {'mock_config': 'fedora-43-x86_64', 'cache': False, 'verbose': True, 'checksum': 'sha256', 'use_colors': True, 'exclude': 'Check1,FooBarCheck,Baz,CheckPythonBuildRequires'}}so we need to go through the |
||||||||||||||||||||||||||||||
| return {} | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| def dump_fedora_review_config(fedora_review_config): | ||||||||||||||||||||||||||||||
| name = "fedora-review.toml" | ||||||||||||||||||||||||||||||
| path: Path = args.workdir / name | ||||||||||||||||||||||||||||||
| with path.open("wb") as fp: | ||||||||||||||||||||||||||||||
| tomli_w.dump(fedora_review_config, fp) | ||||||||||||||||||||||||||||||
| print(f"Copying {name} to the test results") | ||||||||||||||||||||||||||||||
| shutil.copy(path, Path(os.environ["TMT_TEST_DATA"]) / name) | ||||||||||||||||||||||||||||||
|
Comment on lines
+151
to
+167
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm thinking if these should be in the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I noticed that tmt-plans/tests/rpmlint/distgit-prepare.py Lines 26 to 39 in 8c265cf
but I was thinking the exact opposite. I see If there is some re-usable piece of code that all the tests should use, it should probably be in |
||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| def main(args: argparse.Namespace) -> None: | ||||||||||||||||||||||||||||||
|
|
@@ -129,14 +181,26 @@ def main(args: argparse.Namespace) -> None: | |||||||||||||||||||||||||||||
| # we just need to copy the .spec next to them | ||||||||||||||||||||||||||||||
| shutil.copy(args.spec_file, args.workdir) | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| # Uncomment if needed for development purposes | ||||||||||||||||||||||||||||||
| # copy_mock_fedora_ci_toml() | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| # Parse the `fedora-review config` aout of the `fedora-ci.toml`, update | ||||||||||||||||||||||||||||||
| # the list of excluded checks and save it as `fedora-review.toml`. | ||||||||||||||||||||||||||||||
| config = parse_fedora_review_toml(args.workdir) | ||||||||||||||||||||||||||||||
| skip = skip_checks(config) | ||||||||||||||||||||||||||||||
| config["exclude"] = ",".join(skip) | ||||||||||||||||||||||||||||||
| dump_fedora_review_config(config) | ||||||||||||||||||||||||||||||
| print(f"Skipping these checks: {skip}") | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| review = fedora_review(args.spec_file, args.workdir) | ||||||||||||||||||||||||||||||
| issues = count_issues(review) | ||||||||||||||||||||||||||||||
| dump_results_yaml(issues) | ||||||||||||||||||||||||||||||
| issues = review.get("issues", []) | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| dump_results_yaml(len(issues), len(skip)) | ||||||||||||||||||||||||||||||
| copy_fedora_review_results(args.spec_file, args.workdir) | ||||||||||||||||||||||||||||||
| copy_viewer_html() | ||||||||||||||||||||||||||||||
| copy_data_into_data() | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| print(f"Found {issues} issues") | ||||||||||||||||||||||||||||||
| print(f"Skipped {len(skip)} issues") | ||||||||||||||||||||||||||||||
| print(f"Found {len(issues)} issues") | ||||||||||||||||||||||||||||||
| if issues: | ||||||||||||||||||||||||||||||
| sys.exit(1) | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
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.
Why this change? It seems to do the same thing as before, but with extra steps. You could just try-catch if what you want a different exception message.
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.
Because with the previous version, the logs show
with the ugly traceback, and now the logs show just:
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.
Ah
CalledProcessError != RuntimeError. Try the pattern in rmdepcheck insteadThere 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.
That's also somehow weird
See how the "Running: fedora-review" line is after the actual failure?