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

Including the branch name in the version? #51

Open
lokkju opened this issue Dec 7, 2017 · 5 comments
Open

Including the branch name in the version? #51

lokkju opened this issue Dec 7, 2017 · 5 comments

Comments

@lokkju
Copy link

lokkju commented Dec 7, 2017

Any chance of a simple option to enable including branch names other than master in the version string?

@dwijnand
Copy link
Member

dwijnand commented Dec 7, 2017

Is there much demand for this support out the box?

Without out the box support you can do this by customising the version string, as defined in https://github.com/dwijnand/sbt-dynver#custom-version-string.

@lokkju
Copy link
Author

lokkju commented Dec 7, 2017

I think it's a pretty common use case, and standard in many build systems; it's could be included as part of build metadata with semver, at the end.

More bringing it up a discussion point; it'd be nice to see the branch name in the metadata, but after thinking about it, it's not required for version uniqueness.

@raboof
Copy link
Collaborator

raboof commented May 16, 2019

I don't think it would be particularly useful to include this in the default version string, but it would be neat to offer a utility function to easily get the git branch for use in your custom version string

@dwijnand
Copy link
Member

A utility function leads to utility function variants, overloads, default params, etc. I'd rather not. Do something like

scala> scala.util.Try(scala.sys.process.Process("git rev-parse --symbolic-full-name --abbrev-ref HEAD").!!).toOption.map(_.dropRight(1))
res0: Option[String] = Some(master)

@atais
Copy link

atais commented Apr 14, 2020

I had a similar need and I do not think the lib is missing anything. It's actually all there.

Here is my very simplified auto-versioning.

.settings(
    version := myVersion(dynverGitDescribeOutput.value),
    dynver ~= (_.replace('+', '-'))
)

def myVersion(out: Option[sbtdynver.GitDescribeOutput]): String = {
  val branchName = Process("git rev-parse --symbolic-full-name --abbrev-ref HEAD").!!.dropRight(1)
  out match {
    case Some(v) if branchName == "develop" =>
      s"${v.commitSuffix.distance}-${v.ref.value}"
    case Some(v) =>
      s"${v.commitSuffix.distance}-${v.ref.value}-${branchName}"
    case None =>
      "0-undefined"
  }
}

btw. I am still using 3.3.0 because 4.0.0 is too fancy for me.

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

No branches or pull requests

4 participants