cmd, internal/build, docker: advertise commit date in unstable build versions (#19522)
* add-date-to unstable * fields-insteadof-split * internal/build: support building with missing git * docker: add git history back to support commit date in version * internal/build: use PR commits hashes for PR builds
This commit is contained in:
parent
c113723fdb
commit
be4d74f8d2
@ -1,7 +1,3 @@
|
|||||||
**/.git
|
|
||||||
.git
|
|
||||||
!.git/HEAD
|
|
||||||
!.git/refs/heads
|
|
||||||
**/*_test.go
|
**/*_test.go
|
||||||
|
|
||||||
build/_workspace
|
build/_workspace
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
# Build Geth in a stock Go builder container
|
# Build Geth in a stock Go builder container
|
||||||
FROM golang:1.12-alpine as builder
|
FROM golang:1.12-alpine as builder
|
||||||
|
|
||||||
RUN apk add --no-cache make gcc musl-dev linux-headers
|
RUN apk add --no-cache make gcc musl-dev linux-headers git
|
||||||
|
|
||||||
ADD . /go-ethereum
|
ADD . /go-ethereum
|
||||||
RUN cd /go-ethereum && make geth
|
RUN cd /go-ethereum && make geth
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
# Build Geth in a stock Go builder container
|
# Build Geth in a stock Go builder container
|
||||||
FROM golang:1.12-alpine as builder
|
FROM golang:1.12-alpine as builder
|
||||||
|
|
||||||
RUN apk add --no-cache make gcc musl-dev linux-headers
|
RUN apk add --no-cache make gcc musl-dev linux-headers git
|
||||||
|
|
||||||
ADD . /go-ethereum
|
ADD . /go-ethereum
|
||||||
RUN cd /go-ethereum && make all
|
RUN cd /go-ethereum && make all
|
||||||
|
@ -284,6 +284,7 @@ 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", "main.gitCommit="+env.Commit)
|
||||||
|
ld = append(ld, "-X", "main.gitDate="+env.Date)
|
||||||
}
|
}
|
||||||
if runtime.GOOS == "darwin" {
|
if runtime.GOOS == "darwin" {
|
||||||
ld = append(ld, "-s")
|
ld = append(ld, "-s")
|
||||||
|
@ -30,11 +30,12 @@ const (
|
|||||||
|
|
||||||
// Git SHA1 commit hash of the release (set via linker flags)
|
// Git SHA1 commit hash of the release (set via linker flags)
|
||||||
var gitCommit = ""
|
var gitCommit = ""
|
||||||
|
var gitDate = ""
|
||||||
|
|
||||||
var app *cli.App
|
var app *cli.App
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
app = utils.NewApp(gitCommit, "an Ethereum key manager")
|
app = utils.NewApp(gitCommit, gitDate, "an Ethereum key manager")
|
||||||
app.Commands = []cli.Command{
|
app.Commands = []cli.Command{
|
||||||
commandGenerate,
|
commandGenerate,
|
||||||
commandInspect,
|
commandInspect,
|
||||||
|
@ -27,9 +27,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var gitCommit = "" // Git SHA1 commit hash of the release (set via linker flags)
|
var gitCommit = "" // Git SHA1 commit hash of the release (set via linker flags)
|
||||||
|
var gitDate = ""
|
||||||
|
|
||||||
var (
|
var (
|
||||||
app = utils.NewApp(gitCommit, "the evm command line interface")
|
app = utils.NewApp(gitCommit, gitDate, "the evm command line interface")
|
||||||
|
|
||||||
DebugFlag = cli.BoolFlag{
|
DebugFlag = cli.BoolFlag{
|
||||||
Name: "debug",
|
Name: "debug",
|
||||||
|
@ -101,7 +101,7 @@ func loadConfig(file string, cfg *gethConfig) error {
|
|||||||
func defaultNodeConfig() node.Config {
|
func defaultNodeConfig() node.Config {
|
||||||
cfg := node.DefaultConfig
|
cfg := node.DefaultConfig
|
||||||
cfg.Name = clientIdentifier
|
cfg.Name = clientIdentifier
|
||||||
cfg.Version = params.VersionWithCommit(gitCommit)
|
cfg.Version = params.VersionWithCommit(gitCommit, gitDate)
|
||||||
cfg.HTTPModules = append(cfg.HTTPModules, "eth", "shh")
|
cfg.HTTPModules = append(cfg.HTTPModules, "eth", "shh")
|
||||||
cfg.WSModules = append(cfg.WSModules, "eth", "shh")
|
cfg.WSModules = append(cfg.WSModules, "eth", "shh")
|
||||||
cfg.IPCPath = "geth.ipc"
|
cfg.IPCPath = "geth.ipc"
|
||||||
|
@ -50,7 +50,7 @@ func TestConsoleWelcome(t *testing.T) {
|
|||||||
geth.SetTemplateFunc("goos", func() string { return runtime.GOOS })
|
geth.SetTemplateFunc("goos", func() string { return runtime.GOOS })
|
||||||
geth.SetTemplateFunc("goarch", func() string { return runtime.GOARCH })
|
geth.SetTemplateFunc("goarch", func() string { return runtime.GOARCH })
|
||||||
geth.SetTemplateFunc("gover", runtime.Version)
|
geth.SetTemplateFunc("gover", runtime.Version)
|
||||||
geth.SetTemplateFunc("gethver", func() string { return params.VersionWithMeta })
|
geth.SetTemplateFunc("gethver", func() string { return params.VersionWithCommit("", "") })
|
||||||
geth.SetTemplateFunc("niltime", func() string { return time.Unix(0, 0).Format(time.RFC1123) })
|
geth.SetTemplateFunc("niltime", func() string { return time.Unix(0, 0).Format(time.RFC1123) })
|
||||||
geth.SetTemplateFunc("apis", func() string { return ipcAPIs })
|
geth.SetTemplateFunc("apis", func() string { return ipcAPIs })
|
||||||
|
|
||||||
@ -133,7 +133,7 @@ func testAttachWelcome(t *testing.T, geth *testgeth, 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("gethver", func() string { return params.VersionWithMeta })
|
attach.SetTemplateFunc("gethver", func() string { return params.VersionWithCommit("", "") })
|
||||||
attach.SetTemplateFunc("etherbase", func() string { return geth.Etherbase })
|
attach.SetTemplateFunc("etherbase", func() string { return geth.Etherbase })
|
||||||
attach.SetTemplateFunc("niltime", func() string { return time.Unix(0, 0).Format(time.RFC1123) })
|
attach.SetTemplateFunc("niltime", func() string { return time.Unix(0, 0).Format(time.RFC1123) })
|
||||||
attach.SetTemplateFunc("ipc", func() bool { return strings.HasPrefix(endpoint, "ipc") })
|
attach.SetTemplateFunc("ipc", func() bool { return strings.HasPrefix(endpoint, "ipc") })
|
||||||
|
@ -50,8 +50,9 @@ const (
|
|||||||
var (
|
var (
|
||||||
// Git SHA1 commit hash of the release (set via linker flags)
|
// Git SHA1 commit hash of the release (set via linker flags)
|
||||||
gitCommit = ""
|
gitCommit = ""
|
||||||
|
gitDate = ""
|
||||||
// The app that holds all commands and flags.
|
// The app that holds all commands and flags.
|
||||||
app = utils.NewApp(gitCommit, "the go-ethereum command line interface")
|
app = utils.NewApp(gitCommit, gitDate, "the go-ethereum command line interface")
|
||||||
// flags that configure the node
|
// flags that configure the node
|
||||||
nodeFlags = []cli.Flag{
|
nodeFlags = []cli.Flag{
|
||||||
utils.IdentityFlag,
|
utils.IdentityFlag,
|
||||||
|
@ -112,6 +112,9 @@ func version(ctx *cli.Context) error {
|
|||||||
if gitCommit != "" {
|
if gitCommit != "" {
|
||||||
fmt.Println("Git Commit:", gitCommit)
|
fmt.Println("Git Commit:", gitCommit)
|
||||||
}
|
}
|
||||||
|
if gitDate != "" {
|
||||||
|
fmt.Println("Git Commit Date:", gitDate)
|
||||||
|
}
|
||||||
fmt.Println("Architecture:", runtime.GOARCH)
|
fmt.Println("Architecture:", runtime.GOARCH)
|
||||||
fmt.Println("Protocol Versions:", eth.ProtocolVersions)
|
fmt.Println("Protocol Versions:", eth.ProtocolVersions)
|
||||||
fmt.Println("Network Id:", eth.DefaultConfig.NetworkId)
|
fmt.Println("Network Id:", eth.DefaultConfig.NetworkId)
|
||||||
|
@ -26,6 +26,7 @@ import (
|
|||||||
var (
|
var (
|
||||||
version = "0.1"
|
version = "0.1"
|
||||||
gitCommit string // Git SHA1 commit hash of the release (set via linker flags)
|
gitCommit string // Git SHA1 commit hash of the release (set via linker flags)
|
||||||
|
gitDate string
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@ -45,6 +46,9 @@ func newApp() (app *cli.App) {
|
|||||||
if len(gitCommit) >= 8 {
|
if len(gitCommit) >= 8 {
|
||||||
app.Version += "-" + gitCommit[:8]
|
app.Version += "-" + gitCommit[:8]
|
||||||
}
|
}
|
||||||
|
if gitDate != "" {
|
||||||
|
app.Version += "-" + gitDate
|
||||||
|
}
|
||||||
app.Usage = "Swarm Global Store"
|
app.Usage = "Swarm Global Store"
|
||||||
|
|
||||||
// app flags (for all commands)
|
// app flags (for all commands)
|
||||||
|
@ -102,7 +102,7 @@ func init() {
|
|||||||
utils.ListenPortFlag.Value = 30399
|
utils.ListenPortFlag.Value = 30399
|
||||||
}
|
}
|
||||||
|
|
||||||
var app = utils.NewApp("", "Ethereum Swarm")
|
var app = utils.NewApp("", "", "Ethereum Swarm")
|
||||||
|
|
||||||
// This init function creates the cli.App.
|
// This init function creates the cli.App.
|
||||||
func init() {
|
func init() {
|
||||||
|
@ -25,6 +25,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var gitCommit string // Git SHA1 commit hash of the release (set via linker flags)
|
var gitCommit string // Git SHA1 commit hash of the release (set via linker flags)
|
||||||
|
var gitDate string
|
||||||
|
|
||||||
// default value for "create" command --nodes flag
|
// default value for "create" command --nodes flag
|
||||||
const defaultNodes = 8
|
const defaultNodes = 8
|
||||||
@ -40,7 +41,7 @@ func main() {
|
|||||||
// newApp construct a new instance of Swarm Snapshot Utility.
|
// newApp construct a new instance of Swarm Snapshot Utility.
|
||||||
// Method Run is called on it in the main function and in tests.
|
// Method Run is called on it in the main function and in tests.
|
||||||
func newApp() (app *cli.App) {
|
func newApp() (app *cli.App) {
|
||||||
app = utils.NewApp(gitCommit, "Swarm Snapshot Utility")
|
app = utils.NewApp(gitCommit, gitDate, "Swarm Snapshot Utility")
|
||||||
|
|
||||||
app.Name = "swarm-snapshot"
|
app.Name = "swarm-snapshot"
|
||||||
app.Usage = ""
|
app.Usage = ""
|
||||||
|
@ -92,16 +92,13 @@ GLOBAL OPTIONS:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewApp creates an app with sane defaults.
|
// NewApp creates an app with sane defaults.
|
||||||
func NewApp(gitCommit, usage string) *cli.App {
|
func NewApp(gitCommit, gitDate, usage string) *cli.App {
|
||||||
app := cli.NewApp()
|
app := cli.NewApp()
|
||||||
app.Name = filepath.Base(os.Args[0])
|
app.Name = filepath.Base(os.Args[0])
|
||||||
app.Author = ""
|
app.Author = ""
|
||||||
//app.Authors = nil
|
//app.Authors = nil
|
||||||
app.Email = ""
|
app.Email = ""
|
||||||
app.Version = params.VersionWithMeta
|
app.Version = params.VersionWithCommit(gitCommit, gitDate)
|
||||||
if len(gitCommit) >= 8 {
|
|
||||||
app.Version += "-" + gitCommit[:8]
|
|
||||||
}
|
|
||||||
app.Usage = usage
|
app.Usage = usage
|
||||||
return app
|
return app
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,9 @@ import (
|
|||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -35,17 +37,17 @@ var (
|
|||||||
|
|
||||||
// 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
|
Name string // name of the environment
|
||||||
Repo string // name of GitHub repo
|
Repo string // name of GitHub repo
|
||||||
Commit, Branch, Tag string // Git info
|
Commit, Date, Branch, Tag string // Git info
|
||||||
Buildnum string
|
Buildnum string
|
||||||
IsPullRequest bool
|
IsPullRequest bool
|
||||||
IsCronJob 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 +55,15 @@ 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 == "" {
|
||||||
|
os.Getenv("TRAVIS_COMMIT")
|
||||||
|
}
|
||||||
return Environment{
|
return Environment{
|
||||||
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,10 +71,15 @@ 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 == "" {
|
||||||
|
os.Getenv("APPVEYOR_REPO_COMMIT")
|
||||||
|
}
|
||||||
return Environment{
|
return Environment{
|
||||||
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"),
|
||||||
@ -84,14 +96,15 @@ func LocalEnv() Environment {
|
|||||||
env := applyEnvFlags(Environment{Name: "local", Repo: "ethereum/go-ethereum"})
|
env := applyEnvFlags(Environment{Name: "local", Repo: "ethereum/go-ethereum"})
|
||||||
|
|
||||||
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 {
|
||||||
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 +120,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")
|
||||||
|
@ -68,13 +68,14 @@ func RunGit(args ...string) string {
|
|||||||
cmd := exec.Command("git", args...)
|
cmd := exec.Command("git", args...)
|
||||||
var stdout, stderr bytes.Buffer
|
var stdout, stderr bytes.Buffer
|
||||||
cmd.Stdout, cmd.Stderr = &stdout, &stderr
|
cmd.Stdout, cmd.Stderr = &stdout, &stderr
|
||||||
if err := cmd.Run(); err == exec.ErrNotFound {
|
if err := cmd.Run(); err != nil {
|
||||||
if !warnedAboutGit {
|
if e, ok := err.(*exec.Error); ok && e.Err == exec.ErrNotFound {
|
||||||
log.Println("Warning: can't find 'git' in PATH")
|
if !warnedAboutGit {
|
||||||
warnedAboutGit = true
|
log.Println("Warning: can't find 'git' in PATH")
|
||||||
|
warnedAboutGit = true
|
||||||
|
}
|
||||||
|
return ""
|
||||||
}
|
}
|
||||||
return ""
|
|
||||||
} else if err != nil {
|
|
||||||
log.Fatal(strings.Join(cmd.Args, " "), ": ", err, "\n", stderr.String())
|
log.Fatal(strings.Join(cmd.Args, " "), ": ", err, "\n", stderr.String())
|
||||||
}
|
}
|
||||||
return strings.TrimSpace(stdout.String())
|
return strings.TrimSpace(stdout.String())
|
||||||
|
@ -55,10 +55,13 @@ func ArchiveVersion(gitCommit string) string {
|
|||||||
return vsn
|
return vsn
|
||||||
}
|
}
|
||||||
|
|
||||||
func VersionWithCommit(gitCommit string) string {
|
func VersionWithCommit(gitCommit, gitDate string) string {
|
||||||
vsn := VersionWithMeta
|
vsn := VersionWithMeta
|
||||||
if len(gitCommit) >= 8 {
|
if len(gitCommit) >= 8 {
|
||||||
vsn += "-" + gitCommit[:8]
|
vsn += "-" + gitCommit[:8]
|
||||||
}
|
}
|
||||||
|
if (VersionMeta != "stable") && (gitDate != "") {
|
||||||
|
vsn += "-" + gitDate
|
||||||
|
}
|
||||||
return vsn
|
return vsn
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user