Anchor the log filename to the start

This commit is contained in:
Rachel Evans 2024-03-28 12:32:22 +01:00
parent 1a102edb52
commit 628ade89a7
3 changed files with 18 additions and 4 deletions

View file

@ -503,7 +503,7 @@ func logFilenameRegexp(job shared.Job, step shared.Step) *regexp.Regexp {
// constructs a job name by constructing a job name of `<JOB_NAME`> / <ACTION_NAME>`. 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)
}

View file

@ -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{