diff --git a/BUILD b/BUILD index c7fe7d1..76afd49 100644 --- a/BUILD +++ b/BUILD @@ -5,7 +5,10 @@ gazelle(name = "gazelle") go_library( name = "aws-in-a-box_lib", - srcs = ["main.go"], + srcs = [ + "main.go", + "version.go", + ], importpath = "aws-in-a-box", visibility = ["//visibility:private"], deps = [ @@ -18,6 +21,9 @@ go_library( "//services/s3", "//services/sqs", ], + x_defs = { + "aws-in-a-box.BazelSuffix": " (Bazel)" + }, ) go_binary( diff --git a/main.go b/main.go index 7c66aef..c304da6 100755 --- a/main.go +++ b/main.go @@ -19,24 +19,25 @@ import ( "aws-in-a-box/services/sqs" ) +var BazelSuffix = "" + func versionString() string { - buildinfo, ok := debug.ReadBuildInfo() - if !ok { - return "" - } - revision := "unknown" - dirty := false - for _, s := range buildinfo.Settings { - if s.Key == "vcs.modified" { - dirty = s.Value == "true" - } else if s.Key == "vcs.revision" { - revision = s.Value + version := Version + BazelSuffix + + // We only have ReadBuildInfo in non-bazel builds. + if version != Version { + buildinfo, ok := debug.ReadBuildInfo() + if ok { + for _, s := range buildinfo.Settings { + if s.Key == "vcs.modified" { + version += " (dirty)" + break + } + } } } - if dirty { - revision += "(dirty)" - } - return revision + + return version } func main() { @@ -84,14 +85,7 @@ func main() { textHandler := slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{ Level: level, }) - logger := slog.New(textHandler) - - version := versionString() - if version == "" { - logger.Warn("Could not read build info") - } else { - logger = logger.With("version", versionString()) - } + logger := slog.New(textHandler).With("version", versionString()) methodRegistry := make(http.Registry) diff --git a/release.sh b/release.sh index bf9b132..db86068 100755 --- a/release.sh +++ b/release.sh @@ -1,2 +1,5 @@ +echo "package main\n\nconst Version = \"$VERSION\"" > version.go +git add . +git commit -m "Update version file to $VERSION" git tag -a $VERSION -m "$VERSION" -git push origin $VERSION +git push origin master $VERSION diff --git a/version.go b/version.go new file mode 100644 index 0000000..e971e4b --- /dev/null +++ b/version.go @@ -0,0 +1,3 @@ +package main + +const Version = "v0.0"