1
0
mirror of https://github.com/openSUSE/osc.git synced 2025-01-12 08:56:13 +01:00

Add results --fail-on-error/-F flag

This allows to exit with `1` in case any build fails to provide feedback
to end-user scripts.

Refers to: https://github.com/kubernetes/release/issues/3632

Signed-off-by: Sascha Grunert <sgrunert@redhat.com>
This commit is contained in:
Sascha Grunert 2024-06-05 11:25:43 +02:00 committed by Daniel Mach
parent a6c0b2c8d5
commit e43477921c
2 changed files with 29 additions and 2 deletions

View File

@ -6049,6 +6049,8 @@ Please submit there instead, or use --nodevelproject to force direct submission.
help='list packages vertically instead horizontally for entire project') help='list packages vertically instead horizontally for entire project')
@cmdln.option('-w', '--watch', action='store_true', @cmdln.option('-w', '--watch', action='store_true',
help='watch the results until all finished building') help='watch the results until all finished building')
@cmdln.option('-F', '--fail-on-error', action='store_true',
help='fail with exit 1 if any build has errored')
@cmdln.option('-s', '--status-filter', @cmdln.option('-s', '--status-filter',
help='only show packages with the given build status') help='only show packages with the given build status')
@cmdln.option('-f', '--failed', action='store_true', @cmdln.option('-f', '--failed', action='store_true',
@ -6162,7 +6164,13 @@ Please submit there instead, or use --nodevelproject to force direct submission.
kwargs['wait'] = opts.watch kwargs['wait'] = opts.watch
kwargs['printJoin'] = '\n' kwargs['printJoin'] = '\n'
kwargs['format'] = opts.format kwargs['format'] = opts.format
get_results(**kwargs)
out = {}
get_results(out=out, **kwargs)
if opts.fail_on_error and out['failed']:
sys.exit(1)
# WARNING: this function is also called by do_results. You need to set a default there # WARNING: this function is also called by do_results. You need to set a default there
# as well when adding a new option! # as well when adding a new option!

View File

@ -4096,7 +4096,16 @@ def format_results(results, format):
return [format % r for r in results] return [format % r for r in results]
def get_results(apiurl: str, project: str, package: str, verbose=False, printJoin="", *args, **kwargs): def get_results(
apiurl: str,
project: str,
package: str,
verbose=False,
printJoin="",
out: Optional[dict] = None,
*args,
**kwargs
):
"""returns list of/or prints a human readable status for the specified package""" """returns list of/or prints a human readable status for the specified package"""
# hmm the function name is a bit too generic - something like # hmm the function name is a bit too generic - something like
# get_package_results_human would be better, but this would break the existing # get_package_results_human would be better, but this would break the existing
@ -4106,6 +4115,7 @@ def get_results(apiurl: str, project: str, package: str, verbose=False, printJoi
format = '%(rep)-20s %(arch)-10s %(pkg)-30s %(status)s' format = '%(rep)-20s %(arch)-10s %(pkg)-30s %(status)s'
r = [] r = []
printed = False printed = False
failed = False
multibuild_packages = kwargs.pop('multibuild_packages', []) multibuild_packages = kwargs.pop('multibuild_packages', [])
show_excluded = kwargs.pop('showexcl', False) show_excluded = kwargs.pop('showexcl', False)
code_filter = kwargs.get('code') code_filter = kwargs.get('code')
@ -4148,12 +4158,21 @@ def get_results(apiurl: str, project: str, package: str, verbose=False, printJoi
if code_filter is None or code_filter == res['code']: if code_filter is None or code_filter == res['code']:
r.append(format % res) r.append(format % res)
if res['code'] in ('failed', 'broken', 'unresolvable'):
failed = True
if printJoin: if printJoin:
if printed: if printed:
# will print a newline if already a result was printed (improves readability) # will print a newline if already a result was printed (improves readability)
print() print()
print(printJoin.join(r)) print(printJoin.join(r))
printed = True printed = True
if out is None:
out = {}
out["failed"] = failed
return r return r