4 Commits

Author SHA1 Message Date
Loki Verloren
aa2e76cef1 oo 2021-04-30 20:29:12 +02:00
Loki Verloren
39c743f551 update *yawn* 2021-04-30 20:22:27 +02:00
Loki Verloren
0b9edd9240 update version 2021-04-30 18:42:38 +02:00
Loki Verloren
86a6516bbf updating version 2021-04-30 18:28:57 +02:00
6 changed files with 117 additions and 48 deletions

8
go.mod
View File

@@ -7,7 +7,8 @@ require (
github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0
github.com/kr/text v0.2.0 // indirect
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
github.com/p9c/log v0.0.6
github.com/p9c/interrupt
github.com/p9c/log v0.0.4
github.com/p9c/qu v0.0.3
github.com/stretchr/testify v1.6.1 // indirect
go.uber.org/atomic v1.7.0
@@ -16,3 +17,8 @@ require (
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect
gopkg.in/src-d/go-git.v4 v4.13.1
)
replace (
github.com/p9c/log => ../log
github.com/p9c/qu => ../qu
github.com/p9c/interrupt => ../interrupt
)

2
log.go
View File

@@ -2,7 +2,7 @@ package interrupt
import (
"github.com/p9c/log"
"github.com/p9c/qu/version"
"github.com/p9c/interrupt/version"
)
var F, E, W, I, D, T = log.GetLogPrinterSet(log.AddLoggerSubsystem(version.PathBase))

16
version/logversion.go Normal file
View File

@@ -0,0 +1,16 @@
package version
import (
"path/filepath"
"runtime"
"github.com/p9c/log"
)
var F, E, W, I, D, T log.LevelPrinter
func init() {
_, file,_, _ := runtime.Caller(0)
verPath := filepath.Dir(file)+"/"
F, E, W, I, D, T = log.GetLogPrinterSet(log.AddLoggerSubsystem(verPath))
}

View File

@@ -2,7 +2,8 @@ package main
import (
"github.com/p9c/log"
"github.com/p9c/qu/version"
"github.com/p9c/log/version"
)
var F, E, W, I, D, T = log.GetLogPrinterSet(log.AddLoggerSubsystem(version.PathBase))

View File

@@ -5,13 +5,14 @@ import (
"io/ioutil"
"os"
"path/filepath"
"runtime"
"strings"
"time"
"gopkg.in/src-d/go-git.v4"
"gopkg.in/src-d/go-git.v4/plumbing"
"gopkg.in/src-d/go-git.v4/plumbing/storer"
"github.com/p9c/interrupt/version"
)
var (
@@ -20,21 +21,27 @@ var (
GitCommit string
BuildTime string
Tag string
Major, Minor, Patch int
Meta string
PathBase string
)
func main() {
I.Ln(version.Get())
BuildTime = time.Now().Format(time.RFC3339)
var cwd string
var e error
if cwd, e = os.Getwd(); e != nil {
if cwd, e = os.Getwd(); E.Chk(e) {
return
}
cwd = filepath.Dir(cwd)
// I.Ln(cwd)
var repo *git.Repository
if repo, e = git.PlainOpen(cwd); e != nil {
if repo, e = git.PlainOpen(cwd); E.Chk(e) {
return
}
var rr []*git.Remote
if rr, e = repo.Remotes(); e != nil {
if rr, e = repo.Remotes(); E.Chk(e) {
return
}
for i := range rr {
@@ -55,15 +62,18 @@ func main() {
}
}
var tr *git.Worktree
if tr, e = repo.Worktree(); E.Chk(e) {
}
var rh *plumbing.Reference
if rh, e = repo.Head(); e != nil {
if rh, e = repo.Head(); E.Chk(e) {
return
}
rhs := rh.Strings()
GitRef = rhs[0]
GitCommit = rhs[1]
var rt storer.ReferenceIter
if rt, e = repo.Tags(); e != nil {
if rt, e = repo.Tags(); E.Chk(e) {
return
}
var maxVersion int
@@ -71,42 +81,44 @@ func main() {
var maxIs bool
if e = rt.ForEach(
func(pr *plumbing.Reference) (e error) {
prs := strings.Split(pr.String(), "/")[2]
s := strings.Split(pr.String(), "/")
prs := s[2]
if strings.HasPrefix(prs, "v") {
var va [3]int
_, _ = fmt.Sscanf(prs, "v%d.%d.%d", &va[0], &va[1], &va[2])
var meta string
_, _ = fmt.Sscanf(prs, "v%d.%d.%d%s", &va[0], &va[1], &va[2], &meta)
vn := va[0]*1000000 + va[1]*1000 + va[2]
if maxVersion < vn {
maxVersion = vn
maxString = prs
Major = va[0]
Minor = va[1]
Patch = va[2]
Meta = meta
}
if pr.Hash() == rh.Hash() {
maxIs = true
return
}
}
return nil
return
},
); e != nil {
); E.Chk(e) {
return
}
if !maxIs {
maxString += "+"
}
Tag = maxString
_, file, _, _ := runtime.Caller(0)
// fmt.Fprintln(os.Stderr, "file", file)
urlSplit := strings.Split(URL, "/")
// fmt.Fprintln(os.Stderr, "urlSplit", urlSplit)
baseFolder := urlSplit[len(urlSplit)-1]
// fmt.Fprintln(os.Stderr, "baseFolder", baseFolder)
splitPath := strings.Split(file, baseFolder)
// fmt.Fprintln(os.Stderr, "splitPath", splitPath)
PathBase := filepath.Join(splitPath[0], baseFolder) + string(filepath.Separator)
PathBase = strings.ReplaceAll(PathBase, "\\", "\\\\")
// fmt.Fprintln(os.Stderr, "PathBase", PathBase)
PathBase = tr.Filesystem.Root() + "/"
// I.Ln(PathBase)
versionFile := `package version
import "fmt"
`+`//go:generate go run ./update/.
import (
"fmt"
)
var (
@@ -123,17 +135,29 @@ var (
Tag = "%s"
// PathBase is the path base returned from runtime caller
PathBase = "%s"
// Major is the major number from the tag
Major = %d
// Minor is the minor number from the tag
Minor = %d
// Patch is the patch version number from the tag
Patch = %d
// Meta is the extra arbitrary string field from Semver spec
Meta = "%s"
)
// Get returns a pretty printed version information string
func Get() string {
return fmt.Sprint(
"Repository Information\n"+
" git repository: "+URL+"\n",
" branch: "+GitRef+"\n"+
" commit: "+GitCommit+"\n"+
" built: "+BuildTime+"\n"+
" Tag: "+Tag+"\n",
"\nRepository Information\n"+
"\tGit repository: "+URL+"\n",
"\tBranch: "+GitRef+"\n"+
"\tCommit: "+GitCommit+"\n"+
"\tBuilt: "+BuildTime+"\n"+
"\tTag: "+Tag+"\n",
"\tMajor:", Major, "\n",
"\tMinor:", Minor, "\n",
"\tPatch:", Patch, "\n",
"\tMeta: ", Meta, "\n",
)
}
`
@@ -145,8 +169,14 @@ func Get() string {
BuildTime,
Tag,
PathBase,
Major,
Minor,
Patch,
Meta,
)
if e = ioutil.WriteFile("version/version.go", []byte(versionFileOut), 0666); E.Chk(e) {
path := filepath.Join(filepath.Join(PathBase, "version"), "version.go")
if e = ioutil.WriteFile(path, []byte(versionFileOut), 0666); E.Chk(e) {
}
// I.Ln("updated version.go written")
return
}

View File

@@ -1,6 +1,10 @@
package version
import "fmt"
//go:generate go run ./update/.
import (
"fmt"
)
var (
@@ -9,24 +13,36 @@ var (
// GitRef is the gitref, as in refs/heads/branchname
GitRef = "refs/heads/main"
// GitCommit is the commit hash of the current HEAD
GitCommit = "568956448c87f6147be12234760f99779ede0304"
GitCommit = "0b9edd924034775ae337ca15a00a20629ff130c3"
// BuildTime stores the time when the current binary was built
BuildTime = "2021-04-15T02:19:31+02:00"
BuildTime = "2021-04-30T19:56:38+02:00"
// Tag lists the Tag on the build, adding a + to the newest Tag if the commit is
// not that commit
Tag = "v0.0.1"
Tag = "v0.0.4"
// PathBase is the path base returned from runtime caller
PathBase = "/home/loki/src/github.com/p9c/interrupt/"
PathBase = "/home/loki/src/github.com/p9c/pod/pkg/interrupt/"
// Major is the major number from the tag
Major = 0
// Minor is the minor number from the tag
Minor = 0
// Patch is the patch version number from the tag
Patch = 4
// Meta is the extra arbitrary string field from Semver spec
Meta = ""
)
// Get returns a pretty printed version information string
func Get() string {
return fmt.Sprint(
"Repository Information\n"+
" git repository: "+URL+"\n",
" branch: "+GitRef+"\n"+
" commit: "+GitCommit+"\n"+
" built: "+BuildTime+"\n"+
" Tag: "+Tag+"\n",
"\nRepository Information\n"+
"\tGit repository: "+URL+"\n",
"\tBranch: "+GitRef+"\n"+
"\tCommit: "+GitCommit+"\n"+
"\tBuilt: "+BuildTime+"\n"+
"\tTag: "+Tag+"\n",
"\tMajor:", Major, "\n",
"\tMinor:", Minor, "\n",
"\tPatch:", Patch, "\n",
"\tMeta: ", Meta, "\n",
)
}