Skip to content

Commit

Permalink
Merge pull request #102 from kcmvp/doc-fix
Browse files Browse the repository at this point in the history
#101: fix path separator for window
  • Loading branch information
kcmvp authored May 17, 2024
2 parents f454661 + d0ebfe5 commit 305127a
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 28 deletions.
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,11 @@ gbc init
Initialize gbc for the project, it will do following initializations
1. generate file `gob.yaml`
2. generate file `.golangci.yaml`, which is the configuration for [golangci-lint](https://github.com/golangci/golangci-lint)
3. setup `git hooks` if project in the source control.
4. commit-msg
5. pre-commit
6. pre-push
3. setup `git hooks`(if project in the source control.)
1. commit-msg
2. pre-commit
3. pre-push

> This command can be executed at any time.
Content of `gob.yaml`
Expand Down Expand Up @@ -141,7 +142,7 @@ gbc build
```
This command would build all the candidate binaries(main methods in main packages) to the `target` folder.
1. Final binary name is same as go source file name which contains `main method`
2. Would fail if there are same name go main surce file
2. Would fail if there are same name go main source file

### gbc clean
```shell
Expand Down Expand Up @@ -185,7 +186,7 @@ List all the installed plugins
```shell
gob setup version
```
This command will generate file `version.go` in `infra` folder, and project version informatill
This command will generate file `version.go` in `infra` folder, and project version information
will be injected into `buildVersion` when build the project with command `gob build`
```go
// buildVersion don't change this
Expand Down
7 changes: 4 additions & 3 deletions cmd/gbc/artifact/internal_plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func (suite *InternalPluginTestSuit) TestNewPlugin() {
defer func() {
os.RemoveAll(gopath)
}()
version := LatestVersion("github.com/golangci/golangci-lint")
tests := []struct {
name string
url string
Expand All @@ -45,15 +46,15 @@ func (suite *InternalPluginTestSuit) TestNewPlugin() {
url: "github.com/golangci/golangci-lint/cmd/golangci-lint",
module: "github.com/golangci/golangci-lint",
logName: "golangci-lint",
binary: "golangci-lint-v1.57.2",
binary: fmt.Sprintf("%s-%s", "golangci-lint", version[0].B),
wantErr: false,
},
{
name: "latest version",
url: "github.com/golangci/golangci-lint/cmd/golangci-lint@latest",
module: "github.com/golangci/golangci-lint",
logName: "golangci-lint",
binary: "golangci-lint-v1.57.2",
binary: fmt.Sprintf("%s-%s", "golangci-lint", version[0].B),
wantErr: false,
},
{
Expand Down Expand Up @@ -105,7 +106,7 @@ func (suite *InternalPluginTestSuit) TestNewPlugin() {
assert.True(t, test.wantErr == (err != nil))
if !test.wantErr {
assert.Equal(t, test.module, plugin.module)
assert.True(t, lo.Contains([]string{"v1.57.2", "v1.1.1", "v1.11.0"}, plugin.Version()))
assert.True(t, lo.Contains([]string{"v1.58.1", "v1.57.2", "v1.1.1", "v1.11.0"}, plugin.Version()))
}
})
}
Expand Down
22 changes: 17 additions & 5 deletions cmd/gbc/artifact/plugin.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package artifact

import (
"bufio"
"encoding/json"
"errors"
"fmt"
Expand Down Expand Up @@ -49,15 +50,26 @@ func (plugin *Plugin) init() error {
}
plugin.name, _ = lo.Last(strings.Split(plugin.module, "/"))
if plugin.version == "latest" {
output, err := exec.Command("go", "list", "-m", fmt.Sprintf("%s@latest", plugin.module)).CombinedOutput() //nolint:gosec
if err != nil {
return fmt.Errorf("failed to get version of %s", plugin.Url)
}
plugin.version = strings.Fields(strings.ReplaceAll(string(output), "\n", ""))[1]
plugin.version = LatestVersion(plugin.module)[0].B
}
return nil
}

func LatestVersion(modules ...string) []lo.Tuple2[string, string] {
modules = lo.Map(modules, func(item string, _ int) string {
return fmt.Sprintf("%s@latest", item)
})
output, _ := exec.Command("go", append([]string{"list", "-m"}, modules...)...).CombinedOutput() //nolint
scanner := bufio.NewScanner(strings.NewReader(string(output)))
var tuple []lo.Tuple2[string, string]
for scanner.Scan() {
line := strings.TrimSpace(scanner.Text())
entry := strings.Split(line, " ")
tuple = append(tuple, lo.Tuple2[string, string]{A: entry[0], B: entry[1]})
}
return tuple
}

func (plugin Plugin) Module() string {
return plugin.module
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/gbc/artifact/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,13 @@ func (project *Project) HookDir() string {
}

func init() {
cmd := exec.Command("go", "list", "-m", "-f", "{{.Dir}}:{{.Path}}")
cmd := exec.Command("go", "list", "-m", "-f", "{{.Dir}}_:_{{.Path}}")
output, err := cmd.Output()
if err != nil || len(string(output)) == 0 {
log.Fatal(color.RedString("Error: please execute command in project root directory"))
log.Fatal(color.RedString("Error: please execute command in project root directory %s", string(output)))
}

item := strings.Split(strings.TrimSpace(string(output)), ":")
item := strings.Split(strings.TrimSpace(string(output)), "_:_")
project = Project{
root: item[0],
module: item[1],
Expand Down
17 changes: 7 additions & 10 deletions cmd/gbc/command/deps.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,18 +66,15 @@ func dependencyTree() (treeprint.Tree, error) {
tree := treeprint.New()
tree.SetValue(module)
direct := lo.FilterMap(dependencies, func(item *lo.Tuple4[string, string, string, int], _ int) (string, bool) {
return fmt.Sprintf("%s@latest", item.A), item.D == 1
return item.A, item.D == 1
})
// get the latest version
output, _ := exec.Command("go", append([]string{"list", "-m"}, direct...)...).CombinedOutput() //nolint
scanner := bufio.NewScanner(strings.NewReader(string(output)))
for scanner.Scan() {
line := strings.TrimSpace(scanner.Text())
entry := strings.Split(line, " ")
for _, dep := range dependencies {
if dep.A == entry[0] && dep.B != entry[1] {
dep.C = entry[1]
}
versions := artifact.LatestVersion(direct...)
for _, dep := range dependencies {
if version, ok := lo.Find(versions, func(t lo.Tuple2[string, string]) bool {
return dep.A == t.A && dep.B != t.B
}); ok {
dep.C = version.B
}
}
// parse the dependency tree
Expand Down
2 changes: 1 addition & 1 deletion cmd/gbc/command/resources/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{
"alias": "lint",
"args": "run ./...",
"url": "github.com/golangci/golangci-lint/cmd/golangci-lint",
"url": "github.com/golangci/golangci-lint/cmd/golangci-lint@v1.57.2",
"config": ".golangci.yaml"
},
{
Expand Down

0 comments on commit 305127a

Please sign in to comment.