Skip to content

Commit

Permalink
Merge pull request #56 from 0pcom/buildinfo
Browse files Browse the repository at this point in the history
Update buildinfo to parse output of `go list` set on compile
  • Loading branch information
mrpalide authored Dec 21, 2024
2 parents 201fde7 + 35b48ef commit 159ccb5
Show file tree
Hide file tree
Showing 475 changed files with 54,874 additions and 17,006 deletions.
39 changes: 20 additions & 19 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,37 +1,38 @@
module github.com/skycoin/skywire-utilities

go 1.21
go 1.22.0

toolchain go1.23.4

require (
github.com/VictoriaMetrics/metrics v1.18.1
github.com/go-chi/chi/v5 v5.0.7
github.com/VictoriaMetrics/metrics v1.35.1
github.com/go-chi/chi/v5 v5.2.0
github.com/go-redis/redis/v8 v8.11.5
github.com/json-iterator/go v1.1.12
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d
github.com/pires/go-proxyproto v0.6.2
github.com/sirupsen/logrus v1.8.1
github.com/skycoin/skycoin v0.27.1
github.com/spf13/cobra v1.3.0
github.com/stretchr/testify v1.7.0
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211
github.com/pires/go-proxyproto v0.8.0
github.com/sirupsen/logrus v1.9.3
github.com/skycoin/skycoin v0.28.1-0.20241105130348-39b49a2d0a7f
github.com/spf13/cobra v1.8.1
github.com/stretchr/testify v1.9.0
golang.org/x/sys v0.28.0
golang.org/x/term v0.27.0
)

require (
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/kr/pretty v0.2.1 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/valyala/fastrand v1.1.0 // indirect
github.com/valyala/histogram v1.2.0 // indirect
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
814 changes: 47 additions & 767 deletions go.sum

Large diffs are not rendered by default.

38 changes: 33 additions & 5 deletions pkg/buildinfo/buildinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,52 @@
package buildinfo

import (
"encoding/json"
"fmt"
"io"
)

const unknown = "unknown"

//$ go build -mod=vendor -ldflags="-X 'github.com/skycoin/skywire-utilities/pkg/buildinfo.version=$(git describe)' -X 'github.com/skycoin/skywire-utilities/pkg/buildinfo.date=$(date -u "+%Y-%m-%dT%H:%M:%SZ")' -X 'github.com/skycoin/skywire-utilities/pkg/buildinfo.commit=$(git rev-list -1 HEAD)'" .

var (
version = unknown
commit = unknown
date = unknown
version = unknown
commit = unknown
date = unknown
)

// Version returns version from git describe.
//$ go build -ldflags="-X 'github.com/skycoin/skywire-utilities/pkg/buildinfo.golist=$(go list -m -json -mod=mod github.com/skycoin/<repo>@<branch>)' -X 'github.com/skycoin/skywire-utilities/pkg/buildinfo.date=$(date -u "+%Y-%m-%dT%H:%M:%SZ")'" .
var golist string

// ModuleInfo represents the JSON structure returned by `go list -m -json`.
type ModuleInfo struct {
Version string `json:"Version"`
Origin struct {
Hash string `json:"Hash"`
} `json:"Origin"`
}

func init() {
if golist != "" {
var mInfo ModuleInfo
if err := json.Unmarshal([]byte(golist), &mInfo); err == nil {
if mInfo.Version != "" && version == unknown {
version = mInfo.Version
}
if mInfo.Origin.Hash != "" && commit == unknown {
commit = mInfo.Origin.Hash
}
}
}
}

// Version returns version from the parsed module info.
func Version() string {
return version
}

// Commit returns commit hash.
// Commit returns commit hash from the parsed module info.
func Commit() string {
return commit
}
Expand Down
20 changes: 15 additions & 5 deletions vendor/github.com/VictoriaMetrics/metrics/README.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 15 additions & 6 deletions vendor/github.com/VictoriaMetrics/metrics/counter.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 10 additions & 6 deletions vendor/github.com/VictoriaMetrics/metrics/floatcounter.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

79 changes: 67 additions & 12 deletions vendor/github.com/VictoriaMetrics/metrics/gauge.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 159ccb5

Please sign in to comment.