From 24964681a8ab84470e623017d066c2815e1692d8 Mon Sep 17 00:00:00 2001 From: William Martin Date: Fri, 13 Feb 2026 15:34:20 +0100 Subject: [PATCH] Respect --exit-status with --log and --log-failed Fixes #12674 --- pkg/cmd/run/view/view.go | 9 +++++- pkg/cmd/run/view/view_test.go | 58 +++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 1 deletion(-) diff --git a/pkg/cmd/run/view/view.go b/pkg/cmd/run/view/view.go index d50b14fdf..bed9e3bfa 100644 --- a/pkg/cmd/run/view/view.go +++ b/pkg/cmd/run/view/view.go @@ -331,7 +331,14 @@ func runView(opts *ViewOptions) error { return err } - return displayLogSegments(opts.IO.Out, segments) + if err := displayLogSegments(opts.IO.Out, segments); err != nil { + return err + } + + if opts.ExitStatus && shared.IsFailureState(run.Conclusion) { + return cmdutil.SilentError + } + return nil } prNumber := "" diff --git a/pkg/cmd/run/view/view_test.go b/pkg/cmd/run/view/view_test.go index 5bcb587d1..14749fcf6 100644 --- a/pkg/cmd/run/view/view_test.go +++ b/pkg/cmd/run/view/view_test.go @@ -1048,6 +1048,64 @@ func TestViewRun(t *testing.T) { }, wantOut: quuxTheBarfLogOutput, }, + { + name: "exit status respected with log-failed, failed run", + opts: &ViewOptions{ + RunID: "1234", + LogFailed: true, + ExitStatus: true, + }, + httpStubs: func(reg *httpmock.Registry) { + reg.Register( + httpmock.REST("GET", "repos/OWNER/REPO/actions/runs/1234"), + httpmock.JSONResponse(shared.FailedRun)) + reg.Register( + httpmock.REST("GET", "runs/1234/jobs"), + httpmock.JSONResponse(shared.JobsPayload{ + Jobs: []shared.Job{ + shared.SuccessfulJob, + shared.FailedJob, + }, + })) + reg.Register( + httpmock.REST("GET", "repos/OWNER/REPO/actions/runs/1234/logs"), + httpmock.BinaryResponse(zipArchive)) + reg.Register( + httpmock.REST("GET", "repos/OWNER/REPO/actions/workflows/123"), + httpmock.JSONResponse(shared.TestWorkflow)) + }, + wantOut: quuxTheBarfLogOutput, + wantErr: true, + }, + { + name: "exit status respected with log, failed run", + opts: &ViewOptions{ + RunID: "1234", + Log: true, + ExitStatus: true, + }, + httpStubs: func(reg *httpmock.Registry) { + reg.Register( + httpmock.REST("GET", "repos/OWNER/REPO/actions/runs/1234"), + httpmock.JSONResponse(shared.FailedRun)) + reg.Register( + httpmock.REST("GET", "runs/1234/jobs"), + httpmock.JSONResponse(shared.JobsPayload{ + Jobs: []shared.Job{ + shared.SuccessfulJob, + shared.FailedJob, + }, + })) + reg.Register( + httpmock.REST("GET", "repos/OWNER/REPO/actions/runs/1234/logs"), + httpmock.BinaryResponse(zipArchive)) + reg.Register( + httpmock.REST("GET", "repos/OWNER/REPO/actions/workflows/123"), + httpmock.JSONResponse(shared.TestWorkflow)) + }, + wantOut: expectedRunLogOutput, + wantErr: true, + }, { name: "interactive with log, with no step logs available (#10551)", tty: true,