Skip to content

Commit

Permalink
Merge pull request #21 from osspkg/develop
Browse files Browse the repository at this point in the history
fix gosite + auto tags
  • Loading branch information
markus621 authored Nov 14, 2023
2 parents de8ee1a + 8bc96e5 commit be0561f
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 7 deletions.
13 changes: 8 additions & 5 deletions internal/gosite/gosite.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion internal/tag/tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")...)
}
Expand Down Expand Up @@ -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...)
})
})
Expand Down
2 changes: 1 addition & 1 deletion pkg/ver/ver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions pkg/ver/ver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit be0561f

Please sign in to comment.