Merge origin/main; aliases share the skipped-set purge
ci/woodpecker/pr/build Pipeline was successful
ci/woodpecker/pr/test Pipeline was successful
ci/woodpecker/pr/lint Pipeline was successful
ci/woodpecker/pr/pre-commit Pipeline was successful

This commit is contained in:
2026-11-08 22:00:36 +11:00
+25 -18
View File
@@ -273,13 +273,12 @@ func (d *Deployer) Deploy(ctx context.Context, only []string, modules bool) erro
return errors.Join(errs...)
}
// srcPlan is a source's resolved envs, the branches that got none and why, names lost to collisions, and the envs to build (nil = all).
// srcPlan is a source's resolved envs, the branches that got none and why, and the envs to build (nil = all).
type srcPlan struct {
s *Source
envs map[string]envRef
skipped map[string]error
collided map[string]bool
want map[string]bool
s *Source
envs map[string]envRef
skipped map[string]error
want map[string]bool
}
// selectEnvs resolves args to envs as a full deploy would: env names in any source first, else raw branch names.
@@ -383,11 +382,11 @@ func (d *Deployer) count(outcome string) {
type envRef struct{ branch, sha string }
// Environments maps env name -> branch and sha, each branch that gets no env to why, and the names no branch won because only corrected branches claimed them.
func (d *Deployer) Environments(ctx context.Context, s *Source) (map[string]envRef, map[string]error, map[string]bool, error) {
// Environments maps env name -> branch and sha, and each branch that gets no env to why.
func (d *Deployer) Environments(ctx context.Context, s *Source) (map[string]envRef, map[string]error, error) {
all, err := d.branches(ctx, d.srcMirror(s))
if err != nil {
return nil, nil, nil, err
return nil, nil, err
}
names := make([]string, 0, len(all))
for b := range all {
@@ -396,7 +395,7 @@ func (d *Deployer) Environments(ctx context.Context, s *Source) (map[string]envR
sort.Strings(names)
claims := map[string][]string{}
exact := map[string]string{}
skipped, collided := map[string]error{}, map[string]bool{}
skipped := map[string]error{}
for _, b := range names {
if s.Ignored(b) {
continue
@@ -423,7 +422,6 @@ func (d *Deployer) Environments(ctx context.Context, s *Source) (map[string]envR
for _, b := range bs {
skipped[b] = err
}
collided[name] = true
continue
}
for _, b := range bs {
@@ -433,7 +431,7 @@ func (d *Deployer) Environments(ctx context.Context, s *Source) (map[string]envR
}
envs[name] = envRef{win, all[win]}
}
return envs, skipped, collided, nil
return envs, skipped, nil
}
func (d *Deployer) planSource(ctx context.Context, s *Source) (*srcPlan, error) {
@@ -444,9 +442,9 @@ func (d *Deployer) planSource(ctx context.Context, s *Source) (*srcPlan, error)
return nil, err
}
bctx, end := d.phase(ctx, "source.branches", "source", s.Name)
envs, skipped, collided, err := d.Environments(bctx, s)
envs, skipped, err := d.Environments(bctx, s)
end("envs", len(envs))
return &srcPlan{s: s, envs: envs, skipped: skipped, collided: collided}, err
return &srcPlan{s: s, envs: envs, skipped: skipped}, err
}
func (d *Deployer) deploySource(ctx context.Context, p *srcPlan, modules bool) error {
@@ -484,7 +482,7 @@ func (d *Deployer) deploySource(ctx context.Context, p *srcPlan, modules bool) e
}
wg.Wait()
if full {
errs = append(errs, d.purge(s, p.envs, p.collided))
errs = append(errs, d.purge(s, p.envs, p.skipped))
}
return errors.Join(errs...)
}
@@ -903,18 +901,27 @@ func Swap(target, link string) error {
return os.Rename(tmp, link)
}
// purge removes owned links of envs that no longer resolve, keeping collided envs and their aliases as they are.
func (d *Deployer) purge(s *Source, envs map[string]envRef, collided map[string]bool) error {
// purge removes owned envs no branch claims; a name only skipped branches claim keeps its live env, as do its aliases.
func (d *Deployer) purge(s *Source, envs map[string]envRef, skipped map[string]error) error {
entries, err := os.ReadDir(s.Basedir)
if err != nil {
return err
}
keep := map[string]bool{}
for name := range envs {
keep[name] = true
}
for b := range skipped {
if name, _, err := s.EnvName(b); err == nil {
keep[name] = true
}
}
for _, e := range entries {
name := e.Name()
if t, ok := d.cfg.W10k.Aliases[name]; ok {
name = t
}
if _, ok := envs[name]; ok || collided[name] {
if keep[name] {
continue
}
link := filepath.Join(s.Basedir, e.Name())