decred / dcrd

Decred daemon in Go (golang).
https://decred.org
ISC License
736 stars 291 forks source link

Distinguish released versions from dev version in -V version string #516

Closed jcvernaleo closed 7 years ago

jcvernaleo commented 7 years ago

I'm opening this in the dcrd repo but really it applies to decred/dcrwallet, decred/gominer, decred/decrediton, decred/dcrticketbuyer, decred/dcrinstal, and any other that have a version number.

Currently we have:

jcv@triforce ~ $ dcrd -V
dcrd version 0.6.1-beta

There is no way to know if that is really the 0.6.1 release or some build from git after that.

go has the option -ldflags "-X " that can be used to pass something in at build time. We could make the build scripts pass in the version at build time and use the git commit hash for any other times like -X main.versiongit rev-parse HEAD" or possibly some other scheme.

I believe @jrick brought this up on irc initially.

Thoughts, Opinions?

jolan commented 7 years ago

+1 from me, I used to use the following to make sure I was on the right revision when testing:

go build -ldflags "-X main.appBuild=$(git describe --always)"
jrick commented 7 years ago

I guess adding the git sha1 is fine but what i'd really like is to default to appending -dev to the version when built without any special linker flags, and to use -release or nothing when doing an official release.

Unfortunately there is no way to add the git sha when doing a bare go build or go install. Best we can do there is to add makefiles or other build systems to all the projects, and tell people to use those.

So, without adding other build scripts, when building from source people would see versions like: 0.7.0-dev. Releases would be like 0.7.0-release+66710f7 or 0.7.0+66710f7, where 66710f7 is the output of git rev-parse --short HEAD. This output also follows the naming conventions used by semver, even though the version numbers themselves do not follow semver.

jrick commented 7 years ago

@jolan git describe --always shows me:

PS C:\Users\jrick\go\src\github.com\decred\dcrwallet> git describe --always
BTCWALLET_0_5_0_ALPHA-386-g66710f7

Not sure exactly where that info is coming from but something isn't quite right...

jcvernaleo commented 7 years ago

Yeah, since there is no way to get the sha in there without imposing some Makefile or other build system I think @jrick's idea (-dev) appended to the version normally and excluded in release builds (where we can control how things are built).

jcvernaleo commented 7 years ago

@jrick and @jolan what do you think of this:

jcv@triforce dcrd $ go build -ldflags "-X main.releaseBuild=true"
jcv@triforce dcrd $ ./dcrd -V
dcrd version 0.6.1-beta
jcv@triforce dcrd $ go build
jcv@triforce dcrd $ ./dcrd -V
dcrd version 0.6.1-beta-dev

Then I would modify the build script for that.

jrick commented 7 years ago

Instead of a bool why not make the constant a string, and then we can pass in other additional info like the git sha if we want to?

jrick commented 7 years ago

Also see points 9 and 10: http://semver.org/#spec-item-9

Might want to put 'dev' or 'release' in the build metadata rather than the prerelease field.

dcrd version 0.6.1-beta+dev
dcrd version 0.6.1-beta+release
dcrd version 0.6.1-beta+release.66710f7