Specify a custom git tag with sbt-release

2.2k Views Asked by At

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.

2

There are 2 best solutions below

0
On BEST ANSWER

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.

0
On

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.