update versioning for gitver, goreleaser

This commit is contained in:
AJ ONeal 2020-11-13 04:53:01 -07:00
parent dfae626dcd
commit b7de32833a
25 changed files with 179 additions and 104 deletions

View File

@ -87,7 +87,7 @@ pushd telebit/
You can build with `go build`: You can build with `go build`:
```bash ```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`: Or with `goreleaser`:
@ -96,6 +96,8 @@ Or with `goreleaser`:
goreleaser --rm-dist --skip-publish --snapshot goreleaser --rm-dist --skip-publish --snapshot
``` ```
See https://webinstall.dev/goreleaser for cheat sheet.
## Install Go ## Install Go
To install Go (on any of Windows, Mac, or Linux), see <https://webinstall.dev/golang>. To install Go (on any of Windows, Mac, or Linux), see <https://webinstall.dev/golang>.

View File

@ -31,11 +31,11 @@ CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build \
-mod=vendor \ -mod=vendor \
-ldflags="-X 'main.VendorID=$VENDOR_ID'" \ -ldflags="-X 'main.VendorID=$VENDOR_ID'" \
-o telebit-debug.exe \ -o telebit-debug.exe \
./cmd/telebit/telebit.go ./cmd/telebit/*.go
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build \ CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build \
-mod=vendor \ -mod=vendor \
-ldflags "-H windowsgui -X 'main.VendorID=$VENDOR_ID'" \ -ldflags "-H windowsgui -X 'main.VendorID=$VENDOR_ID'" \
-o telebit-windows.exe \ -o telebit-windows.exe \
./cmd/telebit/telebit.go ./cmd/telebit/*.go
``` ```

View File

@ -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

View File

@ -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 package main
@ -18,12 +18,12 @@ import (
) )
var ( var (
// GitRev refers to the abbreviated commit hash // commit refers to the abbreviated commit hash
GitRev = "0000000" commit = "0000000"
// GitVersion refers to the most recent tag, plus any commits made since then // version refers to the most recent tag, plus any commits made since then
GitVersion = "v0.0.0-pre0+0000000" version = "v0.0.0-pre0+0000000"
// GitTimestamp refers to the timestamp of the most recent commit // 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() { func main() {
@ -38,9 +38,10 @@ func main() {
flag.Parse() flag.Parse()
if len(os.Args) >= 2 { if len(os.Args) >= 2 {
if "version" == os.Args[1] { if "version" == strings.TrimLeft(os.Args[1], "-") {
fmt.Printf("telebit %s %s %s", GitVersion, GitRev, GitTimestamp) fmt.Printf("telebit %s (%s) %s\n", version, commit[:7], date)
os.Exit(0) os.Exit(0)
return
} }
} }

View File

@ -7,7 +7,7 @@ import (
"fmt" "fmt"
"os" "os"
"git.rootprojects.org/root/telebit/mgmt/authstore" "git.rootprojects.org/root/telebit/internal/mgmt/authstore"
"github.com/denisbrodbeck/machineid" "github.com/denisbrodbeck/machineid"
_ "github.com/joho/godotenv/autoload" _ "github.com/joho/godotenv/autoload"

View File

@ -77,7 +77,7 @@ The admin token can be used to interact with the server.
```bash ```bash
VENDOR_ID="example.com" VENDOR_ID="example.com"
MGMT_SECRET=XxX-mgmt-secret-XxX MGMT_SECRET=XxX-mgmt-secret-XxX
ADMIN_TOKEN=$(go run cmd/signjwt/signjwt.go \ ADMIN_TOKEN=$(go run cmd/signjwt/*.go \
--debug \ --debug \
--expires-in 15m \ --expires-in 15m \
--vendor-id $VENDOR_ID \ --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`: You can build with `go build`:
```bash ```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`: Or with `goreleaser`:

View File

@ -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 package main
@ -22,12 +22,12 @@ import (
) )
var ( var (
// GitRev refers to the abbreviated commit hash // commit refers to the abbreviated commit hash
GitRev = "0000000" commit = "0000000"
// GitVersion refers to the most recent tag, plus any commits made since then // version refers to the most recent tag, plus any commits made since then
GitVersion = "v0.0.0-pre0+0000000" version = "v0.0.0-pre0+0000000"
// GitTimestamp refers to the timestamp of the most recent commit // 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 var store authstore.Store
@ -38,6 +38,14 @@ func help() {
} }
func main() { 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 err error
var port string var port string

View File

@ -5,7 +5,7 @@ import (
"log" "log"
"strings" "strings"
"git.rootprojects.org/root/telebit/mgmt/authstore" "git.rootprojects.org/root/telebit/internal/mgmt/authstore"
) )
func main() { func main() {

View File

@ -100,7 +100,7 @@ bash examples/admin-disconnect-device.sh
You can build with `go build`: You can build with `go build`:
```bash ```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`: Or with `goreleaser`:

View File

@ -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 package main
@ -61,12 +61,12 @@ const (
) )
var ( var (
// GitRev refers to the abbreviated commit hash // commit refers to the abbreviated commit hash
GitRev = "0000000" commit = "0000000"
// GitVersion refers to the most recent tag, plus any commits made since then // version refers to the most recent tag, plus any commits made since then
GitVersion = "v0.0.0-pre0+0000000" version = "v0.0.0-pre0+0000000"
// GitTimestamp refers to the timestamp of the most recent commit // 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 is the service name
serviceName = "telebit" serviceName = "telebit"
@ -94,7 +94,7 @@ var ClientSecret string
func main() { func main() {
if len(os.Args) >= 2 { if len(os.Args) >= 2 {
if "version" == strings.TrimLeft(os.Args[1], "-") { 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) os.Exit(exitOk)
return return
} }

View File

@ -11,9 +11,9 @@ import (
"strings" "strings"
"time" "time"
telebit "git.rootprojects.org/root/telebit" "git.rootprojects.org/root/telebit"
"git.rootprojects.org/root/telebit/mgmt" "git.rootprojects.org/root/telebit/internal/mgmt"
"git.rootprojects.org/root/telebit/mgmt/authstore" "git.rootprojects.org/root/telebit/internal/mgmt/authstore"
"github.com/denisbrodbeck/machineid" "github.com/denisbrodbeck/machineid"
"github.com/gorilla/websocket" "github.com/gorilla/websocket"
@ -50,7 +50,7 @@ func main() {
ppid = base64.RawURLEncoding.EncodeToString(ppidBytes) ppid = base64.RawURLEncoding.EncodeToString(ppidBytes)
fmt.Println("[debug] vendor-id, secret, ppid", *vendorID, *secret, ppid) fmt.Println("[debug] vendor-id, secret, ppid", *vendorID, *secret, ppid)
if 0 == len(*token) { if 0 == len(*token) {
*token, err = authstore.HMACToken(ppid) *token, err = authstore.HMACToken(ppid, 15*time.Minute)
if nil != err { if nil != err {
fmt.Fprintf(os.Stderr, "neither secret nor token provided\n") fmt.Fprintf(os.Stderr, "neither secret nor token provided\n")
os.Exit(1) os.Exit(1)

2
go.mod
View File

@ -5,7 +5,7 @@ go 1.14
replace github.com/caddyserver/certmagic => github.com/coolaj86/certmagic v0.12.1-pre.2 replace github.com/caddyserver/certmagic => github.com/coolaj86/certmagic v0.12.1-pre.2
require ( 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/coolaj86/certmagic v0.12.1-pre.2
github.com/denisbrodbeck/machineid v1.0.1 github.com/denisbrodbeck/machineid v1.0.1
github.com/dgrijalva/jwt-go v3.2.0+incompatible github.com/dgrijalva/jwt-go v3.2.0+incompatible

4
go.sum
View File

@ -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= 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= 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= 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/v2 v2.0.2 h1:T+Je13wrY1jz4OPJF98HnuCNp6n2Xe2uK6/NNF6a4+0=
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/go.mod h1:ur82M/jZcvr1WWihyVtNEgDBqIjo22o56wcVHeVJFh8=
github.com/Azure/azure-sdk-for-go v32.4.0+incompatible/go.mod h1:9XXNKU+eRnpl9moKnB4QOLf1HestfXbmab5FXxiDBjc= 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.1.0/go.mod h1:AKyIcETwSUFxIcs/Wnq/C+kwCtlEYGUVd7FPNb2slmg=
github.com/Azure/go-autorest/autorest v0.5.0/go.mod h1:9HLKlQjVBH6U3oDfsXOeVc56THsLPw1L03yban4xThw= github.com/Azure/go-autorest/autorest v0.5.0/go.mod h1:9HLKlQjVBH6U3oDfsXOeVc56THsLPw1L03yban4xThw=

View File

@ -5,7 +5,7 @@ package tools
import ( import (
// these are binaries // these are binaries
_ "git.rootprojects.org/root/go-gitver" _ "git.rootprojects.org/root/go-gitver/v2"
_ "github.com/shurcooL/vfsgen" _ "github.com/shurcooL/vfsgen"
_ "github.com/shurcooL/vfsgen/cmd/vfsgendev" _ "github.com/shurcooL/vfsgen/cmd/vfsgendev"
) )

View File

@ -1,3 +0,0 @@
module git.rootprojects.org/root/go-gitver
go 1.12

View File

@ -1,6 +1,10 @@
xversion.go xversion.go
zversion.go zversion.go
/go-gitver
hello
examples/*/*.sum
# ---> Go # ---> Go
# Binaries for programs and plugins # Binaries for programs and plugins
*.exe *.exe

View File

@ -0,0 +1 @@
{}

View File

@ -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 ```txt
Goal: Either use an exact version like v1.0.0 Goals:
or translate the git version like v1.0.0-4-g0000000
to a semver like v1.0.1-pre4+g0000000 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. Fail gracefully when git repo isn't available.
``` ```
# GoDoc
See <https://pkg.go.dev/git.rootprojects.org/root/go-gitver/v2>.
# 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 # Demo
Generate an `xversion.go` file: Generate an `xversion.go` file:
```bash ```bash
go run git.rootprojects.org/root/go-gitver go run git.rootprojects.org/root/go-gitver/v2
cat xversion.go 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"
}
```
<small>**Note**: The file is named `xversion.go` by default so that the <small>**Note**: The file is named `xversion.go` by default so that the
generated file's `init()` will come later, and thus take priority, over generated file's `init()` will come later, and thus take priority, over
most other files.</small> most other files.</small>
@ -26,15 +81,21 @@ most other files.</small>
See `go-gitver`s self-generated version: See `go-gitver`s self-generated version:
```bash ```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 # 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
//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 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: 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 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 # Options
@ -77,12 +138,12 @@ GITVER_FAIL=true
For example: For example:
```go ```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 ```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 # Usage
@ -91,9 +152,9 @@ See `examples/basic`
1. Create a `tools` package in your project 1. Create a `tools` package in your project
2. Guard it against regular builds with `// +build tools` 2. Guard it against regular builds with `// +build tools`
3. Include `_ "git.rootprojects.org/root/go-gitver"` in the imports 3. Include `_ "git.rootprojects.org/root/go-gitver/v2"` in the imports
4. Declare `var GitRev, GitVersion, GitTimestamp string` in your `package main` 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` as well 5. Include `//go:generate go run -mod=vendor git.rootprojects.org/root/go-gitver/v2` as well
`tools/tools.go`: `tools/tools.go`:
@ -104,29 +165,29 @@ See `examples/basic`
package tools package tools
import ( import (
_ "git.rootprojects.org/root/go-gitver" _ "git.rootprojects.org/root/go-gitver/v2"
) )
``` ```
`main.go`: `main.go`:
```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 package main
import "fmt" import "fmt"
var ( var (
GitRev = "0000000" commit = "0000000"
GitVersion = "v0.0.0-pre0+0000000" version = "0.0.0-pre0+0000000"
GitTimestamp = "0000-00-00T00:00:00+0000" date = "0000-00-00T00:00:00+0000"
) )
func main() { func main() {
fmt.Println(GitRev) fmt.Println(commit)
fmt.Println(GitVersion) fmt.Println(version)
fmt.Println(GitTimestamp) 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: you'd modify the `go:generate` ever so slightly:
```go ```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 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? # 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 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`, 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 "." ### cannot find package "."
```txt ```txt
package git.rootprojects.org/root/go-gitver: cannot find package "." in: package git.rootprojects.org/root/go-gitver/v2: cannot find package "." in:
/Users/me/go-example/vendor/git.rootprojects.org/root/go-gitver /Users/me/go-example/vendor/git.rootprojects.org/root/go-gitver/v2
cmd/example/example.go:1: running "go": exit status 1 cmd/example/example.go:1: running "go": exit status 1
``` ```

View File

@ -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 package main
@ -10,10 +10,10 @@ import (
"text/template" "text/template"
"time" "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 exitCode int
var verFile = "xversion.go" var verFile = "xversion.go"
@ -32,9 +32,9 @@ func main() {
pkg = args[i+1] pkg = args[i+1]
args[i+1] = "" args[i+1] = ""
} else if "-V" == arg || "version" == arg || "-version" == arg || "--version" == arg { } else if "-V" == arg || "version" == arg || "-version" == arg || "--version" == arg {
fmt.Println(GitRev) fmt.Println(commit)
fmt.Println(GitVersion) fmt.Println(version)
fmt.Println(GitTimestamp) fmt.Println(date)
os.Exit(0) os.Exit(0)
} }
} }
@ -59,12 +59,12 @@ func main() {
Package string Package string
Timestamp string Timestamp string
Version string Version string
GitRev string Commit string
}{ }{
Package: pkg, Package: pkg,
Timestamp: v.Timestamp.Format(time.RFC3339), Timestamp: v.Timestamp.Format(time.RFC3339),
Version: v.Version, Version: v.Version,
GitRev: v.Rev, Commit: v.Rev,
}); nil != err { }); nil != err {
panic(err) panic(err)
} }
@ -93,12 +93,12 @@ var versionTpl = template.Must(template.New("").Parse(`// Code generated by go g
package {{ .Package }} package {{ .Package }}
func init() { func init() {
{{ if .GitRev -}} {{ if .Commit -}}
GitRev = "{{ .GitRev }}" commit = "{{ .Commit }}"
{{ end -}} {{ end -}}
{{ if .Version -}} {{ if .Version -}}
GitVersion = "{{ .Version }}" version = "{{ .Version }}"
{{ end -}} {{ end -}}
GitTimestamp = "{{ .Timestamp }}" date = "{{ .Timestamp }}"
} }
`)) `))

View File

@ -21,12 +21,14 @@ func init() {
gitVer = regexp.MustCompile(`^(v\d+\.\d+)\.(\d+)(-(\d+))?(-(g[0-9a-f]+))?(-(dirty))?`) gitVer = regexp.MustCompile(`^(v\d+\.\d+)\.(\d+)(-(\d+))?(-(g[0-9a-f]+))?(-(dirty))?`)
} }
// Versions describes the various version properties
type Versions struct { type Versions struct {
Timestamp time.Time Timestamp time.Time
Version string Version string
Rev string Rev string
} }
// ExecAndParse will run git and parse the output
func ExecAndParse() (*Versions, error) { func ExecAndParse() (*Versions, error) {
desc, err := gitDesc() desc, err := gitDesc()
if nil != err { if nil != err {
@ -58,7 +60,7 @@ func gitDesc() (string, error) {
out, err := cmd.CombinedOutput() out, err := cmd.CombinedOutput()
if nil != err { if nil != err {
// Don't panic, just carry on // Don't panic, just carry on
//out = []byte("v0.0.0-0-g0000000") //out = []byte("0.0.0-0-g0000000")
return "", err return "", err
} }
return strings.TrimSpace(string(out)), nil return strings.TrimSpace(string(out)), nil
@ -83,7 +85,7 @@ func gitRev() (string, error) {
func semVer(desc string) (string, error) { func semVer(desc string) (string, error) {
if exactVer.MatchString(desc) { if exactVer.MatchString(desc) {
// v1.0.0 // v1.0.0
return desc, nil return strings.TrimPrefix(desc, "v"), nil
} }
if !gitVer.MatchString(desc) { if !gitVer.MatchString(desc) {
@ -122,10 +124,19 @@ func semVer(desc string) (string, error) {
ver += vers[8] ver += vers[8]
} }
return ver, nil return strings.TrimPrefix(ver, "v"), nil
} }
func gitTimestamp(desc string) (time.Time, error) { 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{ args := []string{
"git", "git",
"show", desc, "show", desc,

3
vendor/git.rootprojects.org/root/go-gitver/v2/go.mod generated vendored Normal file
View File

@ -0,0 +1,3 @@
module git.rootprojects.org/root/go-gitver/v2
go 1.12

2
vendor/git.rootprojects.org/root/go-gitver/v2/go.sum generated vendored Normal file
View File

@ -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=

View File

@ -3,7 +3,7 @@ package main
// use recently generated version info as a fallback // use recently generated version info as a fallback
// for when git isn't present (i.e. go run <url>) // for when git isn't present (i.e. go run <url>)
func init() { func init() {
GitRev = "0921ed1e6007493c886c87ee9a15f2cceecb1f9f" commit = "37c1fd4b5694fd62c9f0d6ad1df47d938accbeec"
GitVersion = "v1.1.2" version = "2.0.0-pre1-dirty"
GitTimestamp = "2019-07-01T02:32:58-06:00" date = "2020-10-10T16:05:59-06:00"
} }

6
vendor/modules.txt vendored
View File

@ -1,7 +1,7 @@
# git.rootprojects.org/root/go-gitver v1.1.3 # git.rootprojects.org/root/go-gitver/v2 v2.0.2
## explicit ## explicit
git.rootprojects.org/root/go-gitver git.rootprojects.org/root/go-gitver/v2
git.rootprojects.org/root/go-gitver/gitver git.rootprojects.org/root/go-gitver/v2/gitver
# github.com/alexbrainman/sspi v0.0.0-20180613141037-e580b900e9f5 # github.com/alexbrainman/sspi v0.0.0-20180613141037-e580b900e9f5
github.com/alexbrainman/sspi github.com/alexbrainman/sspi
github.com/alexbrainman/sspi/negotiate github.com/alexbrainman/sspi/negotiate