module: bump minimum Go version to 1.18 and use debug.ReadBuildInfo()

This commit is contained in:
cn 2022-03-18 00:21:53 +01:00
parent 0268126d70
commit 72c4c94cb7
4 changed files with 20 additions and 11 deletions

View File

@ -11,7 +11,7 @@ jobs:
strategy: strategy:
matrix: matrix:
go: go:
- '1.17' - '1.18'
env: env:
GO111MODULE: on GO111MODULE: on
GOPROXY: direct GOPROXY: direct

View File

@ -53,8 +53,8 @@ remote-run: clean ## Run clean, build $RUN_COMMAND for Linux on ARM and launch i
release: ## Build and upload release version of miflorad to Github release: ## Build and upload release version of miflorad to Github
mkdir -p pkg mkdir -p pkg
pushd cmd/miflorad pushd cmd/miflorad
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o "../../pkg/miflorad-$(MIFLORAD_VERSION)-linux-amd64" -ldflags="-s -w -X main.version=$(MIFLORAD_VERSION)" CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o "../../pkg/miflorad-$(MIFLORAD_VERSION)-linux-amd64" -ldflags="-s -w"
CGO_ENABLED=0 GOOS=linux GOARCH=arm go build -o "../../pkg/miflorad-$(MIFLORAD_VERSION)-linux-arm" -ldflags="-s -w -X main.version=$(MIFLORAD_VERSION)" CGO_ENABLED=0 GOOS=linux GOARCH=arm go build -o "../../pkg/miflorad-$(MIFLORAD_VERSION)-linux-arm" -ldflags="-s -w"
popd popd
# github-release "v$(MIFLORAD_VERSION)" pkg/miflorad-$(MIFLORAD_VERSION)-* --commit "master" --tag "v$(MIFLORAD_VERSION)" --prerelease --github-repository "cmur2/miflorad" # github-release "v$(MIFLORAD_VERSION)" pkg/miflorad-$(MIFLORAD_VERSION)-* --commit "master" --tag "v$(MIFLORAD_VERSION)" --prerelease --github-repository "cmur2/miflorad"
github-release "v$(MIFLORAD_VERSION)" pkg/miflorad-$(MIFLORAD_VERSION)-* --commit "master" --tag "v$(MIFLORAD_VERSION)" --github-repository "cmur2/miflorad" github-release "v$(MIFLORAD_VERSION)" pkg/miflorad-$(MIFLORAD_VERSION)-* --commit "master" --tag "v$(MIFLORAD_VERSION)" --github-repository "cmur2/miflorad"
@ -62,7 +62,7 @@ release: ## Build and upload release version of miflorad to Github
.PHONY: cmd/miflorad/miflorad .PHONY: cmd/miflorad/miflorad
cmd/miflorad/miflorad: cmd/miflorad/miflorad:
pushd cmd/miflorad pushd cmd/miflorad
CGO_ENABLED=0 go build -buildmode=pie -ldflags "-X main.version=$(MIFLORAD_VERSION)" CGO_ENABLED=0 go build -buildmode=pie
.PHONY: cmd/munin-miflora/munin-miflora .PHONY: cmd/munin-miflora/munin-miflora
cmd/munin-miflora/munin-miflora: cmd/munin-miflora/munin-miflora:

View File

@ -1,12 +1,21 @@
package main package main
// program version, will be populated on build import (
var version string "runtime/debug"
)
func getVersion() string { func getVersion() string {
if version == "" { info, ok := debug.ReadBuildInfo()
return "dev" if !ok {
} else { return "unknown"
return version
} }
for _, kv := range info.Settings {
switch kv.Key {
case "vcs.revision":
return kv.Value[0:8]
}
}
return "unknown"
} }

2
go.mod
View File

@ -1,6 +1,6 @@
module miflorad module miflorad
go 1.17 go 1.18
require ( require (
github.com/currantlabs/gatt v0.0.0-20161006170101-f949eac78f4e github.com/currantlabs/gatt v0.0.0-20161006170101-f949eac78f4e