Warn about corrected branch names only for envs being deployed
ci/woodpecker/pr/build Pipeline was successful
ci/woodpecker/pr/test Pipeline was successful
ci/woodpecker/pr/pre-commit Pipeline was successful
ci/woodpecker/pr/lint Pipeline was successful

This commit is contained in:
2026-11-08 21:06:28 +11:00
parent 503db52306
commit 260dd4fc78
2 changed files with 11 additions and 4 deletions
+5 -4
View File
@@ -378,9 +378,6 @@ func (d *Deployer) Environments(ctx context.Context, s *Source) (map[string]envR
skipped[b] = fmt.Errorf("branch %s collides with environment %s, skipped", b, name)
}
}
if !isExact && s.InvalidBranches == "correct_and_warn" {
log.Printf("warning: branch %s deployed as environment %s", win, name)
}
envs[name] = envRef{win, all[win]}
}
return envs, skipped, nil
@@ -413,10 +410,14 @@ func (d *Deployer) deploySource(ctx context.Context, p *srcPlan, modules bool) e
}
var mu sync.Mutex
var wg sync.WaitGroup
for name, ref := range p.envs {
for _, name := range slices.Sorted(maps.Keys(p.envs)) {
ref := p.envs[name]
if !full && !p.want[name] {
continue
}
if _, corrected, _ := s.EnvName(ref.branch); corrected && s.InvalidBranches == "correct_and_warn" {
log.Printf("warning: branch %s deployed as environment %s", ref.branch, name)
}
wg.Add(1)
go func() {
defer wg.Done()
+6
View File
@@ -888,9 +888,15 @@ func TestNamedDeployPrefixedSources(t *testing.T) {
p := &Source{Name: "p", Remote: f.control, Basedir: pbase, Prefix: "p", InvalidBranches: "correct_and_warn"}
f.cfg.Sources["p"] = p
penv := func(name string) string { return f.deployer().owned(p, filepath.Join(pbase, name)) }
var logs bytes.Buffer
log.SetOutput(&logs)
defer log.SetOutput(os.Stderr)
if err := f.deploy(false, "main"); err != nil || f.env("main") == "" {
t.Fatalf("deploy main: %v", err)
}
if strings.Contains(logs.String(), "benvin/x") {
t.Fatalf("named deploy warned about a branch it did not deploy:\n%s", logs.String())
}
if penv("p_main") != "" {
t.Fatal("env name main also deployed branch main of source p as p_main")
}