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

Add setting/ability to use basic snapshot versioning with the hash. #277

Open
mdedetrich opened this issue Oct 23, 2023 · 0 comments
Open

Comments

@mdedetrich
Copy link
Contributor

mdedetrich commented Oct 23, 2023

In both sbt-osgi and sbt-github-actions we have the following code

// So that publishLocal doesn't continuously create new versions
def versionFmt(out: sbtdynver.GitDescribeOutput): String = {
  val snapshotSuffix = if
    (out.isSnapshot()) "-SNAPSHOT"
  else ""
  out.ref.dropPrefix + snapshotSuffix
}

def fallbackVersion(d: java.util.Date): String = s"HEAD-${sbtdynver.DynVer timestamp d}"

ThisBuild / version := dynverGitDescribeOutput.value.mkVersion(versionFmt, fallbackVersion(dynverCurrentDate.value))
ThisBuild / dynver := {
  val d = new java.util.Date
  sbtdynver.DynVer.getGitDescribeOutput(d).mkVersion(versionFmt, fallbackVersion(d))
}

The code basically means that you get basic snapshots (i.e. v1.0.0-SNAPSHOT) without any hashing/commit'ids/etc etc. The reason why this is useful is specifically for SBT plugins that have scripted tests which require local publishing (see discussion at sbt/sbt-osgi#88 (review)). Without this change, every single invocation of a scripted test that slightly changes the contents to make the state dirty ends up creating a new publishLocal which can quickly fill up local cache (and this is standard flow for working on sbt plugins).

One question is how this should be implemented, i.e. should we just add versionFmt/fallbackVersion as constants into sbt-dynver so that end users can just go

ThisBuild / version := dynverGitDescribeOutput.value.mkVersion(versionFmt, fallbackVersion(dynverCurrentDate.value))
ThisBuild / dynver := {
  val d = new java.util.Date
  sbtdynver.DynVer.getGitDescribeOutput(d).mkVersion(versionFmt, fallbackVersion(d))
}

Or should we instead do something more comprehensive, i.e. some ADT that has predefined "patterns"

sealed abstract trait VersionPattern

object VersionPattern {
  case object Default extends VersionPattern // current implementation
  case object Simple extends VersionPattern // whats being suggested in this PR
  final case class Custom(versionFmt: sbtdynver.GitDescribeOutput => String, fallbackVersion: java.util.Date => String)
}
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

1 participant