Skip to content

Commit 902b966

Browse files
authored
[plugins] New github repo structure (#1290)
## Summary This follows the following plan: - No manifest - Use flake notation `github:org/repo/<revision>?dir=<dir>` - Use `plugin.json` as config file name TODO (in follow up): - Special case `plugin:<name>` to our own plugin repo. ## How was it tested? `devbox run run_test`
1 parent 6269239 commit 902b966

File tree

4 files changed

+18
-17
lines changed

4 files changed

+18
-17
lines changed

.github/workflows/cli-tests.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ jobs:
113113
DEVBOX_DEBUG: ${{ (!matrix.run-example-tests || inputs.example-debug) && '1' || '0' }}
114114
DEVBOX_EXAMPLE_TESTS: ${{ matrix.run-example-tests }}
115115
# Used in `go test -timeout` flag. Needs a value that time.ParseDuration can parse.
116-
DEVBOX_GOLANG_TEST_TIMEOUT: "${{ (github.ref == 'refs/heads/main' || inputs.run-mac-tests) && '35m' || '15m' }}"
116+
DEVBOX_GOLANG_TEST_TIMEOUT: "${{ (github.ref == 'refs/heads/main' || inputs.run-mac-tests) && '35m' || '20m' }}"
117117
run: |
118118
go test -v -timeout $DEVBOX_GOLANG_TEST_TIMEOUT ./...
119119

examples/plugins/github-with-revision/devbox.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@
1111
}
1212
},
1313
"include": [
14-
"github:jetpack-io/devbox-plugin-example/6ea0ef9e12ab58dbbb145ca8f3a465611cb603a9#devbox"
14+
"github:jetpack-io/devbox-plugin-example/d9c00334353c9b1294c7bd5dbea128c149b2eb3a"
1515
]
1616
}

examples/plugins/github/devbox.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@
1212
},
1313
"include": [
1414
"github:jetpack-io/devbox-plugin-example",
15-
"github:jetpack-io/devbox-plugin-example#custom-name"
15+
"github:jetpack-io/devbox-plugin-example?dir=custom-dir"
1616
]
1717
}

internal/plugin/github.go

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"strings"
88

99
"github.com/pkg/errors"
10-
"github.com/samber/lo"
1110
"go.jetpack.io/devbox/internal/boxcli/usererr"
1211
"go.jetpack.io/devbox/internal/cuecfg"
1312
)
@@ -17,31 +16,33 @@ type githubPlugin struct {
1716
org string
1817
repo string
1918
revision string
20-
fragment string
19+
dir string
2120
}
2221

2322
// newGithubPlugin returns a plugin that is hosted on github.
24-
// url is of the form org/repo#name
25-
// The repo must have a [name].json in the root of the repo. If fragment is
26-
// not set, it defaults to "default"
27-
func newGithubPlugin(url string) (*githubPlugin, error) {
28-
path, fragment, _ := strings.Cut(url, "#")
23+
// url is of the form org/repo?dir=<dir>
24+
// The (optional) dir must have a plugin.json"
25+
func newGithubPlugin(rawURL string) (*githubPlugin, error) {
26+
pluginURL, err := url.Parse(rawURL)
27+
if err != nil {
28+
return nil, err
29+
}
2930

30-
parts := strings.Split(path, "/")
31+
parts := strings.Split(pluginURL.Path, "/")
3132

3233
if len(parts) < 2 || len(parts) > 3 {
3334
return nil, usererr.New(
3435
"invalid github plugin url %q. Must be of the form org/repo/[revision]",
35-
url,
36+
rawURL,
3637
)
3738
}
3839

3940
plugin := &githubPlugin{
40-
raw: url,
41+
raw: rawURL,
4142
org: parts[0],
4243
repo: parts[1],
4344
revision: "master",
44-
fragment: fragment,
45+
dir: pluginURL.Query().Get("dir"),
4546
}
4647

4748
if len(parts) == 3 {
@@ -68,6 +69,7 @@ func (p *githubPlugin) FileContent(subpath string) ([]byte, error) {
6869
p.org,
6970
p.repo,
7071
p.revision,
72+
p.dir,
7173
subpath,
7274
)
7375
if err != nil {
@@ -82,7 +84,7 @@ func (p *githubPlugin) FileContent(subpath string) ([]byte, error) {
8284
if res.StatusCode != http.StatusOK {
8385
return nil, usererr.New(
8486
"failed to get plugin github:%s (Status code %d). \nPlease make sure a "+
85-
"[name].json or default.json file exists in the root of the repo.",
87+
"plugin.json file exists in plugin directory.",
8688
p.raw,
8789
res.StatusCode,
8890
)
@@ -91,8 +93,7 @@ func (p *githubPlugin) FileContent(subpath string) ([]byte, error) {
9193
}
9294

9395
func (p *githubPlugin) buildConfig(projectDir string) (*config, error) {
94-
configName, _ := lo.Coalesce(p.fragment, "default")
95-
content, err := p.FileContent(configName + ".json")
96+
content, err := p.FileContent("plugin.json")
9697
if err != nil {
9798
return nil, errors.WithStack(err)
9899
}

0 commit comments

Comments
 (0)