Skip to content

Commit

Permalink
fix(pipeline): validate presence of tag on tag events to avoid panic (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
ecrupper authored Feb 9, 2024
1 parent 08b96be commit ddb971f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
5 changes: 5 additions & 0 deletions action/pipeline/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/go-vela/cli/internal/output"
"github.com/go-vela/sdk-go/vela"
"github.com/go-vela/types/constants"
"github.com/go-vela/types/library"

"github.com/go-vela/server/compiler"
Expand Down Expand Up @@ -69,6 +70,10 @@ func (c *Config) Validate() error {
return fmt.Errorf("invalid format for template file: %s (valid format: <name>:<source>)", file)
}
}
case "exec":
if strings.EqualFold(c.Event, constants.EventTag) && len(c.Tag) == 0 {
return fmt.Errorf("no tag provided for tag event")
}
}

return nil
Expand Down
19 changes: 19 additions & 0 deletions action/pipeline/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,25 @@ func TestPipeline_Config_Validate(t *testing.T) {
Output: "",
},
},
{
failure: true,
config: &Config{
Action: "exec",
Org: "github",
Repo: "octocat",
Event: "tag",
},
},
{
failure: false,
config: &Config{
Action: "exec",
Org: "github",
Repo: "octocat",
Event: "tag",
Tag: "v1.0.0",
},
},
{
failure: false,
config: &Config{
Expand Down

0 comments on commit ddb971f

Please sign in to comment.