From 5790001bc13401a12a32dbb3012c49a647cc541a Mon Sep 17 00:00:00 2001 From: vlad Date: Thu, 21 Jul 2016 21:32:49 -0400 Subject: Plugins configuration for releases --- project/DriverConfigurations.scala | 105 +++++++++++++++++++++++++++++++++++++ project/plugins.sbt | 4 ++ 2 files changed, 109 insertions(+) create mode 100644 project/DriverConfigurations.scala (limited to 'project') diff --git a/project/DriverConfigurations.scala b/project/DriverConfigurations.scala new file mode 100644 index 0000000..097279a --- /dev/null +++ b/project/DriverConfigurations.scala @@ -0,0 +1,105 @@ +import org.scalafmt.sbt.ScalaFmtPlugin.autoImport._ +import sbt.Keys._ +import sbt._ +import wartremover.WartRemover.autoImport._ +import com.typesafe.sbt.SbtGit.git +import com.typesafe.sbt.{GitBranchPrompt, GitVersioning} +import org.scalafmt.sbt.ScalaFmtPlugin.autoImport._ +import sbtrelease.{Version, _} +// we hide the existing definition for setReleaseVersion to replace it with our own +import sbtrelease.ReleasePlugin.autoImport.ReleaseTransformations._ +import sbtrelease.ReleasePlugin.autoImport._ +import sbtrelease.ReleaseStateTransformations.{setReleaseVersion => _} + + +object DriverConfigurations { + + lazy val wartRemoverSettings = Seq( + wartremoverErrors in (Compile, compile) ++= Warts.allBut( + Wart.AsInstanceOf, Wart.Nothing, Wart.Overloading, Wart.DefaultArguments, Wart.Any, + Wart.Option2Iterable, Wart.ExplicitImplicitTypes, Wart.Throw, Wart.ToString) + ) + + lazy val acyclicSettings = Seq( + autoCompilerPlugins := true, + addCompilerPlugin("com.lihaoyi" %% "acyclic" % "0.1.4") + ) + + lazy val scalafmtSettings = Seq( + scalafmtConfig in ThisBuild := Some(file(".scalafmt")), + testExecution in (Test, test) <<= + (testExecution in (Test, test)) dependsOn (scalafmtTest in Compile, scalafmtTest in Test) + ) + + lazy val compileScalastyle = taskKey[Unit]("compileScalastyle") + + def publicationSettings() = Seq( + publishTo := Some(Resolver.file("file", new File("releases"))) + // publishTo := { // TODO: For actual Driver jar repo + // val nexus = "https://my.artifact.repo.net/" + // if (isSnapshot.value) + // Some("snapshots" at nexus + "content/repositories/snapshots") + // else + // Some("releases" at nexus + "service/local/staging/deploy/maven2") + // } + ) + + def releaseSettings() = { + def setVersionOnly(selectVersion: Versions => String): ReleaseStep = { st: State => + val vs = st.get(ReleaseKeys.versions).getOrElse( + sys.error("No versions are set! Was this release part executed before inquireVersions?")) + val selected = selectVersion(vs) + + st.log.info("Setting version to '%s'." format selected) + val useGlobal = Project.extract(st).get(releaseUseGlobalVersion) + + reapply(Seq( + if (useGlobal) version in ThisBuild := selected else version := selected + ), st) + } + + lazy val setReleaseVersion: ReleaseStep = setVersionOnly(_._1) + + Seq( + releaseIgnoreUntrackedFiles := true, + // Check http://blog.byjean.eu/2015/07/10/painless-release-with-sbt.html for details + releaseVersionBump := sbtrelease.Version.Bump.Minor, + releaseVersion <<= releaseVersionBump(bumper => { + ver => Version(ver) + .map(_.withoutQualifier) + .map(_.bump(bumper).string).getOrElse(versionFormatError) + }), + releaseProcess := Seq[ReleaseStep]( + checkSnapshotDependencies, + inquireVersions, + runTest, // probably, runTest after setReleaseVersion, if tests depend on version + setReleaseVersion, + commitReleaseVersion, // performs the initial git checks + tagRelease, + publishArtifacts, + setNextVersion, + commitNextVersion, + pushChanges // also checks that an upstream branch is properly configured + ) + ) + } + + implicit class driverConfigurations(project: Project) { + + def gitPluginConfiguration: Project = { + val VersionRegex = "v([0-9]+.[0-9]+.[0-9]+)-?(.*)?".r + + project + .enablePlugins(GitVersioning, GitBranchPrompt) + .settings( + git.useGitDescribe := true, + git.baseVersion := "0.0.0", + git.gitTagToVersionNumber := { + case VersionRegex(v, "SNAPSHOT") => Some(s"$v-SNAPSHOT") + case VersionRegex(v, "") => Some(v) + case VersionRegex(v, s) => Some(s"$v-$s-SNAPSHOT") + case _ => None + }) + } + } +} \ No newline at end of file diff --git a/project/plugins.sbt b/project/plugins.sbt index ee760ea..a3a7fb7 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -3,5 +3,9 @@ addSbtPlugin("com.geirsson" % "sbt-scalafmt" % "0.2.10") addSbtPlugin("org.wartremover" % "sbt-wartremover" % "1.0.1") addSbtPlugin("org.scalastyle" %% "scalastyle-sbt-plugin" % "0.8.0") +// Launch and deploy/release plugins +addSbtPlugin("com.typesafe.sbt" % "sbt-git" % "0.8.5") +addSbtPlugin("com.github.gseitz" % "sbt-release" % "1.0.3") + // This plugin represents functionality that is to be added to sbt in the future addSbtPlugin("org.scala-sbt" % "sbt-core-next" % "0.1.1") \ No newline at end of file -- cgit v1.2.3