Skip to content

Commit

Permalink
Add results --fail-on-error/-F flag
Browse files Browse the repository at this point in the history
This allows to exit with `1` in case any build fails to provide feedback
to end-user scripts.

Refers to: kubernetes/release#3632

Signed-off-by: Sascha Grunert <[email protected]>
  • Loading branch information
saschagrunert committed Jun 11, 2024
1 parent 84524b5 commit 84841fc
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
11 changes: 10 additions & 1 deletion osc/commandline.py
Original file line number Diff line number Diff line change
Expand Up @@ -6046,6 +6046,8 @@ def do_rremove(self, subcmd, opts):
help='list packages vertically instead horizontally for entire project')
@cmdln.option('-w', '--watch', action='store_true',
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',
help='only show packages with the given build status')
@cmdln.option('-f', '--failed', action='store_true',
Expand Down Expand Up @@ -6129,7 +6131,14 @@ def do_results(self, subcmd, opts, *args):
kwargs['verbose'] = opts.verbose
kwargs['wait'] = opts.watch
kwargs['printJoin'] = '\n'
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
# as well when adding a new option!
Expand Down
21 changes: 20 additions & 1 deletion osc/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -4089,7 +4089,16 @@ def format_results(results, format):
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"""
# hmm the function name is a bit too generic - something like
# get_package_results_human would be better, but this would break the existing
Expand All @@ -4098,6 +4107,7 @@ def get_results(apiurl: str, project: str, package: str, verbose=False, printJoi
result_line_mb_templ = '%(rep)-20s %(arch)-10s %(pkg)-30s %(status)s'
r = []
printed = False
failed = False
multibuild_packages = kwargs.pop('multibuild_packages', [])
show_excluded = kwargs.pop('showexcl', False)
code_filter = kwargs.get('code')
Expand Down Expand Up @@ -4143,12 +4153,21 @@ def get_results(apiurl: str, project: str, package: str, verbose=False, printJoi
else:
r.append(result_line_templ % res)

if res['code'] in ('failed', 'broken', 'unresolvable'):
failed = True

if printJoin:
if printed:
# will print a newline if already a result was printed (improves readability)
print()
print(printJoin.join(r))
printed = True

if out is None:
out = {}

out["failed"] = failed

return r


Expand Down

0 comments on commit 84841fc

Please sign in to comment.