Skip to content

Commit

Permalink
Merge pull request #23 from osspkg/fix-tags
Browse files Browse the repository at this point in the history
fix setup tags for go work
  • Loading branch information
markus621 authored Dec 7, 2023
2 parents be0561f + bf27549 commit 7c62e1d
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 6 deletions.
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ module github.com/osspkg/devtool
go 1.18

require (
go.osspkg.com/algorithms v1.3.0
go.osspkg.com/goppy v0.14.0
golang.org/x/mod v0.13.0
golang.org/x/mod v0.14.0
gopkg.in/yaml.v3 v3.0.1
)

Expand Down
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M=
github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
go.osspkg.com/algorithms v1.3.0 h1:rrKO440aNTofYJwGnOVsW00w0VRtZtu+BQrgXMXw7j4=
go.osspkg.com/algorithms v1.3.0/go.mod h1:J2SXxHdqBK9ALGYJomA9XGvTOhIwMK0fvVw+KusYyoo=
go.osspkg.com/goppy v0.14.0 h1:7YoNaSA+XIAy+lbIMEdmMIXH9Em+keNRMVvqP4+4jiE=
go.osspkg.com/goppy v0.14.0/go.mod h1:NAWYk3WylEMTTcEgFiFEQsL69T/ox614gpuzlWyxlzg=
golang.org/x/mod v0.13.0 h1:I/DsJXRlw/8l/0c24sM9yb0T4z9liZTduXvdAWYiysY=
golang.org/x/mod v0.13.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/mod v0.14.0 h1:dGoOF9QVLYng8IHTm7BAyWqCqSheQ5pYWGhzW00YJr0=
golang.org/x/mod v0.14.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
Expand Down
41 changes: 38 additions & 3 deletions internal/tag/tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/osspkg/devtool/pkg/modules"
"github.com/osspkg/devtool/pkg/repo"
"github.com/osspkg/devtool/pkg/ver"
"go.osspkg.com/algorithms/graph/kahn"
"go.osspkg.com/goppy/sdk/console"
"golang.org/x/mod/modfile"
)
Expand Down Expand Up @@ -70,11 +71,26 @@ func Cmd() console.CommandGetter {
console.FatalIfErr(err, "Detect changed files")
changedFiles := strings.Split(string(b), "\n")
for _, file := range changedFiles {
if len(file) == 0 {
continue
}
dir := filepath.Dir(file)
currmod, err = modules.Read(dir + "/go.mod")
isRoot := dir == "."
for {
currmod, err = modules.Read(dir + "/go.mod")
if err != nil && !isRoot && strings.Contains(err.Error(), "no such file") {
dir = filepath.Dir(dir)
if dir != "." {
continue
}
break
}
break
}
if err != nil {
continue
}

for _, m := range allMods {
if m.Name == currmod.Name && !m.Changed {
m.Changed = true
Expand All @@ -89,7 +105,26 @@ func Cmd() console.CommandGetter {

console.Infof("--- UPDATE MODULES ---")

graph := kahn.New()
for _, m := range allMods {
_, err = os.Stat(m.File)
console.FatalIfErr(err, "Get info go.mod file: %s", m.File)
b, err = os.ReadFile(m.File)
console.FatalIfErr(err, "Read go.mod file: %s", m.File)
_, err = modfile.Parse(m.File, b, func(path, version string) (string, error) {
if _, ok := allMods[path]; ok {
console.FatalIfErr(graph.Add(path, m.Name), "Create graph from: %s", m.File)
}
return version, nil
})
console.FatalIfErr(err, "Parse go.mod file: %s", m.File)
}
console.FatalIfErr(graph.Build(), "Build graph")
for _, s := range graph.Result() {
m, ok := allMods[s]
if !ok {
continue
}
fmt.Println(">", m.Name)
fi, err = os.Stat(m.File)
console.FatalIfErr(err, "Get info go.mod file: %s", m.File)
Expand All @@ -109,7 +144,7 @@ func Cmd() console.CommandGetter {
}
return version, nil
})
console.FatalIfErr(err, "Parce go.mod file: %s", m.File)
console.FatalIfErr(err, "Parse go.mod file: %s", m.File)
b, err = f.Format()
console.FatalIfErr(err, "Format go.mod file: %s", m.File)
err = os.WriteFile(m.File, b, fi.Mode())
Expand All @@ -129,7 +164,7 @@ func Cmd() console.CommandGetter {
}
cmds = append(cmds, "git tag "+m.Prefix+m.Version.String())
}
cmds = append(cmds, "git push --tags")
cmds = append(cmds, "git push", "git push --tags")
exec.CommandPack("bash", cmds...)
})
})
Expand Down

0 comments on commit 7c62e1d

Please sign in to comment.