Skip to content

Commit 9b53c08

Browse files
authored
Merge pull request #28 from FrostyX/fedora-review
Implement fedora-review plan
2 parents ba4a542 + ce1ca8c commit 9b53c08

6 files changed

Lines changed: 135 additions & 0 deletions

File tree

plans/fedora-review/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Fedora Review
2+
3+
Run [fedora-review] on the current Copr project or Koji build
4+
5+
See this discussion for more
6+
https://discussion.fedoraproject.org/t/running-fedora-review-on-every-commit/178858
7+
8+
[fedora-review]: https://pagure.io/FedoraReview

plans/fedora-review/main.fmf

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
summary: Run fedora-review on all rpms and spec file
2+
3+
description: |
4+
See this discussion for more
5+
https://discussion.fedoraproject.org/t/running-fedora-review-on-every-commit/178858
6+
7+
# We need a full VM because fedora-review does things inside of Mock, which
8+
# AFAIK cannot run inside a container yet.
9+
# https://github.com/rpm-software-management/mock/issues/1487
10+
# https://github.com/rpm-software-management/mock/issues/217
11+
# https://github.com/rpm-software-management/mock/issues/192
12+
provision:
13+
how: virtual
14+
image: fedora
15+
16+
discover:
17+
how: fmf
18+
test: /tests/fedora-review
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../rpmlint/copr-prepare.py
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../rpmlint/distgit-prepare.py

tests/fedora-review/main.fmf

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/:
2+
inherit: false
3+
4+
/prepare-distgit:
5+
summary: Prepare with distgit environment
6+
enabled: false
7+
duration: 30m
8+
order: 40
9+
require:
10+
- koji
11+
- git
12+
test: python3 ./distgit-prepare.py
13+
adjust:
14+
# TODO: For now this is only available for distgit commits
15+
when: initiator == fedora-ci and trigger == commit
16+
enabled: true
17+
18+
/prepare-copr:
19+
summary: Prepare with copr environment
20+
enabled: false
21+
duration: 30m
22+
order: 40
23+
require:
24+
- copr
25+
- git
26+
test: python3 ./copr-prepare.py
27+
adjust:
28+
when: initiator == packit
29+
enabled: true
30+
31+
/run-fedora-review:
32+
summary: Run fedora-review
33+
duration: 30m
34+
description: |
35+
Requires having some environment variables predefined.
36+
See documentation of the run-fedora-review script.
37+
require:
38+
- fedora-review
39+
test: python3 ./run-fedora-review.py
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#!/usr/bin/python3
2+
3+
import sys
4+
import argparse
5+
import os
6+
import subprocess
7+
import shutil
8+
from pathlib import Path
9+
10+
11+
def main(args: argparse.Namespace) -> None:
12+
"""
13+
Run fedora-review
14+
"""
15+
if not args.spec_file:
16+
raise RuntimeError("No spec file provided")
17+
18+
if not args.rpm_files:
19+
raise RuntimeError("No RPM files provided")
20+
21+
# At this point, the RPM packages are already downloaded in `args.workdir`,
22+
# we just need to copy the .spec next to them
23+
shutil.copy(args.spec_file, args.workdir)
24+
25+
env = os.environ.copy()
26+
env["REVIEW_NO_MOCKGROUP_CHECK"] = "true"
27+
28+
name = Path(args.spec_file).stem
29+
cmd = ["fedora-review", "--prebuilt", "-n", name]
30+
print(f"Running: {" ".join(cmd)}")
31+
subprocess.run(cmd, cwd=args.workdir, env=env, check=True)
32+
33+
result = os.path.join(args.workdir, "review-" + name, "review.json")
34+
if not os.path.exists(result):
35+
raise RuntimeError(f"Result JSON doesn't exist: {result}")
36+
37+
print("Result: {0}".format(result))
38+
39+
40+
if __name__ == "__main__":
41+
parser = argparse.ArgumentParser(
42+
description=(
43+
"Simple wrapper for fedora-review. "
44+
"Can also pass variables via environment variables."
45+
)
46+
)
47+
parser.add_argument(
48+
"--workdir",
49+
type=Path,
50+
default=os.environ.get("TMT_PLAN_DATA", "."),
51+
)
52+
parser.add_argument(
53+
"--spec-file",
54+
help="Spec file to check.",
55+
default=os.environ.get("SPEC_FILE"),
56+
)
57+
parser.add_argument(
58+
"--rpm-files",
59+
help="RPM files to check. Can be wildcard.",
60+
default=os.environ.get("RPM_FILES"),
61+
)
62+
63+
args = parser.parse_args()
64+
try:
65+
main(args)
66+
except RuntimeError as ex:
67+
print(ex, file=sys.stderr)
68+
sys.exit(1)

0 commit comments

Comments
 (0)