Skip to content

Commit df95fda

Browse files
authored
SRE-2920 ci: Simplify RPM Lint (#462)
rpmlintMockResults.groovy was screen scraping the results of rpmlint to get additional information. With an updated to rpmlint, this broke. Simplifying the script to just use rpmlint return code. Signed-off-by: Ryon Jensen <[email protected]>
1 parent 5fc4967 commit df95fda

File tree

1 file changed

+9
-51
lines changed

1 file changed

+9
-51
lines changed

vars/rpmlintMockResults.groovy

+9-51
Original file line numberDiff line numberDiff line change
@@ -13,30 +13,6 @@
1313
* @param config Mock configuration name to check in
1414
* @param allow_errors Whether errors are allowd. Defaults to false.
1515
*/
16-
String warnings(String output) {
17-
return extract(output, 'warnings')
18-
}
19-
20-
String errors(String output) {
21-
return extract(output, 'errors')
22-
}
23-
24-
String extract(String output, String type) {
25-
/* groovylint-disable-next-line VariableName */
26-
String T
27-
if (type == 'errors') {
28-
T = 'E'
29-
} else if (type == 'warnings') {
30-
T = 'W'
31-
} else {
32-
error("Unsupported type ${type} passed to extract()")
33-
}
34-
35-
return sh(label: "Extract ${type} from rpmlint output",
36-
script: "echo \"${output}\" | grep ': ${T}: '",
37-
returnStdout: true).trim()
38-
}
39-
4016
/* groovylint-disable-next-line ParameterName */
4117
void call(String config, Boolean allow_errors=false, Boolean skip_rpmlint=false, String make_args='') {
4218
if (skip_rpmlint || config == 'not_applicable') {
@@ -47,50 +23,32 @@ void call(String config, Boolean allow_errors=false, Boolean skip_rpmlint=false,
4723
if (fileExists('utils/rpms/Makefile')) {
4824
chdir = 'utils/rpms/'
4925
}
50-
String output = sh(label: 'RPM Lint built RPMs',
51-
script: 'cd ' + chdir + '\n' +
26+
int result = sh(label: 'RPM Lint built RPMs',
27+
script: 'cd ' + chdir + '\n' +
5228
/* groovylint-disable-next-line GStringExpressionWithinString */
5329
'''name=$(make ''' + make_args + ''' show_NAME)
5430
if [ -f "$name".rpmlintrc ]; then
5531
rpmlint_args=(-r "$name".rpmlintrc)
5632
fi
5733
rpmlint --ignore-unused-rpmlintrc "${rpmlint_args[@]}" ''' +
5834
'$(ls /var/lib/mock/' + config + '/result/*.rpm | ' +
59-
'grep -v -e -debuginfo -e debugsource) || exit 0',
60-
returnStdout: true).trim()
61-
62-
int result = sh(label: 'Analyze rpmlint output',
63-
script: "read e w b < <(echo \"${output}\" | " +
64-
"""sed -nEe '\$s/.*([0-9]+) errors, ([0-9]+) warnings, ([0-9]+) badness;.*/\\1 \\2 \\3/p')
65-
if [ "\$e" -gt 0 ]; then
66-
exit 2
67-
elif [ "\$w" -gt 0 ]; then
68-
exit 1
69-
fi
70-
exit 0""",
35+
'grep -v -e -debuginfo -e debugsource)',
7136
returnStatus: true)
7237

7338
catchError(stageResult: 'UNSTABLE', buildResult: 'SUCCESS') {
74-
if (result == 2 && allow_errors) {
75-
error('RPM Lint found errors, but allow_errors is ' + allow_errors + ':\n' +
76-
errors(output) + '\n\n' +
77-
'And also found additional warnings that it would be nice to fix:\n' + warnings(output))
78-
} else if (result == 1) {
79-
error('RPM Lint found warnings:\n' + warnings(output))
39+
if (result > 0 && allow_errors) {
40+
error('RPM Lint found errors, but allow_errors is true.')
8041
}
81-
return
8242
}
8343

8444
catchError(stageResult: 'UNSTABLE', buildResult: 'UNSTABLE') {
85-
if (result == 2 && !allow_errors) {
86-
error('RPM Lint found errors:\n' + errors(output) + '\n\n' +
87-
'And also found additional warnings that it would be nice to fix:\n' + warnings(output))
45+
if (result > 0 && !allow_errors) {
46+
error('RPM Lint found errors.')
8847
}
89-
return
9048
}
9149

92-
// the returns above in the catchError() blocks don't acutally seem to work
50+
// Print success message if rpmlint exits with 0
9351
if (result == 0) {
94-
echo('RPM Lint output:\n' + output)
52+
echo 'RPM Lint passed with no errors or warnings.'
9553
}
9654
}

0 commit comments

Comments
 (0)