Skip to content

Commit b79f823

Browse files
authored
Merge pull request #23 from LecrisUT/feat/rpmlint-distgit
Rework rpmlint to work with distgit
2 parents 025b4fa + 5b308bb commit b79f823

File tree

7 files changed

+256
-132
lines changed

7 files changed

+256
-132
lines changed

plans/rpmlint/README.md

Lines changed: 28 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -7,62 +7,46 @@ Run [rpmlint] on the current Copr project or Koji build
77
## Synopsis
88

99
```yaml
10-
discover:
11-
how: fmf
12-
filter: "tag: rpmlint"
13-
url: https://github.com/packit/tmt-plans
14-
ref: main
15-
execute:
16-
how: tmt
10+
plans:
11+
import:
12+
url: https://github.com/packit/tmt-plans
13+
ref: main
14+
name: /plans/rpmlint
1715
```
1816
1917
## Description
2018
21-
This plan simply runs the command
19+
This plan simply runs `rpmlint` against the rpms and spec files provided. For specific details, see the
20+
[`/tests/rpmlint/run-rpmlint.py`] wrapper file.
2221

23-
```console
24-
$ rpmlint ./*.rpm
25-
```
22+
Depending on the calling environment (`initiator`, `trigger` contexts) the inputs of this plan are provided
23+
automatically, otherwise see the [options section](#options) for the expected control parameters.
2624

27-
The `rpm` and `srpm` artifacts are taken from the testing-farm artifacts. In order to pass a `.rpmlintrc` file, use the
28-
[`prepare`] step of the plan to copy the file to `TMT_PLAN_DATA`. Only the `rpmlintrc` file that matches the spec file
29-
is used.
25+
## Options
3026

31-
:::note
27+
`SPEC_FILE`
3228

33-
The rpmlint of the `.spec` file is handled automatically when running `rpmlint` against a `srpm`.
29+
: koji-build: Detected from dist-git (`*.spec`)
30+
: copr: Not supported currently
31+
: Spec file to check.
3432

35-
:::
33+
`RPM_FILES`
3634

37-
## Options
35+
: koji-build: Downloaded all rpm files from koji task
36+
: copr: From testing-farm artifacts (`/var/share/test-artifacts/*.rpm`)
37+
: RPM files to check. Can be wildcard.
3838

39-
No options available
39+
`RPMLINT_RC_FILE`
4040

41-
## Examples
41+
: koji-build: Detected from dist-git (`*.rpmlintrc`)
42+
: copr: Not supported currently
43+
: .rpmlintrc file.
4244

43-
- Rpmlint the upstream packit project
44-
```yaml
45-
discover:
46-
how: fmf
47-
filter: "tag: rpmlint"
48-
url: https://github.com/packit/tmt-plans
49-
ref: main
50-
execute:
51-
how: tmt
52-
```
53-
- Use `rpmlintrc` file
54-
```yaml
55-
prepare:
56-
- how: shell
57-
script: cp ./*.rpmlintrc $TMT_PLAN_DATA/
58-
discover:
59-
how: fmf
60-
filter: "tag: rpmlint"
61-
url: https://github.com/packit/tmt-plans
62-
ref: main
63-
execute:
64-
how: tmt
65-
```
45+
`RPMLINT_TOML_FILE`
46+
47+
: koji-build: Detected from dist-git (`rpmlint.toml`)
48+
: copr: Not supported currently
49+
: Rpmlint toml file to override.
6650

6751
## See Also
6852

@@ -71,4 +55,4 @@ No options available
7155
<!-- SPHINX-END -->
7256

7357
[rpmlint]: https://github.com/rpm-software-management/rpmlint
74-
[`prepare`]: https://tmt.readthedocs.io/en/stable/spec/plans.html#prepare
58+
[`/tests/rpmlint/run-rpmlint.py`]: ../../tests/rpmlint/run-rpmlint.py

plans/rpmlint/main.fmf

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,10 @@ summary: Run rpmlint on all rpms and spec file
33
description: |
44
Equivalent to zuul job running rpmlint
55

6-
discover+:
7-
filter: "tag: rpmlint"
6+
provision:
7+
how: container
8+
image: fedora:latest
9+
10+
discover:
11+
how: fmf
12+
test: /tests/rpmlint

tests/rpmlint/copr-prepare.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/usr/bin/python3
2+
# /// script
3+
# dependencies = [ ]
4+
# ///
5+
6+
import argparse
7+
import os
8+
import re
9+
import subprocess
10+
from pathlib import Path
11+
12+
13+
def main(args: argparse.Namespace) -> None:
14+
"""
15+
Prepare for rpmlint from a copr-build
16+
"""
17+
args.env_file: Path
18+
19+
# TODO: Get the data from copr.
20+
# For now we assume a testing-farm environment.
21+
with args.env_file.open("a") as f:
22+
f.write("RPM_FILES=/var/share/test-artifacts/*.rpm\n")
23+
24+
25+
if __name__ == "__main__":
26+
parser = argparse.ArgumentParser()
27+
parser.add_argument("--copr-project", default=os.environ.get("PACKIT_COPR_PROJECT"))
28+
# TODO: Get the data from copr.
29+
# TODO: Get the rpmlint that upstream passes somehow
30+
parser.add_argument(
31+
"--workdir",
32+
type=Path,
33+
default=os.environ.get("TMT_PLAN_DATA", "."),
34+
)
35+
parser.add_argument(
36+
"--env-file",
37+
type=Path,
38+
default=os.environ.get("TMT_PLAN_ENVIRONMENT_FILE", ".env"),
39+
)
40+
41+
args = parser.parse_args()
42+
main(args)

tests/rpmlint/distgit-prepare.py

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
#!/usr/bin/python3
2+
# /// script
3+
# dependencies = [ ]
4+
# ///
5+
6+
import argparse
7+
import os
8+
import re
9+
import subprocess
10+
from pathlib import Path
11+
12+
13+
def main(args: argparse.Namespace) -> None:
14+
"""
15+
Prepare for rpmlint from a dist-git
16+
"""
17+
args.env_file: Path
18+
19+
# Get the basic build information from koji
20+
task_info = subprocess.run(
21+
[
22+
"koji",
23+
"taskinfo",
24+
"-v",
25+
args.koji_task_id,
26+
],
27+
capture_output=True,
28+
text=True,
29+
).stdout
30+
source = re.search(r"Source:\s*(.*)", task_info).group(1)
31+
source_match = re.search(r"git\+(?P<url>.*)#(?P<ref>.*)", source)
32+
repo_url = source_match.group("url")
33+
repo_ref = source_match.group("ref")
34+
35+
# Clone the dist-git used in the build
36+
dist_git_path: Path = args.workdir / "dist-git"
37+
subprocess.run(["git", "clone", repo_url, dist_git_path])
38+
subprocess.run(["git", "checkout", "-d", repo_ref], cwd=dist_git_path)
39+
40+
# Find any rplintrc files
41+
rc_files = list(dist_git_path.glob("*.rpmlintrc"))
42+
if len(rc_files) > 1:
43+
print("Warn: More than 1 rpmlintrc file found")
44+
if rc_files:
45+
print("Found rpmlintrc file")
46+
with args.env_file.open("a") as f:
47+
f.write(f"RPMLINT_RC_FILE={rc_files[0]}\n")
48+
toml_file = dist_git_path / "rpmlint.toml"
49+
if toml_file.exists():
50+
print("Found rpmlint.toml file")
51+
with args.env_file.open("a") as f:
52+
f.write(f"RPMLINT_TOML_FILE={toml_file}\n")
53+
54+
# Find the files to lint
55+
spec_files = list(dist_git_path.glob("*.spec"))
56+
if len(spec_files) > 1:
57+
print("Warn: More than 1 spec file found")
58+
if spec_files:
59+
with args.env_file.open("a") as f:
60+
f.write(f"SPEC_FILE={spec_files[0]}\n")
61+
else:
62+
print("Warn: No spec file found?")
63+
subprocess.run(
64+
["koji", "download-task", args.koji_task_id],
65+
cwd=args.workdir,
66+
)
67+
with args.env_file.open("a") as f:
68+
f.write(f"RPM_FILES={args.workdir}/*.rpm\n")
69+
70+
71+
if __name__ == "__main__":
72+
parser = argparse.ArgumentParser()
73+
parser.add_argument("--koji-task-id", default=os.environ.get("KOJI_TASK_ID"))
74+
parser.add_argument(
75+
"--workdir",
76+
type=Path,
77+
default=os.environ.get("TMT_PLAN_DATA", "."),
78+
)
79+
parser.add_argument(
80+
"--env-file",
81+
type=Path,
82+
default=os.environ.get("TMT_PLAN_ENVIRONMENT_FILE", ".env"),
83+
)
84+
85+
args = parser.parse_args()
86+
main(args)

tests/rpmlint/main.fmf

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,37 @@
1-
summary: Run rpmlint
2-
tag: rpmlint
3-
require:
4-
- rpmlint
5-
result: custom
1+
/:
2+
inherit: false
63

7-
test+: rpmlint.sh
4+
/prepare-distgit:
5+
summary: Prepare with distgit environment
6+
enabled: false
7+
order: 40
8+
require:
9+
- koji
10+
- git
11+
test: python3 ./distgit-prepare.py
12+
adjust:
13+
# TODO: For now this is only available for distgit commits
14+
when: initiator == fedora-ci and trigger == commit
15+
enabled: true
16+
17+
/prepare-copr:
18+
summary: Prepare with copr environment
19+
enabled: false
20+
order: 40
21+
require:
22+
- copr
23+
- git
24+
test: python3 ./copr-prepare.py
25+
adjust:
26+
when: initiator == packit
27+
enabled: true
28+
29+
/run-rpmlint:
30+
summary: Run rpmlint
31+
description: |
32+
Requires having some environment variables predefined.
33+
See documentation of the run-rpmlint script.
34+
require:
35+
- rpmlint
36+
- rpmlint-fedora-license-data
37+
test: python3 ./run-rpmlint.py

tests/rpmlint/rpmlint.sh

Lines changed: 0 additions & 80 deletions
This file was deleted.

0 commit comments

Comments
 (0)