Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(config): dynamically set version based on environment #3693

Merged
merged 6 commits into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,4 @@ endif
chmod a+x $(GOPATH)/bin/zombienet

zombienet-test: install install-zombienet
zombienet test -p native zombienet_tests/functional/0001-basic-network.zndsl
zombienet test -p native zombienet_tests/functional/0001-basic-network.zndsl
4 changes: 1 addition & 3 deletions cmd/gossamer/commands/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ package commands
import (
"fmt"

cfg "github.com/ChainSafe/gossamer/config"

"github.com/spf13/cobra"
)

Expand All @@ -17,7 +15,7 @@ var VersionCmd = &cobra.Command{
Short: "gossamer version",
Long: `gossamer version`,
RunE: func(cmd *cobra.Command, args []string) error {
fmt.Printf("%s version %s\n", cfg.DefaultSystemName, cfg.DefaultSystemVersion)
fmt.Printf("%s version %s\n", config.System.SystemName, config.System.SystemVersion)
return nil
},
}
6 changes: 3 additions & 3 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const (
// DefaultSystemName is the default system name
DefaultSystemName = "Gossamer"
// DefaultSystemVersion is the default system version
DefaultSystemVersion = "0.9.0"
DefaultSystemVersion = "0.0.0"
)

// DefaultRPCModules the default RPC modules
Expand Down Expand Up @@ -402,7 +402,7 @@ func DefaultConfig() *Config {
},
System: &SystemConfig{
SystemName: DefaultSystemName,
SystemVersion: DefaultSystemVersion,
SystemVersion: getFullVersion(),
},
}
}
Expand Down Expand Up @@ -483,7 +483,7 @@ func DefaultConfigFromSpec(nodeSpec *genesis.Genesis) *Config {
},
System: &SystemConfig{
SystemName: DefaultSystemName,
SystemVersion: DefaultSystemVersion,
SystemVersion: getFullVersion(),
},
}
}
Expand Down
52 changes: 52 additions & 0 deletions config/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Copyright 2024 ChainSafe Systems (ON)
// SPDX-License-Identifier: LGPL-3.0-only

package config

import (
"fmt"
"runtime/debug"
)

// Sets the numeric Gossamer version here
const (
VersionMajor = 0
VersionMinor = 9
VersionPatch = 0
VersionMeta = "unstable"
)

// Attempts to get a Git commit hash
var GitCommit = func() string {
if info, ok := debug.ReadBuildInfo(); ok {
for _, setting := range info.Settings {
if setting.Key == "vcs.revision" {
return setting.Value
}
}
}
return ""
}()

// Holds a text representation of the Gossamer version
var Version = func() string {
if VersionMeta != "stable" {
return getFullVersion()
} else {
return getStableVersion()
}
}()

// Gets a verbose, long version string, e.g., 0.9.0-unstable-e41617ba
func getFullVersion() string {
version := getStableVersion() + "-" + VersionMeta
if len(GitCommit) >= 8 {
version += "-" + GitCommit[:8]
}
return version
}

// Gets a short, stable version string, e.g., 0.9.0
func getStableVersion() string {
return fmt.Sprintf("%d.%d.%d", VersionMajor, VersionMinor, VersionPatch)
}
Loading