mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2025-02-13 09:55:14 +00:00
feat: add linter support for step-level depends_on
existence (#4657)
This commit is contained in:
parent
d818ad3001
commit
5e75e4ec9c
2 changed files with 30 additions and 0 deletions
|
@ -161,11 +161,37 @@ func (l *Linter) lintContainers(config *WorkflowConfig, area string) error {
|
||||||
if err := l.lintContainerDeprecations(config, container, area); err != nil {
|
if err := l.lintContainerDeprecations(config, container, area); err != nil {
|
||||||
linterErr = multierr.Append(linterErr, err)
|
linterErr = multierr.Append(linterErr, err)
|
||||||
}
|
}
|
||||||
|
if err := l.lintDependsOn(config, container, area); err != nil {
|
||||||
|
linterErr = multierr.Append(linterErr, err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return linterErr
|
return linterErr
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (l *Linter) lintDependsOn(config *WorkflowConfig, c *types.Container, area string) error {
|
||||||
|
if area != "steps" {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
var linterErr error
|
||||||
|
check:
|
||||||
|
for _, dep := range c.DependsOn {
|
||||||
|
for _, step := range config.Workflow.Steps.ContainerList {
|
||||||
|
if dep == step.Name {
|
||||||
|
continue check
|
||||||
|
}
|
||||||
|
}
|
||||||
|
linterErr = multierr.Append(linterErr,
|
||||||
|
newLinterError(
|
||||||
|
"One or more of the specified dependencies do not exist",
|
||||||
|
config.File, fmt.Sprintf("%s.%s.depends_on", area, c.Name), false,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
return linterErr
|
||||||
|
}
|
||||||
|
|
||||||
func (l *Linter) lintImage(config *WorkflowConfig, c *types.Container, area string) error {
|
func (l *Linter) lintImage(config *WorkflowConfig, c *types.Container, area string) error {
|
||||||
if len(c.Image) == 0 {
|
if len(c.Image) == 0 {
|
||||||
return newLinterError("Invalid or missing image", config.File, fmt.Sprintf("%s.%s", area, c.Name), false)
|
return newLinterError("Invalid or missing image", config.File, fmt.Sprintf("%s.%s", area, c.Name), false)
|
||||||
|
|
|
@ -185,6 +185,10 @@ func TestLintErrors(t *testing.T) {
|
||||||
from: "steps: { build: { image: golang, secrets: [ 'mysql_username' ] } }",
|
from: "steps: { build: { image: golang, secrets: [ 'mysql_username' ] } }",
|
||||||
want: "Usage of `secrets` is deprecated, use `environment` in combination with `from_secret`",
|
want: "Usage of `secrets` is deprecated, use `environment` in combination with `from_secret`",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
from: "steps: { build: { image: golang }, publish: { image: golang, depends_on: [ binary ] } }",
|
||||||
|
want: "One or more of the specified dependencies do not exist",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range testdata {
|
for _, test := range testdata {
|
||||||
|
|
Loading…
Reference in a new issue