mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-17 18:30:45 +00:00
parent
a75a1467ab
commit
6d7c36bb8f
16 changed files with 271 additions and 91 deletions
|
|
@ -179,7 +179,8 @@ func doInstall(cmdline []string) {
|
||||||
func buildFlags(env build.Environment) (flags []string) {
|
func buildFlags(env build.Environment) (flags []string) {
|
||||||
var ld []string
|
var ld []string
|
||||||
if env.Commit != "" {
|
if env.Commit != "" {
|
||||||
ld = append(ld, "-X", "main.gitCommit="+env.Commit)
|
ld = append(ld, "-X", "github.com/XinFinOrg/XDPoSChain/internal/version.gitCommit="+env.Commit)
|
||||||
|
ld = append(ld, "-X", "github.com/XinFinOrg/XDPoSChain/internal/version.gitDate="+env.Date)
|
||||||
}
|
}
|
||||||
if runtime.GOOS == "darwin" {
|
if runtime.GOOS == "darwin" {
|
||||||
ld = append(ld, "-s")
|
ld = append(ld, "-s")
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/XinFinOrg/XDPoSChain/cmd/internal/browser"
|
"github.com/XinFinOrg/XDPoSChain/cmd/internal/browser"
|
||||||
"github.com/XinFinOrg/XDPoSChain/params"
|
"github.com/XinFinOrg/XDPoSChain/internal/version"
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -47,7 +47,7 @@ func reportBug(ctx *cli.Context) error {
|
||||||
var buff bytes.Buffer
|
var buff bytes.Buffer
|
||||||
|
|
||||||
fmt.Fprintln(&buff, header)
|
fmt.Fprintln(&buff, header)
|
||||||
fmt.Fprintln(&buff, "Version:", params.Version)
|
fmt.Fprintln(&buff, "Version:", version.WithMeta)
|
||||||
fmt.Fprintln(&buff, "Go Version:", runtime.Version())
|
fmt.Fprintln(&buff, "Go Version:", runtime.Version())
|
||||||
fmt.Fprintln(&buff, "OS:", runtime.GOOS)
|
fmt.Fprintln(&buff, "OS:", runtime.GOOS)
|
||||||
printOSDetails(&buff)
|
printOSDetails(&buff)
|
||||||
|
|
@ -97,9 +97,9 @@ func printCmdOut(w io.Writer, prefix, path string, args ...string) {
|
||||||
const header = `Please answer these questions before submitting your issue. Thanks!
|
const header = `Please answer these questions before submitting your issue. Thanks!
|
||||||
|
|
||||||
#### What did you do?
|
#### What did you do?
|
||||||
|
|
||||||
#### What did you expect to see?
|
#### What did you expect to see?
|
||||||
|
|
||||||
#### What did you see instead?
|
#### What did you see instead?
|
||||||
|
|
||||||
#### System details`
|
#### System details`
|
||||||
|
|
|
||||||
|
|
@ -39,10 +39,10 @@ import (
|
||||||
"github.com/XinFinOrg/XDPoSChain/eth/ethconfig"
|
"github.com/XinFinOrg/XDPoSChain/eth/ethconfig"
|
||||||
"github.com/XinFinOrg/XDPoSChain/internal/ethapi"
|
"github.com/XinFinOrg/XDPoSChain/internal/ethapi"
|
||||||
"github.com/XinFinOrg/XDPoSChain/internal/flags"
|
"github.com/XinFinOrg/XDPoSChain/internal/flags"
|
||||||
|
"github.com/XinFinOrg/XDPoSChain/internal/version"
|
||||||
"github.com/XinFinOrg/XDPoSChain/log"
|
"github.com/XinFinOrg/XDPoSChain/log"
|
||||||
"github.com/XinFinOrg/XDPoSChain/metrics"
|
"github.com/XinFinOrg/XDPoSChain/metrics"
|
||||||
"github.com/XinFinOrg/XDPoSChain/node"
|
"github.com/XinFinOrg/XDPoSChain/node"
|
||||||
"github.com/XinFinOrg/XDPoSChain/params"
|
|
||||||
"github.com/naoina/toml"
|
"github.com/naoina/toml"
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
)
|
)
|
||||||
|
|
@ -122,9 +122,10 @@ func loadConfig(file string, cfg *XDCConfig) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func defaultNodeConfig() node.Config {
|
func defaultNodeConfig() node.Config {
|
||||||
|
git, _ := version.VCS()
|
||||||
cfg := node.DefaultConfig
|
cfg := node.DefaultConfig
|
||||||
cfg.Name = clientIdentifier
|
cfg.Name = clientIdentifier
|
||||||
cfg.Version = params.VersionWithCommit(gitCommit)
|
cfg.Version = version.WithCommit(git.Commit, git.Date)
|
||||||
cfg.HTTPModules = append(cfg.HTTPModules, "eth")
|
cfg.HTTPModules = append(cfg.HTTPModules, "eth")
|
||||||
cfg.WSModules = append(cfg.WSModules, "eth")
|
cfg.WSModules = append(cfg.WSModules, "eth")
|
||||||
cfg.IPCPath = "XDC.ipc"
|
cfg.IPCPath = "XDC.ipc"
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/XinFinOrg/XDPoSChain/params"
|
"github.com/XinFinOrg/XDPoSChain/internal/version"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|
@ -50,7 +50,10 @@ func TestConsoleWelcome(t *testing.T) {
|
||||||
XDC.SetTemplateFunc("goos", func() string { return runtime.GOOS })
|
XDC.SetTemplateFunc("goos", func() string { return runtime.GOOS })
|
||||||
XDC.SetTemplateFunc("goarch", func() string { return runtime.GOARCH })
|
XDC.SetTemplateFunc("goarch", func() string { return runtime.GOARCH })
|
||||||
XDC.SetTemplateFunc("gover", runtime.Version)
|
XDC.SetTemplateFunc("gover", runtime.Version)
|
||||||
XDC.SetTemplateFunc("XDCver", func() string { return params.Version })
|
XDC.SetTemplateFunc("XDCver", func() string {
|
||||||
|
git, _ := version.VCS()
|
||||||
|
return version.WithCommit(git.Commit, git.Date)
|
||||||
|
})
|
||||||
XDC.SetTemplateFunc("niltime", func() string {
|
XDC.SetTemplateFunc("niltime", func() string {
|
||||||
return time.Unix(1559211559, 0).Format("Mon Jan 02 2006 15:04:05 GMT-0700 (MST)")
|
return time.Unix(1559211559, 0).Format("Mon Jan 02 2006 15:04:05 GMT-0700 (MST)")
|
||||||
})
|
})
|
||||||
|
|
@ -137,7 +140,10 @@ func testAttachWelcome(t *testing.T, XDC *testXDC, endpoint, apis string) {
|
||||||
attach.SetTemplateFunc("goos", func() string { return runtime.GOOS })
|
attach.SetTemplateFunc("goos", func() string { return runtime.GOOS })
|
||||||
attach.SetTemplateFunc("goarch", func() string { return runtime.GOARCH })
|
attach.SetTemplateFunc("goarch", func() string { return runtime.GOARCH })
|
||||||
attach.SetTemplateFunc("gover", runtime.Version)
|
attach.SetTemplateFunc("gover", runtime.Version)
|
||||||
attach.SetTemplateFunc("XDCver", func() string { return params.Version })
|
attach.SetTemplateFunc("XDCver", func() string {
|
||||||
|
git, _ := version.VCS()
|
||||||
|
return version.WithCommit(git.Commit, git.Date)
|
||||||
|
})
|
||||||
attach.SetTemplateFunc("etherbase", func() string { return XDC.Etherbase })
|
attach.SetTemplateFunc("etherbase", func() string { return XDC.Etherbase })
|
||||||
attach.SetTemplateFunc("niltime", func() string {
|
attach.SetTemplateFunc("niltime", func() string {
|
||||||
return time.Unix(1559211559, 0).Format("Mon Jan 02 2006 15:04:05 GMT-0700 (MST)")
|
return time.Unix(1559211559, 0).Format("Mon Jan 02 2006 15:04:05 GMT-0700 (MST)")
|
||||||
|
|
|
||||||
|
|
@ -53,10 +53,8 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
// Git SHA1 commit hash of the release (set via linker flags)
|
|
||||||
gitCommit = ""
|
|
||||||
// The app that holds all commands and flags.
|
// The app that holds all commands and flags.
|
||||||
app = flags.NewApp(gitCommit, "the XDPoSChain command line interface")
|
app = flags.NewApp("the XDPoSChain command line interface")
|
||||||
|
|
||||||
// The app that holds all commands and flags.
|
// The app that holds all commands and flags.
|
||||||
nodeFlags = slices.Concat([]cli.Flag{
|
nodeFlags = slices.Concat([]cli.Flag{
|
||||||
|
|
@ -194,7 +192,7 @@ var (
|
||||||
func init() {
|
func init() {
|
||||||
// Initialize the CLI app and start XDC
|
// Initialize the CLI app and start XDC
|
||||||
app.Action = XDC
|
app.Action = XDC
|
||||||
app.Copyright = "Copyright (c) 2024 XDPoSChain"
|
app.Copyright = "Copyright (c) 2025 XDPoSChain"
|
||||||
app.Commands = []*cli.Command{
|
app.Commands = []*cli.Command{
|
||||||
// See chaincmd.go:
|
// See chaincmd.go:
|
||||||
initCommand,
|
initCommand,
|
||||||
|
|
|
||||||
|
|
@ -24,13 +24,13 @@ import (
|
||||||
|
|
||||||
"github.com/XinFinOrg/XDPoSChain/eth"
|
"github.com/XinFinOrg/XDPoSChain/eth"
|
||||||
"github.com/XinFinOrg/XDPoSChain/eth/ethconfig"
|
"github.com/XinFinOrg/XDPoSChain/eth/ethconfig"
|
||||||
"github.com/XinFinOrg/XDPoSChain/params"
|
"github.com/XinFinOrg/XDPoSChain/internal/version"
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
versionCommand = &cli.Command{
|
versionCommand = &cli.Command{
|
||||||
Action: version,
|
Action: printVersion,
|
||||||
Name: "version",
|
Name: "version",
|
||||||
Usage: "Print version numbers",
|
Usage: "Print version numbers",
|
||||||
ArgsUsage: " ",
|
ArgsUsage: " ",
|
||||||
|
|
@ -46,11 +46,16 @@ The output of this command is supposed to be machine-readable.
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
func version(ctx *cli.Context) error {
|
func printVersion(ctx *cli.Context) error {
|
||||||
|
git, _ := version.VCS()
|
||||||
|
|
||||||
fmt.Println(strings.Title(clientIdentifier))
|
fmt.Println(strings.Title(clientIdentifier))
|
||||||
fmt.Println("Version:", params.Version)
|
fmt.Println("Version:", version.WithMeta)
|
||||||
if gitCommit != "" {
|
if git.Commit != "" {
|
||||||
fmt.Println("Git Commit:", gitCommit)
|
fmt.Println("Git Commit:", git.Commit)
|
||||||
|
}
|
||||||
|
if git.Date != "" {
|
||||||
|
fmt.Println("Git Commit Date:", git.Date)
|
||||||
}
|
}
|
||||||
fmt.Println("Architecture:", runtime.GOARCH)
|
fmt.Println("Architecture:", runtime.GOARCH)
|
||||||
fmt.Println("Protocol Versions:", eth.ProtocolVersions)
|
fmt.Println("Protocol Versions:", eth.ProtocolVersions)
|
||||||
|
|
|
||||||
|
|
@ -73,7 +73,7 @@ var (
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
var app = flags.NewApp("", "XDC ABI wrapper code generator")
|
var app = flags.NewApp("XDC ABI wrapper code generator")
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
app.Name = "abigen"
|
app.Name = "abigen"
|
||||||
|
|
|
||||||
|
|
@ -28,13 +28,10 @@ const (
|
||||||
defaultKeyfileName = "keyfile.json"
|
defaultKeyfileName = "keyfile.json"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Git SHA1 commit hash of the release (set via linker flags)
|
|
||||||
var gitCommit = ""
|
|
||||||
|
|
||||||
var app *cli.App
|
var app *cli.App
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
app = flags.NewApp(gitCommit, "an Ethereum key manager")
|
app = flags.NewApp("an Ethereum key manager")
|
||||||
app.Commands = []*cli.Command{
|
app.Commands = []*cli.Command{
|
||||||
commandGenerate,
|
commandGenerate,
|
||||||
commandInspect,
|
commandInspect,
|
||||||
|
|
@ -53,10 +50,6 @@ var (
|
||||||
Name: "json",
|
Name: "json",
|
||||||
Usage: "output JSON instead of human-readable format",
|
Usage: "output JSON instead of human-readable format",
|
||||||
}
|
}
|
||||||
messageFlag = &cli.StringFlag{
|
|
||||||
Name: "message",
|
|
||||||
Usage: "the file that contains the message to sign/verify",
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
|
||||||
|
|
@ -27,9 +27,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
gitCommit = "" // Git SHA1 commit hash of the release (set via linker flags)
|
app = flags.NewApp("the evm command line interface")
|
||||||
|
|
||||||
app = flags.NewApp(gitCommit, "the evm command line interface")
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
|
||||||
|
|
@ -100,13 +100,8 @@ var (
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
|
||||||
// Git information set by linker when building with ci.go.
|
|
||||||
gitCommit string
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
app := flags.NewApp(gitCommit, "devp2p simulation command-line client")
|
app := flags.NewApp("devp2p simulation command-line client")
|
||||||
app.Usage = "devp2p simulation command-line client"
|
app.Usage = "devp2p simulation command-line client"
|
||||||
app.Flags = []cli.Flag{
|
app.Flags = []cli.Flag{
|
||||||
apiFlag,
|
apiFlag,
|
||||||
|
|
|
||||||
|
|
@ -52,6 +52,7 @@ import (
|
||||||
"github.com/XinFinOrg/XDPoSChain/ethdb"
|
"github.com/XinFinOrg/XDPoSChain/ethdb"
|
||||||
"github.com/XinFinOrg/XDPoSChain/event"
|
"github.com/XinFinOrg/XDPoSChain/event"
|
||||||
"github.com/XinFinOrg/XDPoSChain/internal/ethapi"
|
"github.com/XinFinOrg/XDPoSChain/internal/ethapi"
|
||||||
|
"github.com/XinFinOrg/XDPoSChain/internal/version"
|
||||||
"github.com/XinFinOrg/XDPoSChain/log"
|
"github.com/XinFinOrg/XDPoSChain/log"
|
||||||
"github.com/XinFinOrg/XDPoSChain/miner"
|
"github.com/XinFinOrg/XDPoSChain/miner"
|
||||||
"github.com/XinFinOrg/XDPoSChain/node"
|
"github.com/XinFinOrg/XDPoSChain/node"
|
||||||
|
|
@ -59,6 +60,7 @@ import (
|
||||||
"github.com/XinFinOrg/XDPoSChain/params"
|
"github.com/XinFinOrg/XDPoSChain/params"
|
||||||
"github.com/XinFinOrg/XDPoSChain/rlp"
|
"github.com/XinFinOrg/XDPoSChain/rlp"
|
||||||
"github.com/XinFinOrg/XDPoSChain/rpc"
|
"github.com/XinFinOrg/XDPoSChain/rpc"
|
||||||
|
ver "github.com/XinFinOrg/XDPoSChain/version"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Ethereum implements the Ethereum full node service.
|
// Ethereum implements the Ethereum full node service.
|
||||||
|
|
@ -166,7 +168,7 @@ func New(stack *node.Node, config *ethconfig.Config, XDCXServ *XDCx.XDCX, lendin
|
||||||
|
|
||||||
if !config.SkipBcVersionCheck {
|
if !config.SkipBcVersionCheck {
|
||||||
if bcVersion != nil && *bcVersion > core.BlockChainVersion {
|
if bcVersion != nil && *bcVersion > core.BlockChainVersion {
|
||||||
return nil, fmt.Errorf("database version is v%d, not supports v%d", *bcVersion, core.BlockChainVersion)
|
return nil, fmt.Errorf("database version is v%d, XDC %s only supports v%d", *bcVersion, version.WithMeta, core.BlockChainVersion)
|
||||||
} else if bcVersion == nil || *bcVersion < core.BlockChainVersion {
|
} else if bcVersion == nil || *bcVersion < core.BlockChainVersion {
|
||||||
if bcVersion != nil { // only print warning on upgrade, not on init
|
if bcVersion != nil { // only print warning on upgrade, not on init
|
||||||
log.Warn("Upgrade blockchain database version", "from", dbVer, "to", core.BlockChainVersion)
|
log.Warn("Upgrade blockchain database version", "from", dbVer, "to", core.BlockChainVersion)
|
||||||
|
|
@ -358,7 +360,7 @@ func makeExtraData(extra []byte) []byte {
|
||||||
if len(extra) == 0 {
|
if len(extra) == 0 {
|
||||||
// create default extradata
|
// create default extradata
|
||||||
extra, _ = rlp.EncodeToBytes([]interface{}{
|
extra, _ = rlp.EncodeToBytes([]interface{}{
|
||||||
uint(params.VersionMajor<<16 | params.VersionMinor<<8 | params.VersionPatch),
|
uint(ver.Major<<16 | ver.Minor<<8 | ver.Patch),
|
||||||
"XDC",
|
"XDC",
|
||||||
runtime.Version(),
|
runtime.Version(),
|
||||||
runtime.GOOS,
|
runtime.GOOS,
|
||||||
|
|
|
||||||
|
|
@ -20,32 +20,38 @@ import (
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"regexp"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
// These flags override values in build env.
|
// These flags override values in build env.
|
||||||
GitCommitFlag = flag.String("git-commit", "", `Overrides git commit hash embedded into executables`)
|
GitCommitFlag = flag.String("git-commit", "", `Overrides git commit hash embedded into executables`)
|
||||||
GitBranchFlag = flag.String("git-branch", "", `Overrides git branch being built`)
|
GitBranchFlag = flag.String("git-branch", "", `Overrides git branch being built`)
|
||||||
GitTagFlag = flag.String("git-tag", "", `Overrides git tag being built`)
|
GitTagFlag = flag.String("git-tag", "", `Overrides git tag being built`)
|
||||||
BuildnumFlag = flag.String("buildnum", "", `Overrides CI build number`)
|
BuildnumFlag = flag.String("buildnum", "", `Overrides CI build number`)
|
||||||
PullRequestFlag = flag.Bool("pull-request", false, `Overrides pull request status of the build`)
|
PullRequestFlag = flag.Bool("pull-request", false, `Overrides pull request status of the build`)
|
||||||
CronJobFlag = flag.Bool("cron-job", false, `Overrides cron job status of the build`)
|
CronJobFlag = flag.Bool("cron-job", false, `Overrides cron job status of the build`)
|
||||||
|
UbuntuVersionFlag = flag.String("ubuntu", "", `Sets the ubuntu version being built for`)
|
||||||
)
|
)
|
||||||
|
|
||||||
// Environment contains metadata provided by the build environment.
|
// Environment contains metadata provided by the build environment.
|
||||||
type Environment struct {
|
type Environment struct {
|
||||||
Name string // name of the environment
|
CI bool
|
||||||
Repo string // name of GitHub repo
|
Name string // name of the environment
|
||||||
Commit, Branch, Tag string // Git info
|
Repo string // name of GitHub repo
|
||||||
Buildnum string
|
Commit, Date, Branch, Tag string // Git info
|
||||||
IsPullRequest bool
|
Buildnum string
|
||||||
IsCronJob bool
|
UbuntuVersion string // Ubuntu version being built for
|
||||||
|
IsPullRequest bool
|
||||||
|
IsCronJob bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (env Environment) String() string {
|
func (env Environment) String() string {
|
||||||
return fmt.Sprintf("%s env (commit:%s branch:%s tag:%s buildnum:%s pr:%t)",
|
return fmt.Sprintf("%s env (commit:%s date:%s branch:%s tag:%s buildnum:%s pr:%t)",
|
||||||
env.Name, env.Commit, env.Branch, env.Tag, env.Buildnum, env.IsPullRequest)
|
env.Name, env.Commit, env.Date, env.Branch, env.Tag, env.Buildnum, env.IsPullRequest)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Env returns metadata about the current CI environment, falling back to LocalEnv
|
// Env returns metadata about the current CI environment, falling back to LocalEnv
|
||||||
|
|
@ -53,10 +59,16 @@ func (env Environment) String() string {
|
||||||
func Env() Environment {
|
func Env() Environment {
|
||||||
switch {
|
switch {
|
||||||
case os.Getenv("CI") == "true" && os.Getenv("TRAVIS") == "true":
|
case os.Getenv("CI") == "true" && os.Getenv("TRAVIS") == "true":
|
||||||
|
commit := os.Getenv("TRAVIS_PULL_REQUEST_SHA")
|
||||||
|
if commit == "" {
|
||||||
|
commit = os.Getenv("TRAVIS_COMMIT")
|
||||||
|
}
|
||||||
return Environment{
|
return Environment{
|
||||||
|
CI: true,
|
||||||
Name: "travis",
|
Name: "travis",
|
||||||
Repo: os.Getenv("TRAVIS_REPO_SLUG"),
|
Repo: os.Getenv("TRAVIS_REPO_SLUG"),
|
||||||
Commit: os.Getenv("TRAVIS_COMMIT"),
|
Commit: commit,
|
||||||
|
Date: getDate(commit),
|
||||||
Branch: os.Getenv("TRAVIS_BRANCH"),
|
Branch: os.Getenv("TRAVIS_BRANCH"),
|
||||||
Tag: os.Getenv("TRAVIS_TAG"),
|
Tag: os.Getenv("TRAVIS_TAG"),
|
||||||
Buildnum: os.Getenv("TRAVIS_BUILD_NUMBER"),
|
Buildnum: os.Getenv("TRAVIS_BUILD_NUMBER"),
|
||||||
|
|
@ -64,16 +76,49 @@ func Env() Environment {
|
||||||
IsCronJob: os.Getenv("TRAVIS_EVENT_TYPE") == "cron",
|
IsCronJob: os.Getenv("TRAVIS_EVENT_TYPE") == "cron",
|
||||||
}
|
}
|
||||||
case os.Getenv("CI") == "True" && os.Getenv("APPVEYOR") == "True":
|
case os.Getenv("CI") == "True" && os.Getenv("APPVEYOR") == "True":
|
||||||
|
commit := os.Getenv("APPVEYOR_PULL_REQUEST_HEAD_COMMIT")
|
||||||
|
if commit == "" {
|
||||||
|
commit = os.Getenv("APPVEYOR_REPO_COMMIT")
|
||||||
|
}
|
||||||
return Environment{
|
return Environment{
|
||||||
|
CI: true,
|
||||||
Name: "appveyor",
|
Name: "appveyor",
|
||||||
Repo: os.Getenv("APPVEYOR_REPO_NAME"),
|
Repo: os.Getenv("APPVEYOR_REPO_NAME"),
|
||||||
Commit: os.Getenv("APPVEYOR_REPO_COMMIT"),
|
Commit: commit,
|
||||||
|
Date: getDate(commit),
|
||||||
Branch: os.Getenv("APPVEYOR_REPO_BRANCH"),
|
Branch: os.Getenv("APPVEYOR_REPO_BRANCH"),
|
||||||
Tag: os.Getenv("APPVEYOR_REPO_TAG_NAME"),
|
Tag: os.Getenv("APPVEYOR_REPO_TAG_NAME"),
|
||||||
Buildnum: os.Getenv("APPVEYOR_BUILD_NUMBER"),
|
Buildnum: os.Getenv("APPVEYOR_BUILD_NUMBER"),
|
||||||
IsPullRequest: os.Getenv("APPVEYOR_PULL_REQUEST_NUMBER") != "",
|
IsPullRequest: os.Getenv("APPVEYOR_PULL_REQUEST_NUMBER") != "",
|
||||||
IsCronJob: os.Getenv("APPVEYOR_SCHEDULED_BUILD") == "True",
|
IsCronJob: os.Getenv("APPVEYOR_SCHEDULED_BUILD") == "True",
|
||||||
}
|
}
|
||||||
|
case os.Getenv("CI") == "true" && os.Getenv("GITHUB_ACTIONS") == "true":
|
||||||
|
commit := os.Getenv("GITHUB_SHA")
|
||||||
|
reftype := os.Getenv("GITHUB_REF_TYPE")
|
||||||
|
isPR := os.Getenv("GITHUB_HEAD_REF") != ""
|
||||||
|
tag := ""
|
||||||
|
branch := ""
|
||||||
|
switch {
|
||||||
|
case isPR:
|
||||||
|
branch = os.Getenv("GITHUB_BASE_REF")
|
||||||
|
case reftype == "branch":
|
||||||
|
branch = os.Getenv("GITHUB_REF_NAME")
|
||||||
|
case reftype == "tag":
|
||||||
|
tag = os.Getenv("GITHUB_REF_NAME")
|
||||||
|
}
|
||||||
|
return Environment{
|
||||||
|
CI: true,
|
||||||
|
Name: "github-actions",
|
||||||
|
Repo: os.Getenv("GITHUB_REPOSITORY"),
|
||||||
|
Commit: commit,
|
||||||
|
Date: getDate(commit),
|
||||||
|
Branch: branch,
|
||||||
|
Tag: tag,
|
||||||
|
IsPullRequest: isPR,
|
||||||
|
Buildnum: os.Getenv("GITHUB_RUN_ID"),
|
||||||
|
IsCronJob: os.Getenv("GITHUB_EVENT_NAME") == "schedule",
|
||||||
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return LocalEnv()
|
return LocalEnv()
|
||||||
}
|
}
|
||||||
|
|
@ -84,14 +129,23 @@ func LocalEnv() Environment {
|
||||||
env := applyEnvFlags(Environment{Name: "local", Repo: "XDPoSChain/XDPoSChain"})
|
env := applyEnvFlags(Environment{Name: "local", Repo: "XDPoSChain/XDPoSChain"})
|
||||||
|
|
||||||
head := readGitFile("HEAD")
|
head := readGitFile("HEAD")
|
||||||
if splits := strings.Split(head, " "); len(splits) == 2 {
|
if fields := strings.Fields(head); len(fields) == 2 {
|
||||||
head = splits[1]
|
head = fields[1]
|
||||||
} else {
|
} else {
|
||||||
|
// In this case we are in "detached head" state
|
||||||
|
// see: https://git-scm.com/docs/git-checkout#_detached_head
|
||||||
|
// Additional check required to verify, that file contains commit hash
|
||||||
|
commitRe, _ := regexp.Compile("^([0-9a-f]{40})$")
|
||||||
|
if commit := commitRe.FindString(head); commit != "" && env.Commit == "" {
|
||||||
|
env.Commit = commit
|
||||||
|
env.Date = getDate(env.Commit)
|
||||||
|
}
|
||||||
return env
|
return env
|
||||||
}
|
}
|
||||||
if env.Commit == "" {
|
if env.Commit == "" {
|
||||||
env.Commit = readGitFile(head)
|
env.Commit = readGitFile(head)
|
||||||
}
|
}
|
||||||
|
env.Date = getDate(env.Commit)
|
||||||
if env.Branch == "" {
|
if env.Branch == "" {
|
||||||
if head != "HEAD" {
|
if head != "HEAD" {
|
||||||
env.Branch = strings.TrimPrefix(head, "refs/heads/")
|
env.Branch = strings.TrimPrefix(head, "refs/heads/")
|
||||||
|
|
@ -107,6 +161,21 @@ func firstLine(s string) string {
|
||||||
return strings.Split(s, "\n")[0]
|
return strings.Split(s, "\n")[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getDate(commit string) string {
|
||||||
|
if commit == "" {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
out := RunGit("show", "-s", "--format=%ct", commit)
|
||||||
|
if out == "" {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
date, err := strconv.ParseInt(strings.TrimSpace(out), 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
panic(fmt.Sprintf("failed to parse git commit date: %v", err))
|
||||||
|
}
|
||||||
|
return time.Unix(date, 0).Format("20060102")
|
||||||
|
}
|
||||||
|
|
||||||
func applyEnvFlags(env Environment) Environment {
|
func applyEnvFlags(env Environment) Environment {
|
||||||
if !flag.Parsed() {
|
if !flag.Parsed() {
|
||||||
panic("you need to call flag.Parse before Env or LocalEnv")
|
panic("you need to call flag.Parse before Env or LocalEnv")
|
||||||
|
|
@ -129,5 +198,8 @@ func applyEnvFlags(env Environment) Environment {
|
||||||
if *CronJobFlag {
|
if *CronJobFlag {
|
||||||
env.IsCronJob = true
|
env.IsCronJob = true
|
||||||
}
|
}
|
||||||
|
if *UbuntuVersionFlag != "" {
|
||||||
|
env.UbuntuVersion = *UbuntuVersionFlag
|
||||||
|
}
|
||||||
return env
|
return env
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,8 +23,8 @@ import (
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/XinFinOrg/XDPoSChain/internal/version"
|
||||||
"github.com/XinFinOrg/XDPoSChain/log"
|
"github.com/XinFinOrg/XDPoSChain/log"
|
||||||
"github.com/XinFinOrg/XDPoSChain/params"
|
|
||||||
"github.com/mattn/go-isatty"
|
"github.com/mattn/go-isatty"
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
)
|
)
|
||||||
|
|
@ -34,12 +34,13 @@ import (
|
||||||
var usecolor = (isatty.IsTerminal(os.Stdout.Fd()) || isatty.IsCygwinTerminal(os.Stdout.Fd())) && os.Getenv("TERM") != "dumb"
|
var usecolor = (isatty.IsTerminal(os.Stdout.Fd()) || isatty.IsCygwinTerminal(os.Stdout.Fd())) && os.Getenv("TERM") != "dumb"
|
||||||
|
|
||||||
// NewApp creates an app with sane defaults.
|
// NewApp creates an app with sane defaults.
|
||||||
func NewApp(gitCommit, usage string) *cli.App {
|
func NewApp(usage string) *cli.App {
|
||||||
|
git, _ := version.VCS()
|
||||||
app := cli.NewApp()
|
app := cli.NewApp()
|
||||||
app.EnableBashCompletion = true
|
app.EnableBashCompletion = true
|
||||||
app.Version = params.VersionWithCommit(gitCommit)
|
app.Version = version.WithCommit(git.Commit, git.Date)
|
||||||
app.Usage = usage
|
app.Usage = usage
|
||||||
app.Copyright = "Copyright 2024 XDPoSChain"
|
app.Copyright = "Copyright 2025 XDPoSChain"
|
||||||
app.Before = func(ctx *cli.Context) error {
|
app.Before = func(ctx *cli.Context) error {
|
||||||
MigrateGlobalFlags(ctx)
|
MigrateGlobalFlags(ctx)
|
||||||
return nil
|
return nil
|
||||||
|
|
@ -104,7 +105,7 @@ func doMigrateFlags(ctx *cli.Context) {
|
||||||
for _, parent := range ctx.Lineage()[1:] {
|
for _, parent := range ctx.Lineage()[1:] {
|
||||||
if parent.IsSet(name) {
|
if parent.IsSet(name) {
|
||||||
// When iterating across the lineage, we will be served both
|
// When iterating across the lineage, we will be served both
|
||||||
// the 'canon' and alias formats of all commmands. In most cases,
|
// the 'canon' and alias formats of all commands. In most cases,
|
||||||
// it's fine to set it in the ctx multiple times (one for each
|
// it's fine to set it in the ctx multiple times (one for each
|
||||||
// name), however, the Slice-flags are not fine.
|
// name), however, the Slice-flags are not fine.
|
||||||
// The slice-flags accumulate, so if we set it once as
|
// The slice-flags accumulate, so if we set it once as
|
||||||
|
|
|
||||||
77
internal/version/vcs.go
Normal file
77
internal/version/vcs.go
Normal file
|
|
@ -0,0 +1,77 @@
|
||||||
|
// Copyright 2022 The go-ethereum Authors
|
||||||
|
// This file is part of the go-ethereum library.
|
||||||
|
//
|
||||||
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU Lesser General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
package version
|
||||||
|
|
||||||
|
import (
|
||||||
|
"runtime/debug"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// the go tool embeds VCS information into the build.
|
||||||
|
|
||||||
|
const (
|
||||||
|
govcsTimeLayout = "2006-01-02T15:04:05Z"
|
||||||
|
ourTimeLayout = "20060102"
|
||||||
|
)
|
||||||
|
|
||||||
|
// These variables are set at build-time by the linker when the build is
|
||||||
|
// done by build/ci.go.
|
||||||
|
var gitCommit, gitDate string
|
||||||
|
|
||||||
|
// VCSInfo represents the git repository state.
|
||||||
|
type VCSInfo struct {
|
||||||
|
Commit string // head commit hash
|
||||||
|
Date string // commit time in YYYYMMDD format
|
||||||
|
Dirty bool
|
||||||
|
}
|
||||||
|
|
||||||
|
// VCS returns version control information of the current executable.
|
||||||
|
func VCS() (VCSInfo, bool) {
|
||||||
|
if gitCommit != "" {
|
||||||
|
// Use information set by the build script if present.
|
||||||
|
return VCSInfo{Commit: gitCommit, Date: gitDate}, true
|
||||||
|
}
|
||||||
|
if buildInfo, ok := debug.ReadBuildInfo(); ok {
|
||||||
|
if buildInfo.Main.Path == ourPath {
|
||||||
|
return buildInfoVCS(buildInfo)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return VCSInfo{}, false
|
||||||
|
}
|
||||||
|
|
||||||
|
// buildInfoVCS returns VCS information of the build.
|
||||||
|
func buildInfoVCS(info *debug.BuildInfo) (s VCSInfo, ok bool) {
|
||||||
|
for _, v := range info.Settings {
|
||||||
|
switch v.Key {
|
||||||
|
case "vcs.revision":
|
||||||
|
s.Commit = v.Value
|
||||||
|
case "vcs.modified":
|
||||||
|
if v.Value == "true" {
|
||||||
|
s.Dirty = true
|
||||||
|
}
|
||||||
|
case "vcs.time":
|
||||||
|
t, err := time.Parse(govcsTimeLayout, v.Value)
|
||||||
|
if err == nil {
|
||||||
|
s.Date = t.Format(ourTimeLayout)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if s.Commit != "" && s.Date != "" {
|
||||||
|
ok = true
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
52
internal/version/version.go
Normal file
52
internal/version/version.go
Normal file
|
|
@ -0,0 +1,52 @@
|
||||||
|
// Copyright 2022 The go-ethereum Authors
|
||||||
|
// This file is part of the go-ethereum library.
|
||||||
|
//
|
||||||
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
||||||
|
// it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
// the Free Software Foundation, either version 3 of the License, or
|
||||||
|
// (at your option) any later version.
|
||||||
|
//
|
||||||
|
// The go-ethereum library is distributed in the hope that it will be useful,
|
||||||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
// GNU Lesser General Public License for more details.
|
||||||
|
//
|
||||||
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
// Package version implements reading of build version information.
|
||||||
|
package version
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/XinFinOrg/XDPoSChain/version"
|
||||||
|
)
|
||||||
|
|
||||||
|
const ourPath = "github.com/XinFinOrg/XDPoSChain" // Path to our module
|
||||||
|
|
||||||
|
// Family holds the textual version string for major.minor
|
||||||
|
var Family = fmt.Sprintf("%d.%d", version.Major, version.Minor)
|
||||||
|
|
||||||
|
// Semantic holds the textual version string for major.minor.patch.
|
||||||
|
var Semantic = fmt.Sprintf("%d.%d.%d", version.Major, version.Minor, version.Patch)
|
||||||
|
|
||||||
|
// WithMeta holds the textual version string including the metadata.
|
||||||
|
var WithMeta = func() string {
|
||||||
|
v := Semantic
|
||||||
|
if version.Meta != "" {
|
||||||
|
v += "-" + version.Meta
|
||||||
|
}
|
||||||
|
return v
|
||||||
|
}()
|
||||||
|
|
||||||
|
func WithCommit(gitCommit, gitDate string) string {
|
||||||
|
vsn := WithMeta
|
||||||
|
if len(gitCommit) >= 8 {
|
||||||
|
vsn += "-" + gitCommit[:8]
|
||||||
|
}
|
||||||
|
if (version.Meta != "stable") && (gitDate != "") {
|
||||||
|
vsn += "-" + gitDate
|
||||||
|
}
|
||||||
|
return vsn
|
||||||
|
}
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
// Copyright 2016 The go-ethereum Authors
|
// Copyright 2024 The go-ethereum Authors
|
||||||
// This file is part of the go-ethereum library.
|
// This file is part of the go-ethereum library.
|
||||||
//
|
//
|
||||||
// The go-ethereum library is free software: you can redistribute it and/or modify
|
// The go-ethereum library is free software: you can redistribute it and/or modify
|
||||||
|
|
@ -14,32 +14,11 @@
|
||||||
// You should have received a copy of the GNU Lesser General Public License
|
// You should have received a copy of the GNU Lesser General Public License
|
||||||
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
package params
|
package version
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
const (
|
||||||
VersionMajor = 2 // Major version component of the current release
|
Major = 2 // Major version component of the current release
|
||||||
VersionMinor = 6 // Minor version component of the current release
|
Minor = 6 // Minor version component of the current release
|
||||||
VersionPatch = 1 // Patch version component of the current release
|
Patch = 5 // Patch version component of the current release
|
||||||
VersionMeta = "beta" // Version metadata to append to the version string
|
Meta = "testnet" // Version metadata to append to the version string
|
||||||
)
|
)
|
||||||
|
|
||||||
// Version holds the textual version string.
|
|
||||||
var Version = func() string {
|
|
||||||
v := fmt.Sprintf("%d.%d.%d", VersionMajor, VersionMinor, VersionPatch)
|
|
||||||
if VersionMeta != "" {
|
|
||||||
v += "-" + VersionMeta
|
|
||||||
}
|
|
||||||
return v
|
|
||||||
}()
|
|
||||||
|
|
||||||
func VersionWithCommit(gitCommit string) string {
|
|
||||||
vsn := Version
|
|
||||||
if len(gitCommit) >= 8 {
|
|
||||||
vsn += "-" + gitCommit[:8]
|
|
||||||
}
|
|
||||||
return vsn
|
|
||||||
}
|
|
||||||
Loading…
Reference in a new issue