feat: add linter support for step-level depends_on existence (#4657)

This commit is contained in:
YR Chen 2025-01-12 14:32:03 +08:00 committed by GitHub
parent d818ad3001
commit 5e75e4ec9c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 30 additions and 0 deletions

View file

@ -161,11 +161,37 @@ func (l *Linter) lintContainers(config *WorkflowConfig, area string) error {
if err := l.lintContainerDeprecations(config, container, area); err != nil {
linterErr = multierr.Append(linterErr, err)
}
if err := l.lintDependsOn(config, container, area); err != nil {
linterErr = multierr.Append(linterErr, err)
}
}
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 {
if len(c.Image) == 0 {
return newLinterError("Invalid or missing image", config.File, fmt.Sprintf("%s.%s", area, c.Name), false)

View file

@ -185,6 +185,10 @@ func TestLintErrors(t *testing.T) {
from: "steps: { build: { image: golang, secrets: [ 'mysql_username' ] } }",
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 {