1
0
Fork 0
mirror of https://code.forgejo.org/forgejo/runner.git synced 2025-10-15 19:42:06 +00:00

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.
This commit is contained in:
Earl Warren 2025-09-17 15:37:07 +02:00
parent 89f37985bd
commit bcf2bfbf20
No known key found for this signature in database
GPG key ID: 0579CB2928A78A00
2 changed files with 22 additions and 4 deletions

View file

@ -65,8 +65,17 @@ func validatePath(validateArgs *validateArgs) error {
return validate("", validateArgs.path, validateArgs.workflow, validateArgs.action) return validate("", validateArgs.path, validateArgs.workflow, validateArgs.action)
} }
func validateHasYamlSuffix(s, suffix string) bool { func validatePathMatch(existing, search string) bool {
return strings.HasSuffix(s, suffix+".yml") || strings.HasSuffix(s, suffix+".yaml") 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 { 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 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 return nil
} }
isWorkflow := false isWorkflow := false
isAction := true isAction := true
if validateHasYamlSuffix(path, "/action") { if validatePathMatch(path, "action") {
if err := validate(clonedir, path, isWorkflow, isAction); err != nil { if err := validate(clonedir, path, isWorkflow, isAction); err != nil {
return err return err
} }

View file

@ -10,6 +10,15 @@ import (
"github.com/stretchr/testify/assert" "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) { func Test_validateCmd(t *testing.T) {
ctx := context.Background() ctx := context.Background()
for _, testCase := range []struct { for _, testCase := range []struct {