Skip to content

Commit

Permalink
fix(golang-rewrite): allow missing post-plugin-update callback during…
Browse files Browse the repository at this point in the history
… plugin update (#1849)
  • Loading branch information
Stratus3D authored Jan 23, 2025
1 parent 40256bb commit 8b1b024
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
5 changes: 0 additions & 5 deletions docs/guide/upgrading-from-v0-15-to-v0-16.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@ rather than a set of scripts.

## Breaking Changes

### `download` is now a required callback for plugins

Previously `download` was optional, now it is required. If a plugin lacks this
callback any installs of any version of that plugin will fail.

### Hyphenated commands have been removed

asdf version 0.15.0 and earlier supported by hyphenated and non-hyphenated
Expand Down
2 changes: 1 addition & 1 deletion docs/plugins/create.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ The full list of scripts callable from asdf.
| Script | Description |
| :---------------------------------------------------------------------------------------------------- |:-----------------------------------------------------------------|
| [bin/list-all](#bin-list-all) <Badge type="tip" text="required" vertical="middle" /> | List all installable versions |
| [bin/download](#bin-download) <Badge type="tip" text="required" vertical="middle" /> | Download source code or binary for the specified version |
| [bin/download](#bin-download) <Badge type="warning" text="recommended" vertical="middle" /> | Download source code or binary for the specified version |
| [bin/install](#bin-install) <Badge type="tip" text="required" vertical="middle" /> | Installs the specified version |
| [bin/latest-stable](#bin-latest-stable) <Badge type="warning" text="recommended" vertical="middle" /> | List the latest stable version of the specified tool |
| [bin/help.overview](#bin-help.overview) | Output a general description about the plugin & tool |
Expand Down
5 changes: 4 additions & 1 deletion internal/plugins/plugins.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,11 +261,14 @@ func (p Plugin) Update(conf config.Config, ref string, out, errout io.Writer) (s
}

err = p.RunCallback("post-plugin-update", []string{}, env, out, errout)
if _, ok := err.(NoCallbackError); err != nil && !ok {
return newRef, err
}

hook.Run(conf, "post_asdf_plugin_update", []string{p.Name})
hook.Run(conf, fmt.Sprintf("post_asdf_plugin_update_%s", p.Name), []string{})

return newRef, err
return newRef, nil
}

// List takes config and flags for what to return and builds a list of plugins
Expand Down
14 changes: 13 additions & 1 deletion internal/plugins/plugins_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,13 @@ func TestUpdate(t *testing.T) {

repoPath, err := repotest.GeneratePlugin("dummy_plugin", testDataDir, testPluginName)
assert.Nil(t, err)
assert.Nil(t, Add(conf, testPluginName, repoPath, ""))

err = Add(conf, testPluginName, repoPath, "")
noPostUpdateCallbackPlugin := "no-post-update"
repoPath, err = repotest.GeneratePlugin("dummy_plugin", testDataDir, noPostUpdateCallbackPlugin)
assert.Nil(t, err)
assert.Nil(t, os.Remove(filepath.Join(repoPath, "bin", "post-plugin-update")))
assert.Nil(t, Add(conf, noPostUpdateCallbackPlugin, repoPath, ""))

badPluginName := "badplugin"
badRepo := data.PluginDirectory(testDataDir, badPluginName)
Expand Down Expand Up @@ -272,6 +276,14 @@ func TestUpdate(t *testing.T) {
wantSomeRef: true,
wantErrMsg: "",
},
{
desc: "updates plugin when plugin when post-plugin-update callback does not exist",
givenConf: conf,
givenName: noPostUpdateCallbackPlugin,
givenRef: "",
wantSomeRef: true,
wantErrMsg: "",
},
}

for _, tt := range tests {
Expand Down

0 comments on commit 8b1b024

Please sign in to comment.