Compare commits
2 Commits
1ee983f56d
...
3409d5f2e4
Author | SHA1 | Date |
---|---|---|
AJ ONeal | 3409d5f2e4 | |
AJ ONeal | cfbbc73f48 |
|
@ -2,7 +2,8 @@ xversion.go
|
||||||
zversion.go
|
zversion.go
|
||||||
|
|
||||||
/go-gitver
|
/go-gitver
|
||||||
examples/**.sum
|
hello
|
||||||
|
examples/*/*.sum
|
||||||
|
|
||||||
# ---> Go
|
# ---> Go
|
||||||
# Binaries for programs and plugins
|
# Binaries for programs and plugins
|
||||||
|
|
34
README.md
34
README.md
|
@ -17,14 +17,14 @@ Goals:
|
||||||
|
|
||||||
# GoDoc
|
# GoDoc
|
||||||
|
|
||||||
See <https://pkg.go.dev/git.rootprojects.org/root/go-gitver>.
|
See <https://pkg.go.dev/git.rootprojects.org/root/go-gitver/v2>.
|
||||||
|
|
||||||
# How it works
|
# How it works
|
||||||
|
|
||||||
1. You define the fallback version and version printing in `main.go`:
|
1. You define the fallback version and version printing in `main.go`:
|
||||||
|
|
||||||
```go
|
```go
|
||||||
//go:generate go run git.rootprojects.org/root/go-gitver
|
//go:generate go run git.rootprojects.org/root/go-gitver/v2
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@ func main() {
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
2. You `go generate` or `go run git.rootprojects.org/root/go-gitver` to generate `xversion.go`:
|
2. You `go generate` or `go run git.rootprojects.org/root/go-gitver/v2` to generate `xversion.go`:
|
||||||
|
|
||||||
```go
|
```go
|
||||||
package main
|
package main
|
||||||
|
@ -59,7 +59,7 @@ func init() {
|
||||||
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
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -81,7 +81,7 @@ 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
|
```txt
|
||||||
|
@ -95,7 +95,7 @@ v1.1.4-pre2+g6dace82
|
||||||
Add this to the top of your main file, so that it runs with `go generate`:
|
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
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -106,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:
|
||||||
|
@ -138,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
|
||||||
|
@ -152,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 commit, version, date 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`:
|
||||||
|
|
||||||
|
@ -165,14 +165,14 @@ 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
|
||||||
|
|
||||||
|
@ -195,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
|
||||||
|
@ -203,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`,
|
||||||
|
@ -243,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
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
@ -2,4 +2,4 @@ module example.com/hello
|
||||||
|
|
||||||
go 1.12
|
go 1.12
|
||||||
|
|
||||||
require git.rootprojects.org/root/go-gitver v1.1.0
|
require git.rootprojects.org/root/go-gitver/v2 v2.0.2
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
//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
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
|
|
|
@ -4,5 +4,5 @@
|
||||||
package tools
|
package tools
|
||||||
|
|
||||||
import (
|
import (
|
||||||
_ "git.rootprojects.org/root/go-gitver"
|
_ "git.rootprojects.org/root/go-gitver/v2"
|
||||||
)
|
)
|
||||||
|
|
|
@ -2,4 +2,4 @@ module example.com/hello
|
||||||
|
|
||||||
go 1.12
|
go 1.12
|
||||||
|
|
||||||
require git.rootprojects.org/root/go-gitver v1.1.0
|
require git.rootprojects.org/root/go-gitver/v2 v2.0.2
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
//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
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
|
|
|
@ -3,4 +3,4 @@
|
||||||
// This is a dummy file for build tooling
|
// This is a dummy file for build tooling
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import _ "git.rootprojects.org/root/go-gitver"
|
import _ "git.rootprojects.org/root/go-gitver/v2"
|
||||||
|
|
|
@ -2,4 +2,4 @@ module example.com/hello
|
||||||
|
|
||||||
go 1.12
|
go 1.12
|
||||||
|
|
||||||
require git.rootprojects.org/root/go-gitver v1.1.0
|
require git.rootprojects.org/root/go-gitver/v2 v2.0.2
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
//go:generate go run -mod=vendor git.rootprojects.org/root/go-gitver --package version --outfile ./version/zversion.go
|
//go:generate go run -mod=vendor git.rootprojects.org/root/go-gitver/v2 --package version --outfile ./version/zversion.go
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
|
@ -14,9 +14,9 @@ func main() {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
if *showVersion {
|
if *showVersion {
|
||||||
fmt.Println(version.commit)
|
fmt.Println(version.Commit())
|
||||||
fmt.Println(version.version)
|
fmt.Println(version.Version())
|
||||||
fmt.Println(version.date)
|
fmt.Println(version.Date())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,5 +4,5 @@
|
||||||
package tools
|
package tools
|
||||||
|
|
||||||
import (
|
import (
|
||||||
_ "git.rootprojects.org/root/go-gitver"
|
_ "git.rootprojects.org/root/go-gitver/v2"
|
||||||
)
|
)
|
||||||
|
|
|
@ -5,3 +5,18 @@ var (
|
||||||
version = "0.0.0-pre0+0000000"
|
version = "0.0.0-pre0+0000000"
|
||||||
date = "0000-00-00T00:00:00+0000"
|
date = "0000-00-00T00:00:00+0000"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Commit returns the git commit reference
|
||||||
|
func Commit() string {
|
||||||
|
return commit
|
||||||
|
}
|
||||||
|
|
||||||
|
// Version returns the git version, without the leading 'v'
|
||||||
|
func Version() string {
|
||||||
|
return version
|
||||||
|
}
|
||||||
|
|
||||||
|
// Date returns the ISO-formatted date string
|
||||||
|
func Date() string {
|
||||||
|
return date
|
||||||
|
}
|
||||||
|
|
|
@ -2,4 +2,4 @@ module example.com/hello
|
||||||
|
|
||||||
go 1.12
|
go 1.12
|
||||||
|
|
||||||
require git.rootprojects.org/root/go-gitver v1.1.0
|
require git.rootprojects.org/root/go-gitver/v2 v2.0.2
|
||||||
|
|
|
@ -12,9 +12,9 @@ func main() {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
if *showVersion {
|
if *showVersion {
|
||||||
fmt.Println(version.commit)
|
fmt.Println(version.Commit())
|
||||||
fmt.Println(version.version)
|
fmt.Println(version.Version())
|
||||||
fmt.Println(version.date)
|
fmt.Println(version.Date())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,5 +4,5 @@
|
||||||
package tools
|
package tools
|
||||||
|
|
||||||
import (
|
import (
|
||||||
_ "git.rootprojects.org/root/go-gitver"
|
_ "git.rootprojects.org/root/go-gitver/v2"
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
//go:generate go run -mod=vendor git.rootprojects.org/root/go-gitver --package version
|
//go:generate go run -mod=vendor git.rootprojects.org/root/go-gitver/v2 --package version
|
||||||
|
|
||||||
package version
|
package version
|
||||||
|
|
||||||
|
@ -7,3 +7,18 @@ var (
|
||||||
version = "0.0.0-pre0+0000000"
|
version = "0.0.0-pre0+0000000"
|
||||||
date = "0000-00-00T00:00:00+0000"
|
date = "0000-00-00T00:00:00+0000"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Commit returns the git commit reference
|
||||||
|
func Commit() string {
|
||||||
|
return commit
|
||||||
|
}
|
||||||
|
|
||||||
|
// Version returns the git version, without the leading 'v'
|
||||||
|
func Version() string {
|
||||||
|
return version
|
||||||
|
}
|
||||||
|
|
||||||
|
// Date returns the ISO-formatted date string
|
||||||
|
func Date() string {
|
||||||
|
return date
|
||||||
|
}
|
||||||
|
|
|
@ -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,7 +10,7 @@ import (
|
||||||
"text/template"
|
"text/template"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"git.rootprojects.org/root/go-gitver/gitver"
|
"git.rootprojects.org/root/go-gitver/v2/gitver"
|
||||||
)
|
)
|
||||||
|
|
||||||
var commit, version, date string
|
var commit, version, date string
|
||||||
|
|
Loading…
Reference in New Issue