From 8bc96e51b9bf43ed9fb685f6738b8cb00315a9fb Mon Sep 17 00:00:00 2001 From: Mikhail Knyazhev Date: Wed, 15 Nov 2023 00:22:23 +0300 Subject: [PATCH] fix gosite + auto tags --- internal/gosite/gosite.go | 13 ++++++++----- internal/tag/tag.go | 3 ++- pkg/ver/ver.go | 2 +- pkg/ver/ver_test.go | 10 ++++++++++ 4 files changed, 21 insertions(+), 7 deletions(-) diff --git a/internal/gosite/gosite.go b/internal/gosite/gosite.go index 5ae8031..8ac1e1c 100644 --- a/internal/gosite/gosite.go +++ b/internal/gosite/gosite.go @@ -5,11 +5,13 @@ import ( "net/url" "os" "regexp" + "sort" "strings" "github.com/osspkg/devtool/internal/global" "github.com/osspkg/devtool/pkg/exec" "github.com/osspkg/devtool/pkg/files" + "github.com/osspkg/devtool/pkg/modules" "go.osspkg.com/goppy/sdk/console" "go.osspkg.com/goppy/sdk/iofile" ) @@ -63,8 +65,8 @@ func Cmd() console.CommandGetter { console.FatalIfErr(err, "Clone remote HEAD") os.RemoveAll(tempdir + "/.git") //nolint: errcheck - var mods []string - mods, err = files.DetectInDir(tempdir, "go.mod") + var mods map[string]*modules.Mod + mods, err = modules.Detect(tempdir) console.FatalIfErr(err, "Detect go.mod files") var dataMod *Data @@ -80,11 +82,11 @@ func Cmd() console.CommandGetter { } for _, mod := range mods { - b, err = os.ReadFile(mod) - console.FatalIfErr(err, "Read go.mod [%s]", mod) + b, err = os.ReadFile(mod.File) + console.FatalIfErr(err, "Read go.mod [%s]", mod.File) _strs = rexMOD.FindStringSubmatch(string(b)) if len(_strs) != 2 { - console.Fatalf("Module not found in %s", mod) + console.Fatalf("Module not found in %s", mod.File) } module := _strs[1] dataMod.Modules = append(dataMod.Modules, module) @@ -114,6 +116,7 @@ func Cmd() console.CommandGetter { index[domain] = make([]string, 0, 10) } + sort.Strings(data.Modules) for _, mod := range data.Modules { err = os.MkdirAll(mod, 0755) console.FatalIfErr(err, "Create site dir [%s]", mod) diff --git a/internal/tag/tag.go b/internal/tag/tag.go index 1d58b60..6599b50 100644 --- a/internal/tag/tag.go +++ b/internal/tag/tag.go @@ -57,7 +57,7 @@ func Cmd() console.CommandGetter { if len(m.Prefix) > 0 { m.Prefix += "/" } - b, err = exec.SingleCmd(context.TODO(), "bash", "git tag -l "+m.Prefix+"v*") + b, err = exec.SingleCmd(context.TODO(), "bash", "git tag -l \""+m.Prefix+"v*\"") console.FatalIfErr(err, "Get tags for: %s", m.Name) m.Version = ver.Max(strings.Split(string(b), "\n")...) } @@ -129,6 +129,7 @@ func Cmd() console.CommandGetter { } cmds = append(cmds, "git tag "+m.Prefix+m.Version.String()) } + cmds = append(cmds, "git push --tags") exec.CommandPack("bash", cmds...) }) }) diff --git a/pkg/ver/ver.go b/pkg/ver/ver.go index d31f343..c74fcee 100644 --- a/pkg/ver/ver.go +++ b/pkg/ver/ver.go @@ -6,7 +6,7 @@ import ( "strconv" ) -var rex = regexp.MustCompile(`^v([0-9]+)\.([0-9]+)\.([0-9]+)`) +var rex = regexp.MustCompile(`v([0-9]+)\.([0-9]+)\.([0-9]+)$`) type Ver struct { Major int64 diff --git a/pkg/ver/ver_test.go b/pkg/ver/ver_test.go index 55af3d3..cca0334 100644 --- a/pkg/ver/ver_test.go +++ b/pkg/ver/ver_test.go @@ -22,6 +22,16 @@ func TestUnit_Parce(t *testing.T) { }, wantErr: false, }, + { + name: "Case2", + args: "app/v1.1000.1231", + want: &Ver{ + Major: 1, + Minor: 1000, + Patch: 1231, + }, + wantErr: false, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) {