update versioning for gitver, goreleaser
This commit is contained in:
parent
dfae626dcd
commit
b7de32833a
|
@ -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 <https://webinstall.dev/golang>.
|
||||
|
|
|
@ -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
|
||||
```
|
||||
|
|
|
@ -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
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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`:
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -5,7 +5,7 @@ import (
|
|||
"log"
|
||||
"strings"
|
||||
|
||||
"git.rootprojects.org/root/telebit/mgmt/authstore"
|
||||
"git.rootprojects.org/root/telebit/internal/mgmt/authstore"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
|
|
@ -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`:
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
2
go.mod
2
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
|
||||
|
|
4
go.sum
4
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=
|
||||
|
|
|
@ -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"
|
||||
)
|
||||
|
|
|
@ -1,3 +0,0 @@
|
|||
module git.rootprojects.org/root/go-gitver
|
||||
|
||||
go 1.12
|
|
@ -1,6 +1,10 @@
|
|||
xversion.go
|
||||
zversion.go
|
||||
|
||||
/go-gitver
|
||||
hello
|
||||
examples/*/*.sum
|
||||
|
||||
# ---> Go
|
||||
# Binaries for programs and plugins
|
||||
*.exe
|
|
@ -0,0 +1 @@
|
|||
{}
|
|
@ -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 <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
|
||||
|
||||
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"
|
||||
}
|
||||
```
|
||||
|
||||
<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
|
||||
most other files.</small>
|
||||
|
@ -26,15 +81,21 @@ most other files.</small>
|
|||
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
|
||||
```
|
||||
|
|
@ -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 }}"
|
||||
}
|
||||
`))
|
|
@ -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,
|
|
@ -0,0 +1,3 @@
|
|||
module git.rootprojects.org/root/go-gitver/v2
|
||||
|
||||
go 1.12
|
|
@ -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=
|
|
@ -3,7 +3,7 @@ package main
|
|||
// use recently generated version info as a fallback
|
||||
// for when git isn't present (i.e. go run <url>)
|
||||
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"
|
||||
}
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue