Skip to content

Commit 6aebb06

Browse files
authored
chore: Automate version file control and fix goreleaser (#304)
## Summary Turns `runtime/debug` package allows us to see `BuildInfo` which among other things has details about the main module's version. The version is set by `go install`, for prebuilt binaries with `go build` we're leaving the process intact. I haven't tested how `go install ...@latest` will behave, until we release an official new version we won't be able to check that. I also fixed `goreleaser` config which was ONCE AGAIN misbehaving due to the recent changes they introduced. It should now not change the release's metadata, so If you mark it as pre-release or official version, it will keep it this way.
1 parent 01f2bda commit 6aebb06

File tree

5 files changed

+18
-9
lines changed

5 files changed

+18
-9
lines changed

.goreleaser.yml

+3
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ checksum:
3030

3131
release:
3232
make_latest: false
33+
draft: true
34+
replace_existing_draft: false
35+
prerelease: auto
3336
github:
3437
owner: nobl9
3538
name: sloctl

Makefile

+4
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ build:
6464
docker:
6565
$(call _build_docker,sloctl,$(VERSION),$(BRANCH),$(REVISION))
6666

67+
.PHONY: test
68+
## Run all tests.
69+
test: test/unit test/e2e
70+
6771
.PHONY: test/unit test/go/unit test/bats/%
6872
## Run all unit tests.
6973
test/unit: test/go/unit test/bats/unit

cspell.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ ignorePaths:
2929
- dist/**
3030
words:
3131
- armv
32+
- devel
3233
- distroless
3334
- dynatrace
3435
- endef

internal/VERSION

-1
This file was deleted.

internal/version.go

+10-8
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package internal
22

33
import (
4-
_ "embed"
54
"fmt"
5+
"runtime/debug"
66
"strings"
77

88
"github.com/spf13/cobra"
@@ -21,12 +21,6 @@ func NewVersionCmd() *cobra.Command {
2121
}
2222
}
2323

24-
// BuildVersion defaults to VERSION file contents.
25-
// This is necessary since we don't have control over build flags when installed through `go install`.
26-
//
27-
//go:embed VERSION
28-
var embeddedBuildVersion string
29-
3024
// Set during build time.
3125
var (
3226
BuildGitRevision string
@@ -37,7 +31,15 @@ var (
3731
func getBuildVersion() string {
3832
version := BuildVersion
3933
if version == "" {
40-
version = embeddedBuildVersion
34+
version = getRuntimeVersion()
4135
}
4236
return strings.TrimSpace(version)
4337
}
38+
39+
func getRuntimeVersion() string {
40+
info, ok := debug.ReadBuildInfo()
41+
if !ok || info.Main.Version == "(devel)" {
42+
return "0.0.0"
43+
}
44+
return strings.TrimPrefix(info.Main.Version, "v")
45+
}

0 commit comments

Comments
 (0)