-
Notifications
You must be signed in to change notification settings - Fork 20.5k
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
Add Date to Unstable #19522
Add Date to Unstable #19522
Conversation
params/version.go
Outdated
return time.Unix(ti, 0).Format("20060102") | ||
} | ||
return "" | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This solution would require the entire git repository to be available during Geth's execution. You need to do this during build time when the source code is available.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, just noticed this when I was running that it was being pulled during the call. Give me a few minutes...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
okey dokey, updated. this solution is a bit more involved but it appears this is what you're looking for. let me know!
updated @karalabe |
CI fails appear to be unrelated. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally this looks good to me. Have not tested it
Don't know if this was already broken (I suppose so), but it appears it cannot build if git is not present:
It looks like we do want to build anyway, but at least linux/fedora gives a different error than we're expecting: func RunGit(args ...string) string {
cmd := exec.Command("git", args...)
var stdout, stderr bytes.Buffer
cmd.Stdout, cmd.Stderr = &stdout, &stderr
if err := cmd.Run(); err == exec.ErrNotFound {
if !warnedAboutGit {
log.Println("Warning: can't find 'git' in PATH")
warnedAboutGit = true
}
return ""
} else if err != nil {
log.Fatal(strings.Join(cmd.Args, " "), ": ", err, "\n", stderr.String())
}
return strings.TrimSpace(stdout.String())
} |
Ah, on
|
This seems to work diff --git a/internal/build/util.go b/internal/build/util.go
index 319c0f2d3..a28b51895 100644
--- a/internal/build/util.go
+++ b/internal/build/util.go
@@ -68,13 +68,19 @@ func RunGit(args ...string) string {
cmd := exec.Command("git", args...)
var stdout, stderr bytes.Buffer
cmd.Stdout, cmd.Stderr = &stdout, &stderr
- if err := cmd.Run(); err == exec.ErrNotFound {
- if !warnedAboutGit {
- log.Println("Warning: can't find 'git' in PATH")
- warnedAboutGit = true
+ err := cmd.Run()
+ if err != nil {
+ if e, ok := err.(*exec.Error); ok {
+ if e.Err == exec.ErrNotFound {
+ if !warnedAboutGit {
+ log.Println("Warning: can't find 'git' in PATH")
+ warnedAboutGit = true
+ }
+ return ""
+ }
}
- return ""
- } else if err != nil {
+ }
+ if err != nil {
log.Fatal(strings.Join(cmd.Args, " "), ": ", err, "\n", stderr.String())
}
return strings.TrimSpace(stdout.String()) I don't know, @karalabe, is this worth fixing now while we're at it? |
Fwiw, windows also appears to wrap the erorr, so building without git can't work on windows either right now. |
Also, if there's no git repo present, it will show
Wouldn't it be nicer to show |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's also a small catch. The date doesn't work in docker, because our .dockerignore doesn't pass the git repo in. Trying to figure out how best to actually handle this without hacing to forward the entire repo.
cmd/utils/flags.go
Outdated
if len(gitCommit) >= 8 { | ||
app.Version += "-" + gitCommit[:8] | ||
} | ||
app.Usage = usage |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You accidentally deleted setting the usage.
internal/build/env.go
Outdated
IsCronJob bool | ||
Name string // name of the environment | ||
Repo string // name of GitHub repo | ||
Commit, CommitDate, Branch, Tag string // Git info |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think if you call it Date
, it's enough.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
got it
internal/build/env.go
Outdated
@@ -107,6 +114,23 @@ func firstLine(s string) string { | |||
return strings.Split(s, "\n")[0] | |||
} | |||
|
|||
func getCommitDate(commit string) string { | |||
if commit != "" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Slight nit, usually it's cleaner code to handle "error" cases first, returning; and only then the main clauses. It saves indentation. i.e.
if commit == "" {
return ""
}
// rest of the code without indent
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agreed, will change
internal/build/env.go
Outdated
@@ -107,6 +114,23 @@ func firstLine(s string) string { | |||
return strings.Split(s, "\n")[0] | |||
} | |||
|
|||
func getCommitDate(commit string) string { | |||
if commit != "" { | |||
out, err := exec.Command("git", "show", "-s", "--format=%ct", commit).CombinedOutput() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have a utility method called build.RunGit
, which does a bit more magic around failures. Please use that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, will do
internal/build/env.go
Outdated
ti, err := strconv.ParseInt(strings.TrimSpace(string(out)), 10, 64) | ||
if err != nil { | ||
log.Println("Could not convert gitCommit date. Parsed timestamp is: " + err.Error()) | ||
return "" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think at this point we should do a log.Fatal
. We seem to have the proper repo, but something is very very wrong if we can't interpret it. Safer to break immediately than to silently disable the date feature without anybody noticing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this makes sense
build/ci.go
Outdated
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pls remove this superfluous empty line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will do
vsn := VersionWithMeta | ||
if len(gitCommit) >= 8 { | ||
vsn += "-" + gitCommit[:8] | ||
} | ||
if VersionMeta != "stable" { | ||
vsn += "-" + gitDate |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need to also check that gitDate is not nil, otherwise you get:
INFO [05-03|10:50:08.272] [...] instance=Geth/v1.9.0-unstable-/linux-amd64/go1.12.3
note, the version has a trailing -
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question regarding this. We do want the date anytime it's not stable, so by nature a v1.9.0-unstable-
would be an error. The question is, do we want to add the check here (essentially a bandaid) and drop the extra dash, or no? I think we do want to add here as I think about it because the other apps built, ie Swarm, end up with this extra dash because this process isn't fully built out there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
I see that regarding the .dockerignore not passing in .git. Without this though, |
4eee67d
to
78e877b
Compare
This should do @karalabe . I think the git is ok, lmk if not |
@holiman We didn't need git until now during builds, because we injected 1-2 fiels from |
@holiman Ah, I see you already debugged and wrote up the code. That SGTM, checked that it's not a recent Go change, 8 years old. The old code was just borked. |
@holiman No, I was just explaining what we've been doing with git in the past and now, since you brought up that builds failed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added some tiny git fixes to make sure it works in docker and in our travis/appveyor builders too. LGTM.
Thanks for putting all that effort and iterations into this PR!
ah... I see what you do there. very cool |
@HACKDOM Btw, we've been talking with @holiman that another potentially useful thing might be to include in the version whether it was built from a clean commit, or contains dirty code? I.e. From time to time we get bug reports that something doesn't work, and it turns out that the OP modified Geth and that's the reason. Would be nice to be able to detect those cases, by prepending a Would you like to pick such a task up? If not, no problem, I can also do it, just figured you might be interested since it's almost the same modification that you did here :) |
Closes #19517
The second commit is a bit out of scope, let me know if that's a problem. This should work now.