-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
* Infer webrpc version if imported from another Go module Useful if you import webrpc into your Go project and invoke it via go run github.com/webrpc/webrpc/cmd/webrpc-gen. * Infer version from git as a fallback * make build: Inject version into the Go binary * Replace webrpc version in all generated files to avoid git conflicts * Update to actions/checkout@v4; Use 20 commit depth for git tags * Improve make generate diff
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,41 @@ | ||
package webrpc | ||
|
||
// VERSION defines version of webrpc tools, such as webrpc-gen. | ||
// | ||
// Please update major/minor version when making any incompatible changes | ||
// to the webrpc schema or webrpc-gen Template Functions API. | ||
// The patch value is automatically updated with the latest git tag in CI. | ||
import ( | ||
"os/exec" | ||
"strings" | ||
) | ||
|
||
// VERSION of webrpc tooling and webrpc-gen Template Functions API. | ||
// Available as {{.WebrpcGenVersion}} variable in Go templates. | ||
// | ||
// Version is available as {{.WebrpcGenVersion}} in generator templates. | ||
var VERSION = "v0.15.2-dev" | ||
// The value is injected during `go build' in the release CI step. | ||
var VERSION = "" | ||
|
||
func init() { | ||
if VERSION == "" { | ||
VERSION = getRuntimeVersion() | ||
} | ||
} | ||
|
||
// getRuntimeVersion tries to infer webrpc version | ||
// 1. from the current go.mod file, which is useful when running webrpc-gen from | ||
// another Go module using `go run github.com/webrpc/webrpc/cmd/webrpc-gen'. | ||
// 2. from the current git history. | ||
func getRuntimeVersion() string { | ||
// $ go list -m github.com/webrpc/webrpc | ||
// github.com/webrpc/webrpc v0.15.1\n | ||
if out, _ := exec.Command("go", "list", "-m", "github.com/webrpc/webrpc").Output(); len(out) > 0 { | ||
parts := strings.Split(strings.TrimSpace(string(out)), " ") | ||
if len(parts) >= 2 { | ||
return parts[1] | ||
} | ||
} | ||
|
||
// $ git describe | ||
// v0.15.1-6-g550333d\n | ||
if out, _ := exec.Command("git", "describe").Output(); len(out) > 0 { | ||
return strings.TrimSpace(string(out)) | ||
} | ||
|
||
return "unknown" | ||
} |