4

Is it possible to specify a git scheme for git tag names with sbt-release?

The tag commit message and comment can be specified. Per the README:

releaseTagComment := s"Releasing ${(version in ThisBuild).value}", releaseCommitMessage := s"Setting version to ${(version in ThisBuild).value}",

But I've been unable to find a way to change the default for the actual tag text, which is set to s"v${releaseVersion}".

I'd like to specify the project name in the tag string, e.g., "myproject-v0.1.1"

To clarify, by the "tag string", I mean the string you see in e.g., git tag -l

We have multiple projects in the same git repository, and they have similar version numbers, so tags like "v0.1.0" are ambiguous.

rcreswick
  • 16,483
  • 15
  • 59
  • 70
  • The question is confusing, what exactly are you asking? What is this "actual tag text" you refer to? Isn't this covered by `releaseTagComment` and `releaseCommitMessage`? – marios Jan 28 '17 at 23:01
  • @marios I've added some clarifications – rcreswick Jan 30 '17 at 18:27

2 Answers2

5

there's an sbt-release configuration value releaseTagName which you can modify to customize how release tag is generated. This is working for me:

lazy val root = (project in file(".")).
  settings(
    .... other settings ....
    releaseTagName := s"version-${if (releaseUseGlobalVersion.value) (version in ThisBuild).value else version.value}",
    ....
    )

If everything else fails you can also customize release steps, and write your own tagRelease step.

vitalii
  • 3,335
  • 14
  • 18
0

You can use the custom tag based on your requirement. Here is the approach which I have followed.

Steps

  1. Add the below-given content in build.sbt file. Here if the branch is master then I am using the semantic versioning like: 1.0.1 but if the branch name is other than master then I am using the custom tag(branch-name + git-commitid + timestamp).
import scala.sys.process.Process

lazy val root = (project in file(".")).enablePlugins(JavaAppPackaging)

name := "your-project-name"
scalaVersion := "2.12.11"

val branch = Process("git rev-parse --abbrev-ref HEAD").lineStream.head
version := {
  branch match {
    case "master" => (version in ThisBuild).value
    case _ => {
      val commit = Process("git rev-parse HEAD").lineStream.head
      val time = Process("git log -1 --format=%ct").lineStream.head
      branch +"-"+ commit +"-"+ time
    }
  }
}
  1. Create a version.sbt file in your project's root directory and add version in ThisBuild := "1.0.1-SNAPSHOT".
  2. Finally you can use sbt-release or any other plugins to release/publish the artifacts in the repository.
Keshav Lodhi
  • 2,641
  • 2
  • 17
  • 23