Rediscover Go settings only when Go work needs them

This commit is contained in:
2026-10-10 14:11:48 +00:00
parent 9333573cd8
commit c8eb64adec
8 changed files with 104 additions and 48 deletions

View File

@@ -18,6 +18,44 @@ import (
const releaseNote = "# Sample App v1.2.3\n\nA source release.\n\nUpgrade notes stay intact.\n"
func TestCandidateOperationsDiscoverGoOnlyWhenLaterWorkNeedsIt(t *testing.T) {
gitPath := mustLookPath(t, "git")
gitOnly := t.TempDir()
if err := os.Symlink(gitPath, filepath.Join(gitOnly, "git")); err != nil {
t.Fatal(err)
}
for _, operation := range []string{"check", "publish"} {
for _, withBuild := range []bool{false, true} {
t.Run(fmt.Sprintf("%s/build=%t", operation, withBuild), func(t *testing.T) {
repo := newPublishFixture(t)
request := releasekit.ReleaseRequest{
RepositoryDir: repo.work, Product: "Sample App", Version: "v1.2.3",
AdditionalChecks: func(context.Context, releasekit.Candidate) error {
t.Setenv("PATH", gitOnly)
return nil
},
}
if withBuild {
request.Build = &releasekit.BuildSpec{MainPackage: ".", BinaryName: "fixture", Targets: []releasekit.Target{{OS: "linux", Arch: "amd64"}}}
}
var err error
if operation == "check" {
_, err = releasekit.Check(context.Background(), request)
} else {
_, err = releasekit.Publish(context.Background(), request)
}
if withBuild {
if !errors.Is(err, exec.ErrNotFound) {
t.Fatalf("later build did not rediscover changed Go inputs: %v", err)
}
} else if err != nil {
t.Fatalf("finished Go work added a discovery gate: %v", err)
}
})
}
}
}
func TestPublishPushesOnlyTheCapturedAnnotatedTag(t *testing.T) {
repo := newPublishFixture(t)
wrapper := installGitWrapper(t, repo, "pass")