From cfbbc73f4888a156643517e6f9023005cf021246 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Mon, 12 Oct 2020 14:42:55 -0600 Subject: [PATCH] complete transition to v2 --- .gitignore | 3 ++- README.md | 34 ++++++++++++------------ examples/basic/go.mod | 4 ++- examples/basic/main.go | 2 +- examples/basic/tools/tools.go | 2 +- examples/no-tools/go.mod | 4 ++- examples/no-tools/main.go | 2 +- examples/no-tools/tools.go | 2 +- examples/special-name/go.mod | 4 ++- examples/special-name/main.go | 8 +++--- examples/special-name/tools/tools.go | 2 +- examples/special-name/version/version.go | 15 +++++++++++ examples/sub-package/go.mod | 4 ++- examples/sub-package/main.go | 6 ++--- examples/sub-package/tools/tools.go | 2 +- examples/sub-package/version/version.go | 17 +++++++++++- gitver.go | 4 +-- go.sum | 2 ++ 18 files changed, 79 insertions(+), 38 deletions(-) create mode 100644 go.sum diff --git a/.gitignore b/.gitignore index b922513..ed6e7ee 100644 --- a/.gitignore +++ b/.gitignore @@ -2,7 +2,8 @@ xversion.go zversion.go /go-gitver -examples/**.sum +hello +examples/*/*.sum # ---> Go # Binaries for programs and plugins diff --git a/README.md b/README.md index 3ffc6ab..bfddd74 100644 --- a/README.md +++ b/README.md @@ -17,14 +17,14 @@ Goals: # GoDoc -See . +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 +//go:generate go run git.rootprojects.org/root/go-gitver/v2 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 package main @@ -59,7 +59,7 @@ func init() { 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 ``` @@ -81,7 +81,7 @@ 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 @@ -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`: ```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 -import _ "git.rootprojects.org/root/go-gitver" +import _ "git.rootprojects.org/root/go-gitver/v2" ``` Change you build instructions to be something like this: @@ -138,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 @@ -152,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 +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` as well +5. Include `//go:generate go run -mod=vendor git.rootprojects.org/root/go-gitver/v2` as well `tools/tools.go`: @@ -165,14 +165,14 @@ 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 @@ -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: ```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 @@ -203,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`, @@ -243,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/examples/basic/go.mod b/examples/basic/go.mod index 0996999..909a264 100644 --- a/examples/basic/go.mod +++ b/examples/basic/go.mod @@ -2,4 +2,6 @@ module example.com/hello go 1.12 -require git.rootprojects.org/root/go-gitver v1.1.0 +require ( + git.rootprojects.org/root/go-gitver/v2 v2.0.1 +) diff --git a/examples/basic/main.go b/examples/basic/main.go index 4939762..8f494de 100644 --- a/examples/basic/main.go +++ b/examples/basic/main.go @@ -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 diff --git a/examples/basic/tools/tools.go b/examples/basic/tools/tools.go index d09a206..b9bc01c 100644 --- a/examples/basic/tools/tools.go +++ b/examples/basic/tools/tools.go @@ -4,5 +4,5 @@ package tools import ( - _ "git.rootprojects.org/root/go-gitver" + _ "git.rootprojects.org/root/go-gitver/v2" ) diff --git a/examples/no-tools/go.mod b/examples/no-tools/go.mod index 0996999..909a264 100644 --- a/examples/no-tools/go.mod +++ b/examples/no-tools/go.mod @@ -2,4 +2,6 @@ module example.com/hello go 1.12 -require git.rootprojects.org/root/go-gitver v1.1.0 +require ( + git.rootprojects.org/root/go-gitver/v2 v2.0.1 +) diff --git a/examples/no-tools/main.go b/examples/no-tools/main.go index 4939762..8f494de 100644 --- a/examples/no-tools/main.go +++ b/examples/no-tools/main.go @@ -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 diff --git a/examples/no-tools/tools.go b/examples/no-tools/tools.go index af07c0b..f21dd4f 100644 --- a/examples/no-tools/tools.go +++ b/examples/no-tools/tools.go @@ -3,4 +3,4 @@ // This is a dummy file for build tooling package main -import _ "git.rootprojects.org/root/go-gitver" +import _ "git.rootprojects.org/root/go-gitver/v2" diff --git a/examples/special-name/go.mod b/examples/special-name/go.mod index 0996999..909a264 100644 --- a/examples/special-name/go.mod +++ b/examples/special-name/go.mod @@ -2,4 +2,6 @@ module example.com/hello go 1.12 -require git.rootprojects.org/root/go-gitver v1.1.0 +require ( + git.rootprojects.org/root/go-gitver/v2 v2.0.1 +) diff --git a/examples/special-name/main.go b/examples/special-name/main.go index 314a51e..a954ce8 100644 --- a/examples/special-name/main.go +++ b/examples/special-name/main.go @@ -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 @@ -14,9 +14,9 @@ func main() { flag.Parse() if *showVersion { - fmt.Println(version.commit) - fmt.Println(version.version) - fmt.Println(version.date) + fmt.Println(version.Commit()) + fmt.Println(version.Version()) + fmt.Println(version.Date()) return } diff --git a/examples/special-name/tools/tools.go b/examples/special-name/tools/tools.go index d09a206..b9bc01c 100644 --- a/examples/special-name/tools/tools.go +++ b/examples/special-name/tools/tools.go @@ -4,5 +4,5 @@ package tools import ( - _ "git.rootprojects.org/root/go-gitver" + _ "git.rootprojects.org/root/go-gitver/v2" ) diff --git a/examples/special-name/version/version.go b/examples/special-name/version/version.go index c56f740..38e708f 100644 --- a/examples/special-name/version/version.go +++ b/examples/special-name/version/version.go @@ -5,3 +5,18 @@ var ( version = "0.0.0-pre0+0000000" 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 +} diff --git a/examples/sub-package/go.mod b/examples/sub-package/go.mod index 0996999..909a264 100644 --- a/examples/sub-package/go.mod +++ b/examples/sub-package/go.mod @@ -2,4 +2,6 @@ module example.com/hello go 1.12 -require git.rootprojects.org/root/go-gitver v1.1.0 +require ( + git.rootprojects.org/root/go-gitver/v2 v2.0.1 +) diff --git a/examples/sub-package/main.go b/examples/sub-package/main.go index ddab381..b36c231 100644 --- a/examples/sub-package/main.go +++ b/examples/sub-package/main.go @@ -12,9 +12,9 @@ func main() { flag.Parse() if *showVersion { - fmt.Println(version.commit) - fmt.Println(version.version) - fmt.Println(version.date) + fmt.Println(version.Commit()) + fmt.Println(version.Version()) + fmt.Println(version.Date()) return } diff --git a/examples/sub-package/tools/tools.go b/examples/sub-package/tools/tools.go index d09a206..b9bc01c 100644 --- a/examples/sub-package/tools/tools.go +++ b/examples/sub-package/tools/tools.go @@ -4,5 +4,5 @@ package tools import ( - _ "git.rootprojects.org/root/go-gitver" + _ "git.rootprojects.org/root/go-gitver/v2" ) diff --git a/examples/sub-package/version/version.go b/examples/sub-package/version/version.go index 923cf0b..0a1f511 100644 --- a/examples/sub-package/version/version.go +++ b/examples/sub-package/version/version.go @@ -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 @@ -7,3 +7,18 @@ var ( version = "0.0.0-pre0+0000000" 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 +} diff --git a/gitver.go b/gitver.go index 46018af..e4b86fd 100644 --- a/gitver.go +++ b/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,7 +10,7 @@ import ( "text/template" "time" - "git.rootprojects.org/root/go-gitver/gitver" + "git.rootprojects.org/root/go-gitver/v2/gitver" ) var commit, version, date string diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..dd58ff6 --- /dev/null +++ b/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=