Files
glint/internal/linter/dependencies.go
T
k3nny 416659ffd8
ci / vet, staticcheck, test, build (push) Failing after 1m54s
release / Build and publish release (push) Successful in 1m6s
feat(linter): context-scoped needs:/dependencies: cross-checks
When glint check runs in single-context mode (--branch, --tag, --source,
or --var), jobs that resolve to JobSkipped against that context are now
excluded from needs: and dependencies: cross-job checks (GL027-GL031).
This eliminates false-positive errors for jobs intentionally gated to
specific pipeline events (e.g. a deploy job with rules:if: CI_COMMIT_TAG
no longer triggers GL027 on branch pipelines).

linter.Lint now accepts a skipped map[string]bool (nil = check all jobs);
checkNeeds and checkDependencies skip jobs present in the map. Multi-context
mode (--context) passes nil, so all jobs are checked regardless of context.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-25 00:25:09 +02:00

54 lines
1.3 KiB
Go

package linter
import (
"fmt"
"git.k3nny.fr/glint/internal/model"
)
func checkDependencies(p *model.Pipeline, skipped map[string]bool) []Finding {
stageIndex := make(map[string]int, len(p.Stages))
for i, s := range p.Stages {
stageIndex[s] = i
}
var findings []Finding
for name, job := range p.Jobs {
if skipped[name] {
continue
}
if len(job.Dependencies) == 0 {
continue
}
jobStageIdx, jobHasStage := stageIndex[job.Stage]
for _, dep := range job.Dependencies {
depJob, exists := p.Jobs[dep]
if !exists {
findings = append(findings, Finding{
Severity: Error,
Rule: RuleUnknownDependency,
Job: name,
File: job.File,
Line: job.Line,
Message: fmt.Sprintf("'dependencies' references unknown job %q", dep),
})
continue
}
if len(p.Stages) > 0 && jobHasStage && depJob.Stage != "" {
depIdx, depHasStage := stageIndex[depJob.Stage]
if depHasStage && depIdx >= jobStageIdx {
findings = append(findings, Finding{
Severity: Error,
Rule: RuleDependencyStage,
Job: name,
File: job.File,
Line: job.Line,
Message: fmt.Sprintf("'dependencies' job %q must be in an earlier stage (in %q, current job is in %q)", dep, depJob.Stage, job.Stage),
})
}
}
}
}
return findings
}