Skip to content

Commit 2496468

Browse files
committed
Respect --exit-status with --log and --log-failed
Fixes cli#12674
1 parent 2c54a0d commit 2496468

2 files changed

Lines changed: 66 additions & 1 deletion

File tree

pkg/cmd/run/view/view.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,14 @@ func runView(opts *ViewOptions) error {
331331
return err
332332
}
333333

334-
return displayLogSegments(opts.IO.Out, segments)
334+
if err := displayLogSegments(opts.IO.Out, segments); err != nil {
335+
return err
336+
}
337+
338+
if opts.ExitStatus && shared.IsFailureState(run.Conclusion) {
339+
return cmdutil.SilentError
340+
}
341+
return nil
335342
}
336343

337344
prNumber := ""

pkg/cmd/run/view/view_test.go

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,6 +1048,64 @@ func TestViewRun(t *testing.T) {
10481048
},
10491049
wantOut: quuxTheBarfLogOutput,
10501050
},
1051+
{
1052+
name: "exit status respected with log-failed, failed run",
1053+
opts: &ViewOptions{
1054+
RunID: "1234",
1055+
LogFailed: true,
1056+
ExitStatus: true,
1057+
},
1058+
httpStubs: func(reg *httpmock.Registry) {
1059+
reg.Register(
1060+
httpmock.REST("GET", "repos/OWNER/REPO/actions/runs/1234"),
1061+
httpmock.JSONResponse(shared.FailedRun))
1062+
reg.Register(
1063+
httpmock.REST("GET", "runs/1234/jobs"),
1064+
httpmock.JSONResponse(shared.JobsPayload{
1065+
Jobs: []shared.Job{
1066+
shared.SuccessfulJob,
1067+
shared.FailedJob,
1068+
},
1069+
}))
1070+
reg.Register(
1071+
httpmock.REST("GET", "repos/OWNER/REPO/actions/runs/1234/logs"),
1072+
httpmock.BinaryResponse(zipArchive))
1073+
reg.Register(
1074+
httpmock.REST("GET", "repos/OWNER/REPO/actions/workflows/123"),
1075+
httpmock.JSONResponse(shared.TestWorkflow))
1076+
},
1077+
wantOut: quuxTheBarfLogOutput,
1078+
wantErr: true,
1079+
},
1080+
{
1081+
name: "exit status respected with log, failed run",
1082+
opts: &ViewOptions{
1083+
RunID: "1234",
1084+
Log: true,
1085+
ExitStatus: true,
1086+
},
1087+
httpStubs: func(reg *httpmock.Registry) {
1088+
reg.Register(
1089+
httpmock.REST("GET", "repos/OWNER/REPO/actions/runs/1234"),
1090+
httpmock.JSONResponse(shared.FailedRun))
1091+
reg.Register(
1092+
httpmock.REST("GET", "runs/1234/jobs"),
1093+
httpmock.JSONResponse(shared.JobsPayload{
1094+
Jobs: []shared.Job{
1095+
shared.SuccessfulJob,
1096+
shared.FailedJob,
1097+
},
1098+
}))
1099+
reg.Register(
1100+
httpmock.REST("GET", "repos/OWNER/REPO/actions/runs/1234/logs"),
1101+
httpmock.BinaryResponse(zipArchive))
1102+
reg.Register(
1103+
httpmock.REST("GET", "repos/OWNER/REPO/actions/workflows/123"),
1104+
httpmock.JSONResponse(shared.TestWorkflow))
1105+
},
1106+
wantOut: expectedRunLogOutput,
1107+
wantErr: true,
1108+
},
10511109
{
10521110
name: "interactive with log, with no step logs available (#10551)",
10531111
tty: true,

0 commit comments

Comments
 (0)