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

Version string verbosity #3240

Closed
wants to merge 1 commit into from
Closed

Version string verbosity #3240

wants to merge 1 commit into from

Conversation

strump
Copy link

@strump strump commented Feb 11, 2023

Build script doesn't produce version string if no git history is available.

Steps to reproduce:

  1. Clone repo with no history (Mogenius.com does this): git clone --depth 1 https://github.com/dani-garcia/vaultwarden.git
  2. Build docker image: docker build --build-arg DB=sqlite -f docker/amd64/Dockerfile -t vaultwarden:local .
  3. Run it: docker run -it --rm vaultwarden:local

Actual result: no version information in output

/--------------------------------------------------------------------\
|                        Starting Vaultwarden                        |
|--------------------------------------------------------------------|
| This is an *unofficial* Bitwarden implementation, DO NOT use the   |
| official channels to report bugs/features, regardless of client.   |
| Send usage/configuration questions or feature requests to:         |
|   https://vaultwarden.discourse.group/                             |
| Report suspected bugs/issues in the software itself at:            |
|   https://github.com/dani-garcia/vaultwarden/issues/new            |
\--------------------------------------------------------------------/

After this PR:

/--------------------------------------------------------------------\
|                        Starting Vaultwarden                        |
|             Version main-7d7da921 2023-02-11 17:27:10              |
|--------------------------------------------------------------------|
| This is an *unofficial* Bitwarden implementation, DO NOT use the   |
| official channels to report bugs/features, regardless of client.   |
| Send usage/configuration questions or feature requests to:         |
|   https://vaultwarden.discourse.group/                             |
| Report suspected bugs/issues in the software itself at:            |
|   https://github.com/dani-garcia/vaultwarden/issues/new            |
\--------------------------------------------------------------------/

Description:

  • Last tag is now optional.
  • Timestamp is added to version string.

Four types of version string are generated in build.rs:

  1. Main branch + last tag → {last_tag}-{rev_short} {commit_time}
  2. Main branch → main-{rev_short} {commit_time}
  3. Non-main branch + last tag → {last_tag}-{rev_short} ({branch}) {commit_time}
  4. Non-main branch → {rev_short} ({branch}) {commit_time}

@@ -57,8 +57,10 @@ fn version_from_git_info() -> Result<String, std::io::Error> {

// The last available tag, equal to exact_tag when
// the current commit is tagged
let last_tag = run(&["git", "describe", "--abbrev=0", "--tags"])?;
println!("cargo:rustc-env=GIT_LAST_TAG={last_tag}");
let last_tag_maybe = run(&["git", "describe", "--abbrev=0", "--tags"]).ok();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should use https://crates.io/crates/vergen for that

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is maybe a nice one to use instead of our custom calls, and it could provide some more info.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yean and its very easy to use, I use it on wdes/mail-autodiscover-autoconfig#3 (comment)
if examples are needed

@BlackDex
Copy link
Collaborator

Besides the tests that are failing. There is an env variable that can be set if it is known to not having a full git clone.
You can use VW_VERSION to set a custom version string instead of this modification.

@@ -69,12 +71,25 @@ fn version_from_git_info() -> Result<String, std::io::Error> {
let rev_short = rev.get(..8).unwrap_or_default();
println!("cargo:rustc-env=GIT_REV={rev_short}");

// The current git commit time
let commit_time = run(&["git", "log", "-1", "--format=%cd", "--date=format:%Y-%m-%d %H:%M:%S"])?;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding the commit time to the version string seems overly verbose, and isn't something that's usually included in a version string itself. While I don't feel that including the commit time is all that valuable, if you really want to include it, I think it should go on its own line of output, and it should also include timezone info.

BTW, hooks/build already includes the build (not commit) time in the Docker image. To me it seems a bit odd for those times not to match, so that's another reason I'd favor not including the commit time.

@BlackDex
Copy link
Collaborator

BlackDex commented Mar 5, 2023

I have looked into vergen, and it looks nice, but it would change our current version string and not the same info we would want.
While I can see a good point into using the commit date as build date in case no other info is present, it isn't very useful in the end I think.

If some maintainer or builder is using a shallow pull they should export VW_VERSION with the correct version them self, since they probably also need to give there package or image a version number, and they can set the same.

Going to close this as we are not going to implement this.
I might see if i can add some more features to vergen so we can use it with our may of versioning, and i think it could be useful for other projects as well. But that is something for later.

@BlackDex BlackDex closed this Mar 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants