From bcbe66a37fccd354f3f7616c29805426058be99f Mon Sep 17 00:00:00 2001 From: jpic Date: Sat, 24 Apr 2021 14:00:27 +0200 Subject: [PATCH] Fix exit codes --- .gitlab-ci.yml | 6 ++++++ shlax/cli.py | 12 ++++++------ tests/shlaxfail.py | 18 ++++++++++++++++++ tests/shlaxsuccess.py | 17 +++++++++++++++++ 4 files changed, 47 insertions(+), 6 deletions(-) create mode 100755 tests/shlaxfail.py create mode 100755 tests/shlaxsuccess.py diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index edef314..080520e 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -16,6 +16,12 @@ build-itself: script: python3 ./shlaxfile.py build push=docker://docker.io/yourlabs/shlax:$CI_COMMIT_REF stage: test +test-exitcode: + image: yourlabs/shlax:$CI_COMMIT_SHORT_SHA + script: + - tests/shlaxfail.py build || [ $? -eq 1 ] + - tests/shlaxsuccess.py build + test: image: yourlabs/python stage: build diff --git a/shlax/cli.py b/shlax/cli.py index 9d07cf5..194d576 100644 --- a/shlax/cli.py +++ b/shlax/cli.py @@ -60,13 +60,13 @@ class Command(cli2.Command): except ProcFailure: # just output the failure without TB, as command was already # printed anyway - self.exit_code = 1 - self['target'].value.output.results(self['target'].value) + pass - if result and result.status == 'success': - self.exit_code = 0 - else: - self.exit_code = 1 + if self['target'].value.results: + if self['target'].value.results[-1].status == 'failure': + self.exit_code = 1 + self['target'].value.output.results(self['target'].value) + return result class ActionCommand(cli2.Command): diff --git a/tests/shlaxfail.py b/tests/shlaxfail.py new file mode 100755 index 0000000..88adda5 --- /dev/null +++ b/tests/shlaxfail.py @@ -0,0 +1,18 @@ +#!/usr/bin/env python +""" +Shlaxfile for shlax itself. +""" + +from shlax.shortcuts import * + +shlax = Container( + build=Buildah( + Packages('prout', upgrade=False), + base='alpine', + commit='shlaxfail', + ), +) + + +if __name__ == '__main__': + print(Group(doc=__doc__).load(shlax).entry_point()) diff --git a/tests/shlaxsuccess.py b/tests/shlaxsuccess.py new file mode 100755 index 0000000..cd5b23b --- /dev/null +++ b/tests/shlaxsuccess.py @@ -0,0 +1,17 @@ +#!/usr/bin/env python +""" +Shlaxfile for shlax itself. +""" + +from shlax.shortcuts import * + +shlax = Container( + build=Buildah( + base='alpine', + commit='shlaxsuccess', + ), +) + + +if __name__ == '__main__': + print(Group(doc=__doc__).load(shlax).entry_point())