-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding a float subcommand for future proofing
- Loading branch information
Scott Nichols
committed
Sep 23, 2020
1 parent
46a9884
commit 029e70c
Showing
3 changed files
with
108 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,8 +12,30 @@ go get github.com/n3wscott/buoy | |
|
||
## Usage | ||
|
||
```shell | ||
Usage: | ||
buoy [command] | ||
|
||
Available Commands: | ||
float Find latest versions of dependencies based on a release. | ||
help Help about any command | ||
|
||
Flags: | ||
-h, --help help for buoy | ||
|
||
Use "buoy [command] --help" for more information about a command. | ||
``` | ||
buoy go.mod $release | ||
|
||
### Float | ||
|
||
```shell | ||
Usage: | ||
buoy float go.mod [flags] | ||
|
||
Flags: | ||
-d, --domain string domain filter (default "knative.dev") | ||
-h, --help help for float | ||
-r, --release string release should be '<major>.<minor>' (i.e.: 1.23 or v1.23) [required] | ||
``` | ||
|
||
Example: | ||
|
@@ -26,15 +48,28 @@ knative.dev/[email protected] | |
knative.dev/[email protected] | ||
``` | ||
|
||
Note: the following are equivalent: | ||
Or set the domain to and target release of that dependency: | ||
|
||
```shell script | ||
$ buoy float go.mod --release 0.18 --domain k8s.io | ||
k8s.io/[email protected] | ||
k8s.io/[email protected] | ||
k8s.io/[email protected] | ||
k8s.io/[email protected] | ||
k8s.io/[email protected] | ||
k8s.io/gengo@master | ||
k8s.io/klog@master | ||
``` | ||
|
||
Note: the following are equivalent releases: | ||
|
||
- `v0.1` | ||
- `v0.1.0` | ||
- `0.1` | ||
- `0.1.0` | ||
|
||
|
||
## Rules | ||
### Float Rules | ||
|
||
Buoy will select a `ref` for a found dependency, in this order: | ||
|
||
|
@@ -45,3 +80,4 @@ Buoy will select a `ref` for a found dependency, in this order: | |
## TODO: | ||
|
||
- Support `go-import` with more than one import on a single page. | ||
- Support release branch templates. For now, hardcoded to Knative style. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package float | ||
|
||
import ( | ||
"fmt" | ||
"github.com/blang/semver/v4" | ||
"github.com/n3wscott/buoy/pkg/git" | ||
"github.com/n3wscott/buoy/pkg/golang" | ||
"golang.org/x/mod/modfile" | ||
"io/ioutil" | ||
"strings" | ||
) | ||
|
||
func Float(gomod, release, domain string) ([]string, error) { | ||
b, err := ioutil.ReadFile(gomod) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
file, err := modfile.Parse(gomod, b, nil) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
packages := make([]string, 0) | ||
for _, r := range file.Require { | ||
// Look for requirements that have the prefix of domain. | ||
if strings.HasPrefix(r.Mod.Path, domain) { | ||
packages = append(packages, r.Mod.Path) | ||
} | ||
} | ||
|
||
this, err := semver.ParseTolerant(release) | ||
|
||
refs := make([]string, 0) | ||
for _, p := range packages { | ||
meta, err := golang.GetMetaImport(p) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
if meta.VCS != "git" { | ||
return nil, fmt.Errorf("unknown VCS: %s", meta.VCS) | ||
} | ||
|
||
repo, err := git.GetRepo(p, meta.RepoRoot) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
refs = append(refs, repo.BestRefFor(this)) | ||
} | ||
return refs, nil | ||
} |