Skip to content

Instantly share code, notes, and snippets.

@Slakah
Created July 11, 2018 14:41
Show Gist options
  • Save Slakah/9aed1502a132b23f52b5dc54ef31d8a5 to your computer and use it in GitHub Desktop.
Save Slakah/9aed1502a132b23f52b5dc54ef31d8a5 to your computer and use it in GitHub Desktop.
Bump a git tag using by specifying major, minor, patch. This will also output the commits since the last tag.
#!/usr/bin/env amm
import ammonite.ops._, ImplicitWd._
case class Version(major: Int, minor: Int, patch: Int, label: String) {
def tag = s"v$major.$minor.$patch$label"
}
def parseVersion(s: String) = {
val VersionPattern = "^v(\\d+).(\\d+).(\\d+)(-.+)?$".r
val VersionPattern(major, minor, patch, labelNullable) = s
val label = Option(labelNullable).getOrElse("")
Version(major.toInt, minor.toInt, patch.toInt, label)
}
@main
def main(bumpType: String) = {
%('git, "pull", "--tags")
val currTag = %%('git, "describe", "--abbrev=0", "--tags").out.trim
val currVersion = parseVersion(currTag)
val newVersion = bumpType.toLowerCase.trim match {
case "major" => currVersion.copy(major = currVersion.major + 1)
case "minor" => currVersion.copy(minor = currVersion.minor + 1)
case "patch" => currVersion.copy(patch = currVersion.patch + 1)
}
val newTag = newVersion.tag
%('git, "commit", "--allow-empty", "-m", s"$newTag (jenkins trigger)")
%('git, "tag", "-a", newTag, "-m", newTag)
println("commits since last tag:")
val commitSummary = %%('git, "log", "--pretty=oneline", "--pretty=format:%s", s"$newTag...$currTag").out.trim
println(commitSummary.split("\n").mkString("* ", "\n* ", ""))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment