From bcf2bfbf2054052e2f48a6dae6c3710bec4abd04 Mon Sep 17 00:00:00 2001 From: Earl Warren Date: Wed, 17 Sep 2025 15:37:07 +0200 Subject: [PATCH] fix: find action.y*ml at the root of the directory The lookup of action.y*ml files failed at the root of the directory when specified with . because it does not start with a / when walking the directory. --- internal/app/cmd/validate.go | 17 +++++++++++++---- internal/app/cmd/validate_test.go | 9 +++++++++ 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/internal/app/cmd/validate.go b/internal/app/cmd/validate.go index 474ff56f..49395000 100644 --- a/internal/app/cmd/validate.go +++ b/internal/app/cmd/validate.go @@ -65,8 +65,17 @@ func validatePath(validateArgs *validateArgs) error { return validate("", validateArgs.path, validateArgs.workflow, validateArgs.action) } -func validateHasYamlSuffix(s, suffix string) bool { - return strings.HasSuffix(s, suffix+".yml") || strings.HasSuffix(s, suffix+".yaml") +func validatePathMatch(existing, search string) bool { + if !validateHasYamlSuffix(existing) { + return false + } + existing = strings.TrimSuffix(existing, ".yml") + existing = strings.TrimSuffix(existing, ".yaml") + return existing == search || strings.HasSuffix(existing, "/"+search) +} + +func validateHasYamlSuffix(s string) bool { + return strings.HasSuffix(s, ".yml") || strings.HasSuffix(s, ".yaml") } func validateRepository(validateArgs *validateArgs) error { @@ -107,12 +116,12 @@ func validateRepository(validateArgs *validateArgs) error { } if err := filepath.Walk(clonedir, func(path string, fi fs.FileInfo, err error) error { - if validateHasYamlSuffix(path, "/.forgejo/workflows/action") { + if validatePathMatch(path, ".forgejo/workflows/action") { return nil } isWorkflow := false isAction := true - if validateHasYamlSuffix(path, "/action") { + if validatePathMatch(path, "action") { if err := validate(clonedir, path, isWorkflow, isAction); err != nil { return err } diff --git a/internal/app/cmd/validate_test.go b/internal/app/cmd/validate_test.go index 8a7c6c71..d620128b 100644 --- a/internal/app/cmd/validate_test.go +++ b/internal/app/cmd/validate_test.go @@ -10,6 +10,15 @@ import ( "github.com/stretchr/testify/assert" ) +func Test_validatePathMatch(t *testing.T) { + assert.False(t, validatePathMatch("nosuffix", "nosuffix")) + assert.True(t, validatePathMatch("something.yml", "something")) + assert.True(t, validatePathMatch("something.yaml", "something")) + assert.False(t, validatePathMatch("entire_something.yaml", "something")) + assert.True(t, validatePathMatch("nested/in/directory/something.yaml", "something")) + assert.False(t, validatePathMatch("nested/in/directory/entire_something.yaml", "something")) +} + func Test_validateCmd(t *testing.T) { ctx := context.Background() for _, testCase := range []struct {