From b7de32833a706eab884dcc75baa5cf86d97ac34d Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Fri, 13 Nov 2020 04:53:01 -0700 Subject: [PATCH] update versioning for gitver, goreleaser --- README.md | 4 +- WHITELIST.md | 4 +- build-client.sh | 15 --- cmd/dnsclient/dnsclient.go | 17 +-- cmd/machineid/machineid.go | 2 +- cmd/mgmt/README.md | 4 +- cmd/mgmt/mgmt.go | 20 ++- cmd/sqlstore/sqlstore.go | 2 +- cmd/telebit/README.md | 2 +- cmd/telebit/telebit.go | 14 +-- cmd/wsconnect/wsconnect.go | 8 +- go.mod | 2 +- go.sum | 4 +- internal/tools/tools.go | 2 +- .../root/go-gitver/go.mod | 3 - .../root/go-gitver/{ => v2}/.gitignore | 4 + .../root/go-gitver/v2/.prettierrc | 1 + .../root/go-gitver/{ => v2}/LICENSE | 0 .../root/go-gitver/{ => v2}/README.md | 117 +++++++++++++----- .../root/go-gitver/{ => v2}/gitver.go | 24 ++-- .../root/go-gitver/{ => v2}/gitver/gitver.go | 17 ++- .../root/go-gitver/v2/go.mod | 3 + .../root/go-gitver/v2/go.sum | 2 + .../root/go-gitver/{ => v2}/version.go | 6 +- vendor/modules.txt | 6 +- 25 files changed, 179 insertions(+), 104 deletions(-) delete mode 100644 build-client.sh delete mode 100644 vendor/git.rootprojects.org/root/go-gitver/go.mod rename vendor/git.rootprojects.org/root/go-gitver/{ => v2}/.gitignore (86%) create mode 100644 vendor/git.rootprojects.org/root/go-gitver/v2/.prettierrc rename vendor/git.rootprojects.org/root/go-gitver/{ => v2}/LICENSE (100%) rename vendor/git.rootprojects.org/root/go-gitver/{ => v2}/README.md (54%) rename vendor/git.rootprojects.org/root/go-gitver/{ => v2}/gitver.go (84%) rename vendor/git.rootprojects.org/root/go-gitver/{ => v2}/gitver/gitver.go (86%) create mode 100644 vendor/git.rootprojects.org/root/go-gitver/v2/go.mod create mode 100644 vendor/git.rootprojects.org/root/go-gitver/v2/go.sum rename vendor/git.rootprojects.org/root/go-gitver/{ => v2}/version.go (52%) diff --git a/README.md b/README.md index 1fc7e5d..9e1a6e0 100644 --- a/README.md +++ b/README.md @@ -87,7 +87,7 @@ pushd telebit/ You can build with `go build`: ```bash -go build -mod vendor -race -o telebit cmd/telebit/telebit.go +go build -mod vendor -race -o telebit cmd/telebit/*.go ``` Or with `goreleaser`: @@ -96,6 +96,8 @@ Or with `goreleaser`: goreleaser --rm-dist --skip-publish --snapshot ``` +See https://webinstall.dev/goreleaser for cheat sheet. + ## Install Go To install Go (on any of Windows, Mac, or Linux), see . diff --git a/WHITELIST.md b/WHITELIST.md index daf53e6..18f6abc 100644 --- a/WHITELIST.md +++ b/WHITELIST.md @@ -31,11 +31,11 @@ CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build \ -mod=vendor \ -ldflags="-X 'main.VendorID=$VENDOR_ID'" \ -o telebit-debug.exe \ - ./cmd/telebit/telebit.go + ./cmd/telebit/*.go CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build \ -mod=vendor \ -ldflags "-H windowsgui -X 'main.VendorID=$VENDOR_ID'" \ -o telebit-windows.exe \ - ./cmd/telebit/telebit.go + ./cmd/telebit/*.go ``` diff --git a/build-client.sh b/build-client.sh deleted file mode 100644 index 5a557fb..0000000 --- a/build-client.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/bash - -set -e -set -u - -#CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -mod vendor -o telebit-relay-linux ./cmd/telebit-relay/telebit-relay.go -#CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -mod vendor -o telebit-relay-macos ./cmd/telebit-relay/telebit-relay.go -#CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -mod vendor -o telebit-relay-windows.exe ./cmd/telebit-relay/telebit-relay.go - -go generate ./... - -CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -mod vendor -o telebit-client-linux ./cmd/telebit/*.go -CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -mod vendor -o telebit-client-macos ./cmd/telebit/*.go -CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -mod vendor -o telebit-client-windows-debug.exe ./cmd/telebit/*.go -CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -mod vendor -ldflags "-H windowsgui" -o telebit-client-windows.exe ./cmd/telebit/*.go diff --git a/cmd/dnsclient/dnsclient.go b/cmd/dnsclient/dnsclient.go index 0ab8254..5827e30 100644 --- a/cmd/dnsclient/dnsclient.go +++ b/cmd/dnsclient/dnsclient.go @@ -1,4 +1,4 @@ -//go:generate go run -mod=vendor git.rootprojects.org/root/go-gitver +//go:generate go run -mod=vendor git.rootprojects.org/root/go-gitver/v2 package main @@ -18,12 +18,12 @@ import ( ) var ( - // GitRev refers to the abbreviated commit hash - GitRev = "0000000" - // GitVersion refers to the most recent tag, plus any commits made since then - GitVersion = "v0.0.0-pre0+0000000" + // commit refers to the abbreviated commit hash + commit = "0000000" + // version refers to the most recent tag, plus any commits made since then + version = "v0.0.0-pre0+0000000" // GitTimestamp refers to the timestamp of the most recent commit - GitTimestamp = "0000-00-00T00:00:00+0000" + date = "0000-00-00T00:00:00+0000" ) func main() { @@ -38,9 +38,10 @@ func main() { flag.Parse() if len(os.Args) >= 2 { - if "version" == os.Args[1] { - fmt.Printf("telebit %s %s %s", GitVersion, GitRev, GitTimestamp) + if "version" == strings.TrimLeft(os.Args[1], "-") { + fmt.Printf("telebit %s (%s) %s\n", version, commit[:7], date) os.Exit(0) + return } } diff --git a/cmd/machineid/machineid.go b/cmd/machineid/machineid.go index d819e9c..55664ec 100644 --- a/cmd/machineid/machineid.go +++ b/cmd/machineid/machineid.go @@ -7,7 +7,7 @@ import ( "fmt" "os" - "git.rootprojects.org/root/telebit/mgmt/authstore" + "git.rootprojects.org/root/telebit/internal/mgmt/authstore" "github.com/denisbrodbeck/machineid" _ "github.com/joho/godotenv/autoload" diff --git a/cmd/mgmt/README.md b/cmd/mgmt/README.md index 3352c9a..c56e5e2 100644 --- a/cmd/mgmt/README.md +++ b/cmd/mgmt/README.md @@ -77,7 +77,7 @@ The admin token can be used to interact with the server. ```bash VENDOR_ID="example.com" MGMT_SECRET=XxX-mgmt-secret-XxX -ADMIN_TOKEN=$(go run cmd/signjwt/signjwt.go \ +ADMIN_TOKEN=$(go run cmd/signjwt/*.go \ --debug \ --expires-in 15m \ --vendor-id $VENDOR_ID \ @@ -187,7 +187,7 @@ curl -L -X DELETE http://mgmt.example.com:6468/api/devices/${my_subdomain} -H "A You can build with `go build`: ```bash -go build -mod vendor -race -o telebit-mgmt cmd/mgmt/mgmt.go +go build -mod vendor -race -o telebit-mgmt cmd/mgmt/*.go ``` Or with `goreleaser`: diff --git a/cmd/mgmt/mgmt.go b/cmd/mgmt/mgmt.go index 78df0c0..08d3dcd 100644 --- a/cmd/mgmt/mgmt.go +++ b/cmd/mgmt/mgmt.go @@ -1,4 +1,4 @@ -//go:generate go run -mod=vendor git.rootprojects.org/root/go-gitver +//go:generate go run -mod=vendor git.rootprojects.org/root/go-gitver/v2 package main @@ -22,12 +22,12 @@ import ( ) var ( - // GitRev refers to the abbreviated commit hash - GitRev = "0000000" - // GitVersion refers to the most recent tag, plus any commits made since then - GitVersion = "v0.0.0-pre0+0000000" + // commit refers to the abbreviated commit hash + commit = "0000000" + // version refers to the most recent tag, plus any commits made since then + version = "v0.0.0-pre0+0000000" // GitTimestamp refers to the timestamp of the most recent commit - GitTimestamp = "0000-00-00T00:00:00+0000" + date = "0000-00-00T00:00:00+0000" ) var store authstore.Store @@ -38,6 +38,14 @@ func help() { } func main() { + if len(os.Args) >= 2 { + if "version" == strings.TrimLeft(os.Args[1], "-") { + fmt.Printf("telebit %s (%s) %s\n", version, commit[:7], date) + os.Exit(0) + return + } + } + var err error var port string diff --git a/cmd/sqlstore/sqlstore.go b/cmd/sqlstore/sqlstore.go index 91a35e5..2dac26b 100644 --- a/cmd/sqlstore/sqlstore.go +++ b/cmd/sqlstore/sqlstore.go @@ -5,7 +5,7 @@ import ( "log" "strings" - "git.rootprojects.org/root/telebit/mgmt/authstore" + "git.rootprojects.org/root/telebit/internal/mgmt/authstore" ) func main() { diff --git a/cmd/telebit/README.md b/cmd/telebit/README.md index 37678cf..c6e1115 100644 --- a/cmd/telebit/README.md +++ b/cmd/telebit/README.md @@ -100,7 +100,7 @@ bash examples/admin-disconnect-device.sh You can build with `go build`: ```bash -go build -mod vendor -race -o telebit-relay cmd/telebit/telebit.go +go build -mod vendor -race -o telebit-relay cmd/telebit/*.go ``` Or with `goreleaser`: diff --git a/cmd/telebit/telebit.go b/cmd/telebit/telebit.go index 5e994ec..46523f4 100644 --- a/cmd/telebit/telebit.go +++ b/cmd/telebit/telebit.go @@ -1,4 +1,4 @@ -//go:generate go run -mod=vendor git.rootprojects.org/root/go-gitver +//go:generate go run -mod=vendor git.rootprojects.org/root/go-gitver/v2 package main @@ -61,12 +61,12 @@ const ( ) var ( - // GitRev refers to the abbreviated commit hash - GitRev = "0000000" - // GitVersion refers to the most recent tag, plus any commits made since then - GitVersion = "v0.0.0-pre0+0000000" + // commit refers to the abbreviated commit hash + commit = "0000000" + // version refers to the most recent tag, plus any commits made since then + version = "v0.0.0-pre0+0000000" // GitTimestamp refers to the timestamp of the most recent commit - GitTimestamp = "0000-00-00T00:00:00+0000" + date = "0000-00-00T00:00:00+0000" // serviceName is the service name serviceName = "telebit" @@ -94,7 +94,7 @@ var ClientSecret string func main() { if len(os.Args) >= 2 { if "version" == strings.TrimLeft(os.Args[1], "-") { - fmt.Printf("telebit %s (%s) %s\n", GitVersion, GitRev[:7], GitTimestamp) + fmt.Printf("telebit %s (%s) %s\n", version, commit[:7], date) os.Exit(exitOk) return } diff --git a/cmd/wsconnect/wsconnect.go b/cmd/wsconnect/wsconnect.go index b84d797..be3ec65 100644 --- a/cmd/wsconnect/wsconnect.go +++ b/cmd/wsconnect/wsconnect.go @@ -11,9 +11,9 @@ import ( "strings" "time" - telebit "git.rootprojects.org/root/telebit" - "git.rootprojects.org/root/telebit/mgmt" - "git.rootprojects.org/root/telebit/mgmt/authstore" + "git.rootprojects.org/root/telebit" + "git.rootprojects.org/root/telebit/internal/mgmt" + "git.rootprojects.org/root/telebit/internal/mgmt/authstore" "github.com/denisbrodbeck/machineid" "github.com/gorilla/websocket" @@ -50,7 +50,7 @@ func main() { ppid = base64.RawURLEncoding.EncodeToString(ppidBytes) fmt.Println("[debug] vendor-id, secret, ppid", *vendorID, *secret, ppid) if 0 == len(*token) { - *token, err = authstore.HMACToken(ppid) + *token, err = authstore.HMACToken(ppid, 15*time.Minute) if nil != err { fmt.Fprintf(os.Stderr, "neither secret nor token provided\n") os.Exit(1) diff --git a/go.mod b/go.mod index 9906396..17d8a14 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.14 replace github.com/caddyserver/certmagic => github.com/coolaj86/certmagic v0.12.1-pre.2 require ( - git.rootprojects.org/root/go-gitver v1.1.3 + git.rootprojects.org/root/go-gitver/v2 v2.0.2 github.com/coolaj86/certmagic v0.12.1-pre.2 github.com/denisbrodbeck/machineid v1.0.1 github.com/dgrijalva/jwt-go v3.2.0+incompatible diff --git a/go.sum b/go.sum index 502c84d..a0f921e 100644 --- a/go.sum +++ b/go.sum @@ -22,8 +22,8 @@ cloud.google.com/go/storage v1.5.0/go.mod h1:tpKbwo567HUNpVclU5sGELwQWBDZ8gh0Zeo cloud.google.com/go/storage v1.6.0/go.mod h1:N7U0C8pVQ/+NIKOBQyamJIeKQKkZ+mxpohlUTyfDhBk= contrib.go.opencensus.io/exporter/ocagent v0.4.12/go.mod h1:450APlNTSR6FrvC3CTRqYosuDstRB9un7SOx2k/9ckA= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= -git.rootprojects.org/root/go-gitver v1.1.3 h1:/qR9z53vY+IFhWRxLkF9cjaiWh8xRJIm6gyuW+MG81A= -git.rootprojects.org/root/go-gitver v1.1.3/go.mod h1:Rj1v3TBhvdaSphFEqMynUYwAz/4f+wY/+syBTvRrmlI= +git.rootprojects.org/root/go-gitver/v2 v2.0.2 h1:T+Je13wrY1jz4OPJF98HnuCNp6n2Xe2uK6/NNF6a4+0= +git.rootprojects.org/root/go-gitver/v2 v2.0.2/go.mod h1:ur82M/jZcvr1WWihyVtNEgDBqIjo22o56wcVHeVJFh8= github.com/Azure/azure-sdk-for-go v32.4.0+incompatible/go.mod h1:9XXNKU+eRnpl9moKnB4QOLf1HestfXbmab5FXxiDBjc= github.com/Azure/go-autorest/autorest v0.1.0/go.mod h1:AKyIcETwSUFxIcs/Wnq/C+kwCtlEYGUVd7FPNb2slmg= github.com/Azure/go-autorest/autorest v0.5.0/go.mod h1:9HLKlQjVBH6U3oDfsXOeVc56THsLPw1L03yban4xThw= diff --git a/internal/tools/tools.go b/internal/tools/tools.go index 11757ff..47c14b2 100644 --- a/internal/tools/tools.go +++ b/internal/tools/tools.go @@ -5,7 +5,7 @@ package tools import ( // these are binaries - _ "git.rootprojects.org/root/go-gitver" + _ "git.rootprojects.org/root/go-gitver/v2" _ "github.com/shurcooL/vfsgen" _ "github.com/shurcooL/vfsgen/cmd/vfsgendev" ) diff --git a/vendor/git.rootprojects.org/root/go-gitver/go.mod b/vendor/git.rootprojects.org/root/go-gitver/go.mod deleted file mode 100644 index af5f2ea..0000000 --- a/vendor/git.rootprojects.org/root/go-gitver/go.mod +++ /dev/null @@ -1,3 +0,0 @@ -module git.rootprojects.org/root/go-gitver - -go 1.12 diff --git a/vendor/git.rootprojects.org/root/go-gitver/.gitignore b/vendor/git.rootprojects.org/root/go-gitver/v2/.gitignore similarity index 86% rename from vendor/git.rootprojects.org/root/go-gitver/.gitignore rename to vendor/git.rootprojects.org/root/go-gitver/v2/.gitignore index bd0c823..ed6e7ee 100644 --- a/vendor/git.rootprojects.org/root/go-gitver/.gitignore +++ b/vendor/git.rootprojects.org/root/go-gitver/v2/.gitignore @@ -1,6 +1,10 @@ xversion.go zversion.go +/go-gitver +hello +examples/*/*.sum + # ---> Go # Binaries for programs and plugins *.exe diff --git a/vendor/git.rootprojects.org/root/go-gitver/v2/.prettierrc b/vendor/git.rootprojects.org/root/go-gitver/v2/.prettierrc new file mode 100644 index 0000000..0967ef4 --- /dev/null +++ b/vendor/git.rootprojects.org/root/go-gitver/v2/.prettierrc @@ -0,0 +1 @@ +{} diff --git a/vendor/git.rootprojects.org/root/go-gitver/LICENSE b/vendor/git.rootprojects.org/root/go-gitver/v2/LICENSE similarity index 100% rename from vendor/git.rootprojects.org/root/go-gitver/LICENSE rename to vendor/git.rootprojects.org/root/go-gitver/v2/LICENSE diff --git a/vendor/git.rootprojects.org/root/go-gitver/README.md b/vendor/git.rootprojects.org/root/go-gitver/v2/README.md similarity index 54% rename from vendor/git.rootprojects.org/root/go-gitver/README.md rename to vendor/git.rootprojects.org/root/go-gitver/v2/README.md index 8dcd0a5..bfddd74 100644 --- a/vendor/git.rootprojects.org/root/go-gitver/README.md +++ b/vendor/git.rootprojects.org/root/go-gitver/v2/README.md @@ -1,24 +1,79 @@ -# git-version.go +# [Go GitVer](https://git.rootprojects.org/root/go-gitver) -Use git tags to add semver to your go package. +Use **git tags** to add (GoRelesear-compatible) [**semver**](https://semver.org/) +to your go package in under 150 +[lines of code](https://git.rootprojects.org/root/go-gitver/src/branch/master/gitver/gitver.go). ```txt -Goal: Either use an exact version like v1.0.0 - or translate the git version like v1.0.0-4-g0000000 - to a semver like v1.0.1-pre4+g0000000 +Goals: + + 1. Use an exact `git tag` version, like v1.0.0, when clean + 2. Translate the `git describe` version (v1.0.0-4-g0000000) + to semver (1.0.1-pre4+g0000000) in between releases + 3. Note when `dirty` (and have build timestamp) Fail gracefully when git repo isn't available. ``` +# GoDoc + +See . + +# How it works + +1. You define the fallback version and version printing in `main.go`: + +```go +//go:generate go run git.rootprojects.org/root/go-gitver/v2 + +package main + +var ( + commit = "0000000" + version = "0.0.0-pre0+0000000" + date = "0000-00-00T00:00:00+0000" +) + +func main() { + if (len(os.Args) > 1 && "version" === os.Args[1]) { + fmt.Printf("Foobar v%s (%s) %s\n", version, commit[:7], date) + } + // ... +} +``` + +2. You `go generate` or `go run git.rootprojects.org/root/go-gitver/v2` to generate `xversion.go`: + +```go +package main + +func init() { + commit = "0921ed1e" + version = "1.1.2" + date = "2019-07-01T02:32:58-06:00" +} +``` + # Demo Generate an `xversion.go` file: ```bash -go run git.rootprojects.org/root/go-gitver +go run git.rootprojects.org/root/go-gitver/v2 cat xversion.go ``` +```go +// Code generated by go generate; DO NOT EDIT. +package main + +func init() { + commit = "6dace8255b52e123297a44629bc32c015add310a" + version = "1.1.4-pre2+g6dace82" + date = "2020-07-16T20:48:15-06:00" +} +``` + **Note**: The file is named `xversion.go` by default so that the generated file's `init()` will come later, and thus take priority, over most other files. @@ -26,15 +81,21 @@ most other files. See `go-gitver`s self-generated version: ```bash -go run git.rootprojects.org/root/go-gitver version +go run git.rootprojects.org/root/go-gitver/v2 version +``` + +```txt +6dace8255b52e123297a44629bc32c015add310a +v1.1.4-pre2+g6dace82 +2020-07-16T20:48:15-06:00 ``` # QuickStart -Add this to the top of your main file: +Add this to the top of your main file, so that it runs with `go generate`: ```go -//go:generate go run -mod=vendor git.rootprojects.org/root/go-gitver +//go:generate go run -mod=vendor git.rootprojects.org/root/go-gitver/v2 ``` @@ -45,7 +106,7 @@ Add a file that imports go-gitver (for versioning) package example -import _ "git.rootprojects.org/root/go-gitver" +import _ "git.rootprojects.org/root/go-gitver/v2" ``` Change you build instructions to be something like this: @@ -56,7 +117,7 @@ go generate -mod=vendor ./... go build -mod=vendor -o example cmd/example/*.go ``` -You don't have to use `mod vendor`, but I highly recommend it. +You don't have to use `-mod=vendor`, but I highly recommend it (just `go mod tidy; go mod vendor` to start). # Options @@ -77,12 +138,12 @@ GITVER_FAIL=true For example: ```go -//go:generate go run -mod=vendor git.rootprojects.org/root/go-gitver --fail +//go:generate go run -mod=vendor git.rootprojects.org/root/go-gitver/v2 --fail ``` ```bash -go run -mod=vendor git.rootprojects.org/root/go-gitver version +go run -mod=vendor git.rootprojects.org/root/go-gitver/v2 version ``` # Usage @@ -91,9 +152,9 @@ See `examples/basic` 1. Create a `tools` package in your project 2. Guard it against regular builds with `// +build tools` -3. Include `_ "git.rootprojects.org/root/go-gitver"` in the imports -4. Declare `var GitRev, GitVersion, GitTimestamp string` in your `package main` -5. Include `//go:generate go run -mod=vendor git.rootprojects.org/root/go-gitver` as well +3. Include `_ "git.rootprojects.org/root/go-gitver/v2"` in the imports +4. Declare `var commit, version, date string` in your `package main` +5. Include `//go:generate go run -mod=vendor git.rootprojects.org/root/go-gitver/v2` as well `tools/tools.go`: @@ -104,29 +165,29 @@ See `examples/basic` package tools import ( - _ "git.rootprojects.org/root/go-gitver" + _ "git.rootprojects.org/root/go-gitver/v2" ) ``` `main.go`: ```go -//go:generate go run git.rootprojects.org/root/go-gitver --fail +//go:generate go run git.rootprojects.org/root/go-gitver/v2 --fail package main import "fmt" var ( - GitRev = "0000000" - GitVersion = "v0.0.0-pre0+0000000" - GitTimestamp = "0000-00-00T00:00:00+0000" + commit = "0000000" + version = "0.0.0-pre0+0000000" + date = "0000-00-00T00:00:00+0000" ) func main() { - fmt.Println(GitRev) - fmt.Println(GitVersion) - fmt.Println(GitTimestamp) + fmt.Println(commit) + fmt.Println(version) + fmt.Println(date) } ``` @@ -134,7 +195,7 @@ If you're using `go mod vendor` (which I highly recommend that you do), you'd modify the `go:generate` ever so slightly: ```go -//go:generate go run -mod=vendor git.rootprojects.org/root/go-gitver --fail +//go:generate go run -mod=vendor git.rootprojects.org/root/go-gitver/v2 --fail ``` The only reason I didn't do that in the example is that I'd be included @@ -142,7 +203,7 @@ the repository in itself and that would be... weird. # Why a tools package? -> import "git.rootprojects.org/root/go-gitver" is a program, not an importable package +> import "git.rootprojects.org/root/go-gitver/v2" is a program, not an importable package Having a tools package with a build tag that you don't use is a nice way to add exact versions of a command package used for tooling to your `go.mod` with `go mod tidy`, @@ -182,8 +243,8 @@ git rev-parse HEAD ### cannot find package "." ```txt -package git.rootprojects.org/root/go-gitver: cannot find package "." in: - /Users/me/go-example/vendor/git.rootprojects.org/root/go-gitver +package git.rootprojects.org/root/go-gitver/v2: cannot find package "." in: + /Users/me/go-example/vendor/git.rootprojects.org/root/go-gitver/v2 cmd/example/example.go:1: running "go": exit status 1 ``` diff --git a/vendor/git.rootprojects.org/root/go-gitver/gitver.go b/vendor/git.rootprojects.org/root/go-gitver/v2/gitver.go similarity index 84% rename from vendor/git.rootprojects.org/root/go-gitver/gitver.go rename to vendor/git.rootprojects.org/root/go-gitver/v2/gitver.go index a0641e4..e4b86fd 100644 --- a/vendor/git.rootprojects.org/root/go-gitver/gitver.go +++ b/vendor/git.rootprojects.org/root/go-gitver/v2/gitver.go @@ -1,4 +1,4 @@ -//go:generate go run -mod=vendor git.rootprojects.org/root/go-gitver +//go:generate go run -mod=vendor git.rootprojects.org/root/go-gitver/v2 package main @@ -10,10 +10,10 @@ import ( "text/template" "time" - "git.rootprojects.org/root/go-gitver/gitver" + "git.rootprojects.org/root/go-gitver/v2/gitver" ) -var GitRev, GitVersion, GitTimestamp string +var commit, version, date string var exitCode int var verFile = "xversion.go" @@ -32,9 +32,9 @@ func main() { pkg = args[i+1] args[i+1] = "" } else if "-V" == arg || "version" == arg || "-version" == arg || "--version" == arg { - fmt.Println(GitRev) - fmt.Println(GitVersion) - fmt.Println(GitTimestamp) + fmt.Println(commit) + fmt.Println(version) + fmt.Println(date) os.Exit(0) } } @@ -59,12 +59,12 @@ func main() { Package string Timestamp string Version string - GitRev string + Commit string }{ Package: pkg, Timestamp: v.Timestamp.Format(time.RFC3339), Version: v.Version, - GitRev: v.Rev, + Commit: v.Rev, }); nil != err { panic(err) } @@ -93,12 +93,12 @@ var versionTpl = template.Must(template.New("").Parse(`// Code generated by go g package {{ .Package }} func init() { - {{ if .GitRev -}} - GitRev = "{{ .GitRev }}" + {{ if .Commit -}} + commit = "{{ .Commit }}" {{ end -}} {{ if .Version -}} - GitVersion = "{{ .Version }}" + version = "{{ .Version }}" {{ end -}} - GitTimestamp = "{{ .Timestamp }}" + date = "{{ .Timestamp }}" } `)) diff --git a/vendor/git.rootprojects.org/root/go-gitver/gitver/gitver.go b/vendor/git.rootprojects.org/root/go-gitver/v2/gitver/gitver.go similarity index 86% rename from vendor/git.rootprojects.org/root/go-gitver/gitver/gitver.go rename to vendor/git.rootprojects.org/root/go-gitver/v2/gitver/gitver.go index fc04418..1c00863 100644 --- a/vendor/git.rootprojects.org/root/go-gitver/gitver/gitver.go +++ b/vendor/git.rootprojects.org/root/go-gitver/v2/gitver/gitver.go @@ -21,12 +21,14 @@ func init() { gitVer = regexp.MustCompile(`^(v\d+\.\d+)\.(\d+)(-(\d+))?(-(g[0-9a-f]+))?(-(dirty))?`) } +// Versions describes the various version properties type Versions struct { Timestamp time.Time Version string Rev string } +// ExecAndParse will run git and parse the output func ExecAndParse() (*Versions, error) { desc, err := gitDesc() if nil != err { @@ -58,7 +60,7 @@ func gitDesc() (string, error) { out, err := cmd.CombinedOutput() if nil != err { // Don't panic, just carry on - //out = []byte("v0.0.0-0-g0000000") + //out = []byte("0.0.0-0-g0000000") return "", err } return strings.TrimSpace(string(out)), nil @@ -83,7 +85,7 @@ func gitRev() (string, error) { func semVer(desc string) (string, error) { if exactVer.MatchString(desc) { // v1.0.0 - return desc, nil + return strings.TrimPrefix(desc, "v"), nil } if !gitVer.MatchString(desc) { @@ -122,10 +124,19 @@ func semVer(desc string) (string, error) { ver += vers[8] } - return ver, nil + return strings.TrimPrefix(ver, "v"), nil } func gitTimestamp(desc string) (time.Time, error) { + // Other options: + // + // Commit Date + // git log -1 --format=%cd --date=format:%Y-%m-%dT%H:%M:%SZ%z + // + // Author Date + // git log -1 --format=%ad --date=format:%Y-%m-%dT%H:%M:%SZ%z + // + // I think I chose this because it would account for dirty-ness better... maybe? args := []string{ "git", "show", desc, diff --git a/vendor/git.rootprojects.org/root/go-gitver/v2/go.mod b/vendor/git.rootprojects.org/root/go-gitver/v2/go.mod new file mode 100644 index 0000000..4f805eb --- /dev/null +++ b/vendor/git.rootprojects.org/root/go-gitver/v2/go.mod @@ -0,0 +1,3 @@ +module git.rootprojects.org/root/go-gitver/v2 + +go 1.12 diff --git a/vendor/git.rootprojects.org/root/go-gitver/v2/go.sum b/vendor/git.rootprojects.org/root/go-gitver/v2/go.sum new file mode 100644 index 0000000..dd58ff6 --- /dev/null +++ b/vendor/git.rootprojects.org/root/go-gitver/v2/go.sum @@ -0,0 +1,2 @@ +git.rootprojects.org/root/go-gitver v1.1.3 h1:/qR9z53vY+IFhWRxLkF9cjaiWh8xRJIm6gyuW+MG81A= +git.rootprojects.org/root/go-gitver v1.1.3/go.mod h1:Rj1v3TBhvdaSphFEqMynUYwAz/4f+wY/+syBTvRrmlI= diff --git a/vendor/git.rootprojects.org/root/go-gitver/version.go b/vendor/git.rootprojects.org/root/go-gitver/v2/version.go similarity index 52% rename from vendor/git.rootprojects.org/root/go-gitver/version.go rename to vendor/git.rootprojects.org/root/go-gitver/v2/version.go index daa07e0..16f94fe 100644 --- a/vendor/git.rootprojects.org/root/go-gitver/version.go +++ b/vendor/git.rootprojects.org/root/go-gitver/v2/version.go @@ -3,7 +3,7 @@ package main // use recently generated version info as a fallback // for when git isn't present (i.e. go run ) func init() { - GitRev = "0921ed1e6007493c886c87ee9a15f2cceecb1f9f" - GitVersion = "v1.1.2" - GitTimestamp = "2019-07-01T02:32:58-06:00" + commit = "37c1fd4b5694fd62c9f0d6ad1df47d938accbeec" + version = "2.0.0-pre1-dirty" + date = "2020-10-10T16:05:59-06:00" } diff --git a/vendor/modules.txt b/vendor/modules.txt index 6a8c0cc..c626934 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -1,7 +1,7 @@ -# git.rootprojects.org/root/go-gitver v1.1.3 +# git.rootprojects.org/root/go-gitver/v2 v2.0.2 ## explicit -git.rootprojects.org/root/go-gitver -git.rootprojects.org/root/go-gitver/gitver +git.rootprojects.org/root/go-gitver/v2 +git.rootprojects.org/root/go-gitver/v2/gitver # github.com/alexbrainman/sspi v0.0.0-20180613141037-e580b900e9f5 github.com/alexbrainman/sspi github.com/alexbrainman/sspi/negotiate