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:
parent
89f37985bd
commit
bcf2bfbf20
2 changed files with 22 additions and 4 deletions
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue