diff options
-rw-r--r-- | project/Publish.scala | 40 | ||||
-rw-r--r-- | project/Release.scala | 65 | ||||
-rw-r--r-- | project/Settings.scala | 2 | ||||
-rw-r--r-- | project/VersionWithSHA.scala | 13 | ||||
-rw-r--r-- | project/plugins.sbt | 3 | ||||
-rw-r--r-- | versionwithsha.sbt | 5 |
6 files changed, 92 insertions, 36 deletions
diff --git a/project/Publish.scala b/project/Publish.scala index 818324c3..5df73228 100644 --- a/project/Publish.scala +++ b/project/Publish.scala @@ -1,52 +1,22 @@ import sbt._ import sbt.Keys._ -import sbt.Project.Initialize -import java.lang.Boolean.{valueOf => convertToBoolean } object Publish { lazy val settings = Seq( crossPaths := false, pomExtra := kamonPomExtra, - publishTo <<= kamonPublish, - organization := kamonOrganization, - credentials ++= kamonCredentials, + publishTo := kamonRepo, + organization := "io.kamon", pomIncludeRepository := { x => false }, publishMavenStyle := true, publishArtifact in Test := false ) - def kamonPublish:Initialize[Option[Resolver]] = { - if(convertToBoolean(System.getProperty("publish.to.sonatype"))) sonatypePublishRepository - else kamonPublishRepository - } - - def sonatypePublishRepository: Initialize[Option[Resolver]] = { - version { v: String => - val nexus = "https://oss.sonatype.org/" - if (v.trim.endsWith("SNAPSHOT")) - Some("snapshots" at nexus + "content/repositories/snapshots") - else - Some("releases" at nexus + "service/local/staging/deploy/maven2") - } - } - - def kamonPublishRepository :Initialize[Option[Resolver]] = { - version { (v: String) => - if (v.trim.endsWith("SNAPSHOT")) - Some(Resolver.sftp("Kamon Snapshots Repository", "snapshots.kamon.io", "/var/local/snapshots-repo")) - else - Some(Resolver.sftp("Kamon Repository", "repo.kamon.io", "/var/local/releases-repo")) - } - } - - def kamonOrganization: String = Option(System.getProperty("kamon.publish.organization", "kamon")).get - - def kamonCredentials: Seq[Credentials] = - Option(System.getProperty("kamon.publish.credentials", null)) map (f => Credentials(new File(f))) toSeq + def kamonRepo = Some(Resolver.sftp("Kamon Snapshots Repository", "snapshots.kamon.io", "/var/local/snapshots-repo")) def kamonPomExtra = { - <url>http://kamon.io</url> + <url>http://kamon.io</url> <licenses> <license> <name>Apache 2</name> @@ -62,4 +32,4 @@ object Publish { <developer><id>dpsoft</id><name>Diego Parra</name><url>https://twitter.com/diegolparra</url></developer> </developers> } -}
\ No newline at end of file +} diff --git a/project/Release.scala b/project/Release.scala new file mode 100644 index 00000000..8b7ecf30 --- /dev/null +++ b/project/Release.scala @@ -0,0 +1,65 @@ +import com.typesafe.sbt.pgp._ +import sbt._ +import sbt.Keys._ +import sbtrelease.ReleasePlugin._ +import sbtrelease.ReleaseStateTransformations._ +import sbtrelease.ReleaseStep +import sbtrelease.Utilities._ +import xerial.sbt.Sonatype._ + +object Release { + + def settings = Seq.empty ++ + releaseSettings ++ + Seq( + ReleaseKeys.releaseProcess := Seq[ReleaseStep]( + checkSnapshotDependencies, + inquireVersions, + runClean, + runTest, + setReleaseVersion, + commitReleaseVersion, // .copy(check = identity), // FIX 0: to skip "all changes committed" precondition + tagRelease, + publishSignedArtifacts, // FIX 1: publish signed. Otherwise sonatype won't sync artifact to maven central + setNextVersion, + commitNextVersion, + pushChanges, + refreshVersionWithSHA // FIX 2: update "version" by replacing the "-SNAPSHOT" with "-WHATEVER_COMMIT_SHA" + ) + ) ++ + sonatypeSettings ++ + Seq( + // sbt-sonatype overrides publishTo. So we need to restore kamon repo declaration for snapshots + publishTo := { if (isSnapshot.value) Publish.kamonRepo else publishTo.value } + ) + + + def kamonSonatypeCredentials = + Credentials.toDirect(Credentials(Path.userHome / ".ivy2" / "kamon-credentials-sonatype.properties")) + + /** + * Hijacked from [[sbtrelease.ReleaseStateTransformations.publishArtifacts]] + */ + lazy val publishSignedArtifacts = ReleaseStep( + action = { st: State => + val extracted = st.extract + val ref = extracted.get(thisProjectRef) + extracted.runAggregated(PgpKeys.publishSigned in Global in ref, st) + }, + check = st => { + // getPublishTo fails if no publish repository is set up. + val ex = st.extract + val ref = ex.get(thisProjectRef) + Classpaths.getPublishTo(ex.get(publishTo in Global in ref)) + st + }, + enableCrossBuild = true + ) + + lazy val refreshVersionWithSHA = ReleaseStep(st => { + reapply(Seq( + version in ThisBuild := VersionWithSHA.kamonVersionWithSHA(st.extract.get(version)) + ), st) + }) + +}
\ No newline at end of file diff --git a/project/Settings.scala b/project/Settings.scala index 9b6c917d..9abd5553 100644 --- a/project/Settings.scala +++ b/project/Settings.scala @@ -1,9 +1,9 @@ import sbt._ import Keys._ -import sbtrelease.ReleasePlugin._ import com.typesafe.sbt.SbtScalariform import com.typesafe.sbt.SbtScalariform.ScalariformKeys import Publish.{settings => publishSettings} +import Release.{settings => releaseSettings} import scalariform.formatter.preferences._ object Settings { diff --git a/project/VersionWithSHA.scala b/project/VersionWithSHA.scala new file mode 100644 index 00000000..4479b88f --- /dev/null +++ b/project/VersionWithSHA.scala @@ -0,0 +1,13 @@ +import sbt.Process + +object VersionWithSHA { + + private lazy val VersionWithShaRegex = """(?:\d+\.)?(?:\d+\.)?(?:\d+)-[0-9a-f]{5,40}""" + + /** Don't use this. You should use version.value instead. */ + def kamonVersionWithSHA(version: String) = version.takeWhile(_ != '-') + "-" + Process("git rev-parse HEAD").lines.head + + /** Don't use this. You should use isSnapshot.value instead. */ + def kamonIsSnapshot(version: String) = (version matches VersionWithShaRegex) || (version endsWith "-SNAPSHOT") + +}
\ No newline at end of file diff --git a/project/plugins.sbt b/project/plugins.sbt index 0e71f446..0d5801c1 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -10,3 +10,6 @@ addSbtPlugin("com.github.gseitz" % "sbt-release" % "0.8.2") addSbtPlugin("com.typesafe.sbt" % "sbt-scalariform" % "1.3.0") +addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "0.2.1") + +addSbtPlugin("com.typesafe.sbt" % "sbt-pgp" % "0.8.1")
\ No newline at end of file diff --git a/versionwithsha.sbt b/versionwithsha.sbt new file mode 100644 index 00000000..288e7948 --- /dev/null +++ b/versionwithsha.sbt @@ -0,0 +1,5 @@ +// This file has a sensitive filename. It MUST be loaded after version.sbt, so it can rely in sbt-release version + +version in ThisBuild := VersionWithSHA.kamonVersionWithSHA((version in ThisBuild).value) + +isSnapshot in ThisBuild := VersionWithSHA.kamonIsSnapshot((version in ThisBuild).value)
\ No newline at end of file |