Key typed worktrees on generate_types and the generator version
This commit is contained in:
@@ -262,10 +262,19 @@ func (d *Deployer) owned(s *Source, link string) string {
|
||||
return ""
|
||||
}
|
||||
|
||||
// worktreePrefix keys worktrees on everything besides modules that changes their content.
|
||||
func (d *Deployer) worktreePrefix(sha string) string {
|
||||
if d.cfg.W10k.GenerateTypes {
|
||||
return sha + "-types" + gentypes.Version + "-"
|
||||
}
|
||||
return sha + "-"
|
||||
}
|
||||
|
||||
func (d *Deployer) deployEnv(ctx context.Context, s *Source, name, sha string, modules bool) error {
|
||||
link := filepath.Join(s.Basedir, name)
|
||||
cur := d.owned(s, link)
|
||||
if cur != "" && !modules && strings.HasPrefix(filepath.Base(cur), sha+"-") && d.complete(cur) {
|
||||
prefix := d.worktreePrefix(sha)
|
||||
if base := filepath.Base(cur); cur != "" && !modules && strings.HasPrefix(base, prefix) && len(base) == len(prefix)+12 && d.complete(cur) {
|
||||
return nil
|
||||
}
|
||||
pf, checksum, err := d.puppetfile(ctx, d.srcMirror(s), sha)
|
||||
@@ -280,7 +289,7 @@ func (d *Deployer) deployEnv(ctx context.Context, s *Source, name, sha string, m
|
||||
for _, m := range mods {
|
||||
_, _ = fmt.Fprintf(h, "%s %s\n", m.path, m.key)
|
||||
}
|
||||
target := filepath.Join(d.srcWorktrees(s), sha+"-"+hex.EncodeToString(h.Sum(nil))[:12])
|
||||
target := filepath.Join(d.srcWorktrees(s), prefix+hex.EncodeToString(h.Sum(nil))[:12])
|
||||
if cur == target && d.complete(cur) {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -639,6 +639,34 @@ func TestGenerateTypesBeforeSwap(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestGenerateTypesToggleRedeploys(t *testing.T) {
|
||||
f := newFixture(t)
|
||||
commit(t, f.control, map[string]string{
|
||||
"environment.conf": "modulepath = site:$basemodulepath\n",
|
||||
"site/local/lib/puppet/type/local.rb": "Puppet::Type.newtype(:local) do\n newparam(:name)\nend\n",
|
||||
})
|
||||
f.mustDeploy(false)
|
||||
plain := f.env("main")
|
||||
if exists(filepath.Join(plain, ".resource_types")) {
|
||||
t.Fatal("types generated while generate_types is off")
|
||||
}
|
||||
f.cfg.W10k.GenerateTypes = true
|
||||
f.mustDeploy(false)
|
||||
typed := f.env("main")
|
||||
if typed == plain || !exists(filepath.Join(typed, ".resource_types", "local.pp")) {
|
||||
t.Fatalf("enabling generate_types must deploy a new worktree with types: %s", typed)
|
||||
}
|
||||
f.mustDeploy(false)
|
||||
if f.env("main") != typed {
|
||||
t.Fatal("an unchanged typed env must not be redeployed")
|
||||
}
|
||||
f.cfg.W10k.GenerateTypes = false
|
||||
f.mustDeploy(false)
|
||||
if f.env("main") != plain {
|
||||
t.Fatalf("disabling generate_types must return to the untyped worktree, got %s", f.env("main"))
|
||||
}
|
||||
}
|
||||
|
||||
func readFileT(t *testing.T, p string) string {
|
||||
t.Helper()
|
||||
b, err := os.ReadFile(p)
|
||||
|
||||
Reference in New Issue
Block a user