Skip to content

Commit

Permalink
Merge pull request #134 from oasisprotocol/tjanez/show-oasis-core-ver…
Browse files Browse the repository at this point in the history
…sion

Get Oasis Core's version from Oasis Core Go module dependency
  • Loading branch information
tjanez authored Dec 9, 2020
2 parents c2dfc31 + d5867ce commit 9215a15
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions .changelog/134.feature.1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
common: Add `GetOasisCoreVersion()` helper for obtaining Oasis Core's version
1 change: 1 addition & 0 deletions .changelog/134.feature.2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cli: Add `-version` flag to `oasis-core-rosetta-gateway` binary
24 changes: 24 additions & 0 deletions common/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,15 @@ package common

import (
"runtime"
"runtime/debug"
"strings"

ocVersion "github.com/oasisprotocol/oasis-core/go/common/version"
)

// VersionUnknown represents an unknown version.
const VersionUnknown = "unknown"

var (
// SoftwareVersion represents the Oasis Core Rosetta Gateway's version and
// should be set by the linker.
Expand All @@ -18,3 +24,21 @@ var (
// ToolchainVersion is the version of the Go compiler/standard library.
ToolchainVersion = strings.TrimPrefix(runtime.Version(), "go")
)

// GetOasisCoreVersion returns the version of the Oasis Core dependency or
// unknown if it can't be obtained.
func GetOasisCoreVersion() string {
bi, ok := debug.ReadBuildInfo()
if !ok {
return VersionUnknown
}

for _, dep := range bi.Deps {
if dep.Path == "github.com/oasisprotocol/oasis-core/go" {
// Convert Go Modules compatible version to Oasis Core's canonical
// version.
return ocVersion.ConvertGoModulesVersion(dep.Version)
}
}
return VersionUnknown
}
2 changes: 2 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ func getPortOrExit() int {
// Print version information.
func printVersionInfo() {
fmt.Printf("Software version: %s\n", common.SoftwareVersion)
fmt.Printf("Oasis Core:\n")
fmt.Printf(" Software version: %s\n", common.GetOasisCoreVersion())
fmt.Printf("Rosetta API version: %s\n", common.RosettaAPIVersion)
fmt.Printf("Go toolchain version: %s\n", common.ToolchainVersion)
}
Expand Down

0 comments on commit 9215a15

Please sign in to comment.