feat(build): summer plugin:update
- module installs move to the newest compatible registry release with one go get; submodules fetch tags, check out the release tag and require it in go.mod; go.work overrides and version pins are refreshed - unlisted submodules (git URL installs) update from their own tags and plugin.yaml; --offline restricts to that - without an ID every plugin that resolves is updated; in-app, unlisted and incompatible ones are reported; failure only when a resolved update cannot be carried out - same prompt rule as plugin:install
This commit is contained in:
@@ -615,6 +615,230 @@ func TestInstallSmoke(t *testing.T) {
|
||||
}
|
||||
})
|
||||
|
||||
// plugin:update. tagRelease adds a tagged release to a fixture repo.
|
||||
tagRelease := func(t *testing.T, repoURL, id, module string, rel fixtureRelease) {
|
||||
t.Helper()
|
||||
dir := strings.TrimPrefix(repoURL, "file://")
|
||||
for name, body := range pluginRepoFiles(t, id, module, rel) {
|
||||
write(t, filepath.Join(dir, name), body)
|
||||
}
|
||||
write(t, filepath.Join(dir, "CHANGES"), "release "+rel.Tag+"\n")
|
||||
runTestGit(t, dir, "add", "-A")
|
||||
runTestGit(t, dir, "commit", "--quiet", "-m", "release "+rel.Tag)
|
||||
runTestGit(t, dir, "tag", rel.Tag)
|
||||
}
|
||||
requireOf := func(t *testing.T, app, module string) string {
|
||||
t.Helper()
|
||||
gomod, err := editJSON(t.Context(), app, "mod", "edit", "-json", filepath.Join(app, "go.mod"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, r := range gomod.Require {
|
||||
if r.Path == module {
|
||||
return r.Version
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
// sourceApp is a git app with acme.blog v0.1.0 installed with --source.
|
||||
sourceApp := func(t *testing.T) (app, blogRepo string, reg *fakeReg) {
|
||||
t.Helper()
|
||||
blogRepo = pluginRepo(t, "acme.blog", blogModule, []fixtureRelease{{Tag: "v0.1.0", Framework: "v0.5.0"}}, nil)
|
||||
app = gitApp(t)
|
||||
reg = fakeRegistry(t, map[string]fakePlugin{
|
||||
"acme.blog": regPlugin("acme.blog", blogRepo, regVersion("v0.1.0", "v0.5.0", blogModule, blogModule, nil)),
|
||||
})
|
||||
plan, err := PlanInstall(t.Context(), InstallOptions{StartDir: app, Arg: "acme.blog", Source: true, Yes: true, Registry: reg.Client})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := ApplyInstall(t.Context(), plan, nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return app, blogRepo, reg
|
||||
}
|
||||
|
||||
t.Run("update", func(t *testing.T) {
|
||||
if testing.Short() {
|
||||
t.Skip("installs from a file:// module proxy")
|
||||
}
|
||||
app := helloCopy(t)
|
||||
proxy := t.TempDir()
|
||||
for _, v := range []string{"v0.1.0", "v0.1.1"} {
|
||||
writeProxyModule(t, proxy, blogModule, v, fixturePluginFiles(blogModule, "blog", "acme.blog", "v0.5.0"))
|
||||
}
|
||||
offlineGoEnv(t, proxy)
|
||||
reg := fakeRegistry(t, map[string]fakePlugin{"acme.blog": regPlugin("acme.blog", "", blogV1)})
|
||||
plan, err := PlanInstall(t.Context(), InstallOptions{StartDir: app, Arg: "acme.blog", Yes: true, Registry: reg.Client})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := ApplyInstall(t.Context(), plan, nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
reg.set("acme.blog", regPlugin("acme.blog", "",
|
||||
regVersion("v0.3.0", "v9.0.0", blogModule, blogModule, nil),
|
||||
regVersion("v0.1.1", "v0.5.0", blogModule, blogModule, nil),
|
||||
blogV1))
|
||||
var out bytes.Buffer
|
||||
if err := Update(t.Context(), UpdateOptions{StartDir: app, ID: "acme.blog", Yes: true, Registry: reg.Client, Out: &out}); err != nil {
|
||||
t.Fatalf("update: %v\n%s", err, out.String())
|
||||
}
|
||||
if got := requireOf(t, app, blogModule); got != "v0.1.1" {
|
||||
t.Fatalf("go.mod requires %s %s, want v0.1.1\n%s", blogModule, got, out.String())
|
||||
}
|
||||
if !strings.Contains(out.String(), "acme.blog v0.1.0 -> v0.1.1 (module)") {
|
||||
t.Fatalf("update output:\n%s", out.String())
|
||||
}
|
||||
out.Reset()
|
||||
if err := Update(t.Context(), UpdateOptions{StartDir: app, ID: "acme.blog", Yes: true, Registry: reg.Client, Out: &out}); err != nil {
|
||||
t.Fatalf("second update: %v\n%s", err, out.String())
|
||||
}
|
||||
if got := requireOf(t, app, blogModule); got != "v0.1.1" {
|
||||
t.Fatalf("second update moved to %s", got)
|
||||
}
|
||||
if !strings.Contains(out.String(), "v0.3.0 needs framework v9.0.0") {
|
||||
t.Fatalf("second update does not report the incompatible release:\n%s", out.String())
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("update_submodule", func(t *testing.T) {
|
||||
if testing.Short() {
|
||||
t.Skip("clones fixture repositories and builds the app")
|
||||
}
|
||||
gitTestEnv(t)
|
||||
app, blogRepo, reg := sourceApp(t)
|
||||
tagRelease(t, blogRepo, "acme.blog", blogModule, fixtureRelease{Tag: "v0.1.1", Framework: "v0.5.0"})
|
||||
reg.set("acme.blog", regPlugin("acme.blog", blogRepo,
|
||||
regVersion("v0.1.1", "v0.5.0", blogModule, blogModule, nil),
|
||||
regVersion("v0.1.0", "v0.5.0", blogModule, blogModule, nil)))
|
||||
var out bytes.Buffer
|
||||
if err := Update(t.Context(), UpdateOptions{StartDir: app, ID: "acme.blog", Yes: true, Registry: reg.Client, Out: &out}); err != nil {
|
||||
t.Fatalf("update: %v\n%s", err, out.String())
|
||||
}
|
||||
if got := gitOut(t, filepath.Join(app, "plugins", "acme", "blog"), "describe", "--tags"); got != "v0.1.1" {
|
||||
t.Fatalf("submodule at %s, want v0.1.1\n%s", got, out.String())
|
||||
}
|
||||
if got := requireOf(t, app, blogModule); got != "v0.1.1" {
|
||||
t.Fatalf("go.mod requires %s, want v0.1.1", got)
|
||||
}
|
||||
if !strings.Contains(out.String(), "acme.blog v0.1.0 -> v0.1.1 (submodule)") {
|
||||
t.Fatalf("update output:\n%s", out.String())
|
||||
}
|
||||
buildApp(t, app)
|
||||
|
||||
// A go.work pin of a module to one of its own versions follows the
|
||||
// app's require when that moves.
|
||||
if err := runGo(t.Context(), app, "work", "edit", "-replace="+translateModule+"="+translateModule+"@v0.1.0"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := runGo(t.Context(), app, "mod", "edit", "-require="+translateModule+"@v0.2.0"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := refreshWorkOverrides(t.Context(), app, &out); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
work, _ := os.ReadFile(filepath.Join(app, "go.work"))
|
||||
if !bytes.Contains(work, []byte(translateModule+" => "+translateModule+" v0.2.0")) {
|
||||
t.Fatalf("pin not refreshed:\n%s", work)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("update_all", func(t *testing.T) {
|
||||
if testing.Short() {
|
||||
t.Skip("clones fixture repositories")
|
||||
}
|
||||
gitTestEnv(t)
|
||||
app, blogRepo, reg := sourceApp(t)
|
||||
// acme.translate from a git URL: not in the registry, updated from
|
||||
// its own tags.
|
||||
translateRepo := pluginRepo(t, "acme.translate", translateModule, []fixtureRelease{{Tag: "v0.1.0", Framework: "v0.5.0"}}, nil)
|
||||
plan, err := PlanInstall(t.Context(), InstallOptions{StartDir: app, Arg: translateRepo, Yes: true, Registry: reg.Client})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := ApplyInstall(t.Context(), plan, nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
// acme.ghost: a module install the registry does not list.
|
||||
if err := appendManifestPlugins(filepath.Join(app, manifestName), []Plugin{{ID: "acme.ghost", Module: "example.com/acme/ghost"}}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := runGo(t.Context(), app, "mod", "edit", "-require=example.com/acme/ghost@v0.1.0"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
tagRelease(t, blogRepo, "acme.blog", blogModule, fixtureRelease{Tag: "v0.1.1", Framework: "v0.5.0"})
|
||||
tagRelease(t, translateRepo, "acme.translate", translateModule, fixtureRelease{Tag: "v0.1.1", Framework: "v0.5.0"})
|
||||
tagRelease(t, translateRepo, "acme.translate", translateModule, fixtureRelease{Tag: "v0.2.0", Framework: "v9.0.0"})
|
||||
reg.set("acme.blog", regPlugin("acme.blog", blogRepo,
|
||||
regVersion("v0.1.1", "v0.5.0", blogModule, blogModule, nil),
|
||||
regVersion("v0.1.0", "v0.5.0", blogModule, blogModule, nil)))
|
||||
|
||||
var out bytes.Buffer
|
||||
if err := Update(t.Context(), UpdateOptions{StartDir: app, Yes: true, Registry: reg.Client, Out: &out}); err != nil {
|
||||
t.Fatalf("update all: %v\n%s", err, out.String())
|
||||
}
|
||||
for _, want := range []string{
|
||||
"acme.blog v0.1.0 -> v0.1.1 (submodule)",
|
||||
"acme.translate v0.1.0 -> v0.1.1 (submodule)",
|
||||
"golem15.hello: ",
|
||||
"acme.ghost: ",
|
||||
"v0.2.0 needs framework v9.0.0",
|
||||
} {
|
||||
if !strings.Contains(out.String(), want) {
|
||||
t.Fatalf("update all output lacks %q:\n%s", want, out.String())
|
||||
}
|
||||
}
|
||||
if got := gitOut(t, filepath.Join(app, "plugins", "acme", "translate"), "describe", "--tags"); got != "v0.1.1" {
|
||||
t.Fatalf("translate at %s, want v0.1.1", got)
|
||||
}
|
||||
|
||||
// A release the registry lists but the repository lacks makes the
|
||||
// run fail, naming the plugin; the other plugins are reported.
|
||||
reg.set("acme.blog", regPlugin("acme.blog", blogRepo,
|
||||
regVersion("v0.1.2", "v0.5.0", blogModule, blogModule, nil),
|
||||
regVersion("v0.1.1", "v0.5.0", blogModule, blogModule, nil)))
|
||||
out.Reset()
|
||||
err = Update(t.Context(), UpdateOptions{StartDir: app, Yes: true, Registry: reg.Client, Out: &out})
|
||||
if err == nil || !strings.Contains(err.Error(), "acme.blog") {
|
||||
t.Fatalf("failed update: err = %v\n%s", err, out.String())
|
||||
}
|
||||
if !strings.Contains(out.String(), "acme.ghost: ") {
|
||||
t.Fatalf("skipped plugins not reported:\n%s", out.String())
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("update_prompt", func(t *testing.T) {
|
||||
if testing.Short() {
|
||||
t.Skip("clones fixture repositories")
|
||||
}
|
||||
gitTestEnv(t)
|
||||
app, blogRepo, reg := sourceApp(t)
|
||||
tagRelease(t, blogRepo, "acme.blog", blogModule, fixtureRelease{Tag: "v0.1.1", Framework: "v0.5.0"})
|
||||
reg.set("acme.blog", regPlugin("acme.blog", blogRepo,
|
||||
regVersion("v0.1.1", "v0.5.0", blogModule, blogModule, nil),
|
||||
regVersion("v0.1.0", "v0.5.0", blogModule, blogModule, nil)))
|
||||
var out bytes.Buffer
|
||||
err := Update(t.Context(), UpdateOptions{StartDir: app, ID: "acme.blog", Registry: reg.Client, Out: &out})
|
||||
if err == nil || !strings.Contains(err.Error(), "--yes") || !strings.Contains(out.String(), "acme.blog v0.1.0 -> v0.1.1") {
|
||||
t.Fatalf("non-interactive update: err = %v\n%s", err, out.String())
|
||||
}
|
||||
err = Update(t.Context(), UpdateOptions{StartDir: app, ID: "acme.blog", Registry: reg.Client, Interactive: true,
|
||||
Confirm: func(string) (bool, error) { return false, nil }})
|
||||
if !errors.Is(err, ErrCancelled) {
|
||||
t.Fatalf("declined update: err = %v", err)
|
||||
}
|
||||
if got := gitOut(t, filepath.Join(app, "plugins", "acme", "blog"), "describe", "--tags"); got != "v0.1.0" {
|
||||
t.Fatalf("declined update moved the submodule to %s", got)
|
||||
}
|
||||
if got := requireOf(t, app, blogModule); got != "v0.1.0" {
|
||||
t.Fatalf("declined update changed go.mod to %s", got)
|
||||
}
|
||||
if err := Update(t.Context(), UpdateOptions{StartDir: app, ID: "acme.nope", Yes: true, Registry: reg.Client}); err == nil || !strings.Contains(err.Error(), "summer.yaml") {
|
||||
t.Fatalf("unknown ID: err = %v", err)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("append_manifest", func(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
path := filepath.Join(dir, manifestName)
|
||||
|
||||
Reference in New Issue
Block a user