Skip to content

Commit 0b7b8db

Browse files
committed
Allow to use rpmlintrc files
Signed-off-by: Cristian Le <[email protected]>
1 parent 2811c0c commit 0b7b8db

File tree

5 files changed

+49
-25
lines changed

5 files changed

+49
-25
lines changed

plans/rpmlint/README.md

+31-13
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@ Run [rpmlint] on the current Copr project or Koji build
77
## Synopsis
88

99
```yaml
10-
plans:
11-
import:
12-
url: https://github.com/packit/tmt-plans
13-
ref: main
14-
name: /plans/rpmlint
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
1517
```
1618
1719
## Description
@@ -22,8 +24,9 @@ This plan simply runs the command
2224
$ rpmlint ./*.rpm
2325
```
2426

25-
Currently, there is no support to pass in additional `.rpmlintrc` due to limitations of the [`tmt`][tmt-import]
26-
interface. The `rpm` and `srpm` artifacts are taken from the testing-farm artifacts
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.
2730

2831
:::note
2932

@@ -39,11 +42,26 @@ No options available
3942

4043
- Rpmlint the upstream packit project
4144
```yaml
42-
plans:
43-
import:
44-
url: https://github.com/packit/tmt-plans
45-
ref: main
46-
name: /plans/rpmlint
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
4765
```
4866

4967
## See Also
@@ -53,4 +71,4 @@ No options available
5371
<!-- SPHINX-END -->
5472

5573
[rpmlint]: https://github.com/rpm-software-management/rpmlint
56-
[tmt-import]: https://tmt.readthedocs.io/en/stable/spec/plans.html#import-plans
74+
[`prepare`]: https://tmt.readthedocs.io/en/stable/spec/plans.html#prepare

plans/rpmlint/main.fmf

-11
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,5 @@ summary: Run rpmlint on all rpms and spec file
33
description: |
44
Equivalent to zuul job running rpmlint
55

6-
prepare:
7-
- name: Get necessary packages
8-
how: install
9-
package:
10-
- rpmlint
11-
- tree
12-
- name: Copy rpmlint toml configuration file
13-
how: shell
14-
script: cp plans/rpmlint/packit.toml $TMT_PLAN_DATA/packit.toml
15-
# TODO: How to get the .rpmlintrc files?
16-
176
discover+:
187
filter: "tag: rpmlint"

tests/rpmlint/main.fmf

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
summary: Run rpmlint
22
tag: rpmlint
3+
require:
4+
- rpmlint
35

46
test+: rpmlint.sh
File renamed without changes.

tests/rpmlint/rpmlint.sh

+16-1
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,31 @@
55
rlJournalStart
66
rlPhaseStartSetup
77
rlRun "tmp=\$(mktemp -d)" 0 "Create tmp directory"
8+
rlRun "work_dir=$(pwd)" 0 "Save original work_dir"
89
rlRun "pushd $tmp"
910
rlRun "set -o pipefail"
1011
rlIsCentOS && rlLogWarning "rpmlint on CentOS+Epel is outdated. Reported information might not be relevant"
1112
rlPhaseEnd
1213

1314
rlPhaseStartTest
15+
if [[ -f "$TMT_PLAN_DATA/rpmlint.toml" ]]; then
16+
# A custom rpmlint toml file was provided. Use that instead of the local files
17+
rlRun "config_file=$TMT_PLAN_DATA/rpmlint.toml" 0 "Use config file from plan data"
18+
else
19+
# TODO: Use packit.toml only in packit context
20+
rlRun "config_file=$work_dir/tests/rpmlint/packit.toml" 0 "Use the provided packit config file"
21+
fi
1422
rlRun "rpm2cpio /var/share/test-artifacts/*.src.rpm | cpio -civ '*.spec'" 0 "Extract spec file from srpm"
1523
rlRun "cp ./*.spec $TMT_TEST_DATA/" 0 "Expose spec file"
24+
# Dummy loop over spec file to extract the file name
25+
for spec_file in *.spec; do
26+
# Extract the base name from the file name and save it in BASH_REMATCH
27+
[[ $spec_file =~ (.*).spec ]];
28+
# Only use rpmlintrc file with the same name as the spec file
29+
[[ -f "$TMT_PLAN_DATA/${BASH_REMATCH[1]}.rpmlintrc" ]] && rlRun "rc_file=$TMT_PLAN_DATA/${BASH_REMATCH[1]}.rpmlintrc" 0 "Use the rpmlintrc file of $spec_file"
30+
done
1631
# The spec rpmlint is already executed from the srpm
17-
rlIsCentOS || rlRun "rpmlint -c $TMT_PLAN_DATA/packit.toml /var/share/test-artifacts/*.rpm" 0 "Run rpmlint (non-CentOS)"
32+
rlIsCentOS || rlRun "rpmlint -c $config_file ${rc_file:+"-r $rc_file"} /var/share/test-artifacts/*.rpm" 0 "Run rpmlint (non-CentOS)"
1833
rlIsCentOS && rlRun "rpmlint /var/share/test-artifacts/*.rpm || true" 0 "Run rpmlint (CentOS)"
1934
rlPhaseEnd
2035

0 commit comments

Comments
 (0)