From 628ade89a77f471d6bed3391d7f0f8776723cd33 Mon Sep 17 00:00:00 2001 From: Rachel Evans Date: Thu, 28 Mar 2024 12:32:22 +0100 Subject: [PATCH] Anchor the log filename to the start --- pkg/cmd/run/view/fixtures/run_log.zip | Bin 2437 -> 2656 bytes pkg/cmd/run/view/view.go | 2 +- pkg/cmd/run/view/view_test.go | 20 +++++++++++++++++--- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/pkg/cmd/run/view/fixtures/run_log.zip b/pkg/cmd/run/view/fixtures/run_log.zip index 5b0bb1e306642f9633f9c1b7d41ba4e665dab0e6..e298df38649fae359e8f6576705b58490b6276e3 100644 GIT binary patch delta 626 zcmZn_ejqZzmzRNogF$gyN07jyl5CNQQ89wdEFugbK}opa^_a=djNzy%CogBrUxuh0|VHx0p7?4Jp1}F zffHx|2umRhFpN)1EJ{--$w*ZwEG@0jE2$`fnJJsbh-qkfMq){7S!xm2)P z$jW6`WO~auc>=o!kaLq=kg;8?y2@W@)I(|+? z#^?gYALBG4EH1^{cJhqC|x delta 423 zcmaDL(keW`mzRTqgF$gyM-T%DOpJ7&b9kG6Gdiw6a|O4#;JZK(-F9YO)t|HxD}pcgFz> zQ=qB}hRGM1{lL}*z+5z0hXuF0ec`HRvc&MAIGkbfMAmplj>#WcGg!f1ob1Rc%X|bF z4i{}E|6}Kxe1uJb*^v>bj8SazUp5V}QsK##?0n2qz@i>NRUAOk+3bqUvP=+l3QU?% zQ9EYw$#NWAjOCLxIm(!nStc*!Faj!8U=g4E8YrAO`5T8DkZ;SW$oOn>Jg0*QD;p?S PxPXv{g@GZN6~qGod%skS diff --git a/pkg/cmd/run/view/view.go b/pkg/cmd/run/view/view.go index c54905422..cc9aa0981 100644 --- a/pkg/cmd/run/view/view.go +++ b/pkg/cmd/run/view/view.go @@ -503,7 +503,7 @@ func logFilenameRegexp(job shared.Job, step shared.Step) *regexp.Regexp { // constructs a job name by constructing a job name of ` / `. This means that logs will // never be found for jobs that use composite actions. sanitizedJobName := strings.ReplaceAll(job.Name, "/", "") - re := fmt.Sprintf(`%s\/%d_.*\.txt`, regexp.QuoteMeta(sanitizedJobName), step.Number) + re := fmt.Sprintf(`^%s\/%d_.*\.txt`, regexp.QuoteMeta(sanitizedJobName), step.Number) return regexp.MustCompile(re) } diff --git a/pkg/cmd/run/view/view_test.go b/pkg/cmd/run/view/view_test.go index 1135212be..1f5d4df75 100644 --- a/pkg/cmd/run/view/view_test.go +++ b/pkg/cmd/run/view/view_test.go @@ -1374,9 +1374,11 @@ func TestViewRun(t *testing.T) { // ├── cool job/ // │ ├── 1_fob the barz.txt // │ └── 2_barz the fob.txt -// └── sad job/ -// ├── 1_barf the quux.txt -// └── 2_quux the barf.txt +// ├── sad job/ +// │ ├── 1_barf the quux.txt +// │ └── 2_quux the barf.txt +// └── ad job/ +// └── 1_barf the quux.txt func Test_attachRunLog(t *testing.T) { tests := []struct { name string @@ -1431,6 +1433,18 @@ func Test_attachRunLog(t *testing.T) { }, wantMatch: false, }, + { + name: "one job name is a suffix of another", + job: shared.Job{ + Name: "ad job", + Steps: []shared.Step{{ + Name: "barf the quux", + Number: 1, + }}, + }, + wantMatch: true, + wantFilename: "ad job/1_barf the quux.txt", + }, { name: "escape metacharacters in job name", job: shared.Job{