woodpecker-helm3/internal/run/lint.go

64 lines
1.2 KiB
Go
Raw Normal View History

package run
import (
2019-12-18 00:55:01 +00:00
"fmt"
)
// Lint is an execution step that calls `helm lint` when executed.
type Lint struct {
Chart string
Values string
StringValues string
ValuesFiles []string
Strict bool
cmd cmd
}
// Execute executes the `helm lint` command.
func (l *Lint) Execute(_ Config) error {
return l.cmd.Run()
}
// Prepare gets the Lint ready to execute.
func (l *Lint) Prepare(cfg Config) error {
if l.Chart == "" {
return fmt.Errorf("chart is required")
}
2019-12-18 00:55:01 +00:00
args := make([]string, 0)
if cfg.Namespace != "" {
args = append(args, "--namespace", cfg.Namespace)
}
2019-12-18 00:55:01 +00:00
if cfg.Debug {
args = append(args, "--debug")
}
args = append(args, "lint")
if l.Values != "" {
args = append(args, "--set", l.Values)
}
if l.StringValues != "" {
args = append(args, "--set-string", l.StringValues)
}
for _, vFile := range l.ValuesFiles {
args = append(args, "--values", vFile)
}
if l.Strict {
args = append(args, "--strict")
}
args = append(args, l.Chart)
l.cmd = command(helmBin, args...)
l.cmd.Stdout(cfg.Stdout)
l.cmd.Stderr(cfg.Stderr)
2019-12-18 00:55:01 +00:00
if cfg.Debug {
fmt.Fprintf(cfg.Stderr, "Generated command: '%s'\n", l.cmd.String())
}
return nil
}