mirror of
https://code.forgejo.org/forgejo/runner.git
synced 2025-10-05 19:30:59 +00:00
fix: forgejo-runner validate exit with error when validation fails
Refs forgejo/runner#1002
This commit is contained in:
parent
bcf2bfbf20
commit
8c6c089a65
2 changed files with 33 additions and 24 deletions
|
@ -50,12 +50,13 @@ func validate(dir, path string, isWorkflow, isAction bool) error {
|
|||
kind = "action"
|
||||
}
|
||||
if err != nil {
|
||||
fmt.Printf("%s %s schema validation failed:\n%s\n", shortPath, kind, err.Error())
|
||||
err = fmt.Errorf("%s %s schema validation failed:\n%s", shortPath, kind, err.Error())
|
||||
fmt.Printf("%s\n", err.Error())
|
||||
} else {
|
||||
fmt.Printf("%s %s schema validation OK\n", shortPath, kind)
|
||||
}
|
||||
|
||||
return nil
|
||||
return err
|
||||
}
|
||||
|
||||
func validatePath(validateArgs *validateArgs) error {
|
||||
|
@ -115,6 +116,8 @@ func validateRepository(validateArgs *validateArgs) error {
|
|||
}
|
||||
}
|
||||
|
||||
var validationErrors error
|
||||
|
||||
if err := filepath.Walk(clonedir, func(path string, fi fs.FileInfo, err error) error {
|
||||
if validatePathMatch(path, ".forgejo/workflows/action") {
|
||||
return nil
|
||||
|
@ -123,7 +126,7 @@ func validateRepository(validateArgs *validateArgs) error {
|
|||
isAction := true
|
||||
if validatePathMatch(path, "action") {
|
||||
if err := validate(clonedir, path, isWorkflow, isAction); err != nil {
|
||||
return err
|
||||
validationErrors = errors.Join(validationErrors, err)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
@ -141,9 +144,9 @@ func validateRepository(validateArgs *validateArgs) error {
|
|||
if err := filepath.Walk(workflowdir, func(path string, fi fs.FileInfo, err error) error {
|
||||
isWorkflow := true
|
||||
isAction := false
|
||||
if validateHasYamlSuffix(path, "") {
|
||||
if validateHasYamlSuffix(path) {
|
||||
if err := validate(clonedir, path, isWorkflow, isAction); err != nil {
|
||||
return err
|
||||
validationErrors = errors.Join(validationErrors, err)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
@ -152,7 +155,7 @@ func validateRepository(validateArgs *validateArgs) error {
|
|||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
return validationErrors
|
||||
}
|
||||
|
||||
func processDirectory(validateArgs *validateArgs) {
|
||||
|
|
|
@ -59,6 +59,7 @@ func Test_validateCmd(t *testing.T) {
|
|||
name: "PathActionNOK",
|
||||
args: []string{"--action", "--path", "testdata/validate/bad-action.yml"},
|
||||
stdOut: "Expected a mapping got scalar",
|
||||
message: "testdata/validate/bad-action.yml action schema validation failed",
|
||||
},
|
||||
{
|
||||
name: "PathWorkflowOK",
|
||||
|
@ -69,6 +70,7 @@ func Test_validateCmd(t *testing.T) {
|
|||
name: "PathWorkflowNOK",
|
||||
args: []string{"--workflow", "--path", "testdata/validate/bad-workflow.yml"},
|
||||
stdOut: "Unknown Property ruins-on",
|
||||
message: "testdata/validate/bad-workflow.yml workflow schema validation failed",
|
||||
},
|
||||
{
|
||||
name: "DirectoryOK",
|
||||
|
@ -79,11 +81,13 @@ func Test_validateCmd(t *testing.T) {
|
|||
name: "DirectoryActionNOK",
|
||||
args: []string{"--directory", "testdata/validate/bad-directory"},
|
||||
stdOut: "action.yml action schema validation failed",
|
||||
message: "action.yml action schema validation failed",
|
||||
},
|
||||
{
|
||||
name: "DirectoryWorkflowNOK",
|
||||
args: []string{"--directory", "testdata/validate/bad-directory"},
|
||||
stdOut: ".forgejo/workflows/workflow1.yml workflow schema validation failed",
|
||||
message: ".forgejo/workflows/workflow1.yml workflow schema validation failed",
|
||||
},
|
||||
{
|
||||
name: "RepositoryOK",
|
||||
|
@ -94,11 +98,13 @@ func Test_validateCmd(t *testing.T) {
|
|||
name: "RepositoryActionNOK",
|
||||
args: []string{"--repository", "testdata/validate/bad-repository"},
|
||||
stdOut: "action.yml action schema validation failed",
|
||||
message: "action.yml action schema validation failed",
|
||||
},
|
||||
{
|
||||
name: "RepositoryWorkflowNOK",
|
||||
args: []string{"--repository", "testdata/validate/bad-repository"},
|
||||
stdOut: ".forgejo/workflows/workflow1.yml workflow schema validation failed",
|
||||
message: ".forgejo/workflows/workflow1.yml workflow schema validation failed",
|
||||
},
|
||||
} {
|
||||
t.Run(testCase.name, func(t *testing.T) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue