From 44b651d6079c98001d234d80b0a90e3bd8502b69 Mon Sep 17 00:00:00 2001 From: Josh Suereth Date: Wed, 4 Sep 2013 11:50:58 -0400 Subject: [PATCH 1/2] Modify publishing to send packages into bintray. * Use rpm repository for rpms * Use debian repository for debians * Use generic repository for everything else. Note: we still need to mark a release as public afterwards with an API call. Need to figure that one out for automation. --- build.sbt | 14 ++------------ project/build.properties | 2 +- project/packaging.scala | 37 +++++++++++++++++++++++++++++++++++-- 3 files changed, 38 insertions(+), 15 deletions(-) diff --git a/build.sbt b/build.sbt index 2b89cd7be..9b16c9b80 100644 --- a/build.sbt +++ b/build.sbt @@ -1,18 +1,8 @@ -sbtPlugin := true - -name := "sbt-launcher-package" - organization := "org.scala-sbt" +name := "sbt-launcher-packaging" + version := "0.1.0" crossTarget <<= target -publishTo in Global := { - val nativeReleaseUrl = "http://scalasbt.artifactoryonline.com/scalasbt/sbt-native-packages" - val nativeReleasePattern = "[organization]/[module]/[revision]/[module].[ext]" - val resolver = Resolver.url("native-releases", new URL(nativeReleaseUrl))(Patterns(nativeReleasePattern)) -// Resolver.file("native-releases-local", file("/home/jsuereth/repos/native-packages"))(Patterns(nativeReleasePattern)) - Some(resolver) -} - diff --git a/project/build.properties b/project/build.properties index 1ced03cad..5e96e9672 100644 --- a/project/build.properties +++ b/project/build.properties @@ -1 +1 @@ -sbt.version=0.12.4-RC1 +sbt.version=0.12.4 diff --git a/project/packaging.scala b/project/packaging.scala index 6fdb8e7ab..c75922d56 100644 --- a/project/packaging.scala +++ b/project/packaging.scala @@ -12,7 +12,15 @@ object Packaging { val stagingDirectory = SettingKey[File]("staging-directory") val stage = TaskKey[File]("stage") - def localWindowsPattern = "[organisation]/[module]/[revision]/[module].[ext]" + val bintrayLinuxPattern = "[module]/[revision]/[module]-[revision].[ext]" + val bintrayGenericPattern = "[module]/[revision]/[module]/[revision]/[module]-[revision].[ext]" + val bintrayDebianUrl = "https://api.bintray.com/content/sbt/debian/" + val bintrayRpmUrl = "https://api.bintray.com/content/sbt/rpm/" + val bintrayGenericPackagesUrl = "https://api.bintray.com/content/sbt/native-packages/" + + // Note: The legacy api. + //val genericNativeReleasesUrl = "http://scalasbt.artifactoryonline.com/scalasbt/sbt-native-packages" + //val genericNativeReleasesPattern = "[organisation]/[module]/[revision]/[module].[ext]" import util.control.Exception.catching @@ -22,8 +30,33 @@ object Packaging { case Array(0, y, _*) if y >= 12 => "http://repo.typesafe.com/typesafe/ivy-releases/org.scala-sbt/sbt-launch/"+v+"/sbt-launch.jar" case _ => "http://repo.typesafe.com/typesafe/ivy-releases/org.scala-tools.sbt/sbt-launch/"+v+"/sbt-launch.jar" } + /** Returns an id, url and pattern for publishing based on the given configuration. */ + def getPublishSettings(config: Configuration): (String, String, String) = + config.name match { + case Debian.name => ("bintray-debian", bintrayDebianUrl, bintrayLinuxPattern) + case Rpm.name => ("bintray-rpm", bintrayRpmUrl, bintrayLinuxPattern) + case _ => ("generic-native-packages-" + config.name, bintrayGenericPackagesUrl, bintrayGenericPattern) + } + + def makePublishTo(id: String, url: String, pattern: String): Setting[_] = { + publishTo := { + val resolver = Resolver.url(id, new URL(url))(Patterns(pattern)) + Some(resolver) + } + } + + def makePublishToForConfig(config: Configuration) = { + val (id, url, pattern) = getPublishSettings(config) + // Add the publish to and ensure global resolvers has the resolver we just configured. + inConfig(config)(Seq(makePublishTo(id, url, pattern))) ++ + Seq(resolvers <++= (publishTo in config) apply (_.toSeq)) + } - val settings: Seq[Setting[_]] = packagerSettings ++ deploymentSettings ++ mapGenericFilesToLinux ++ mapGenericFilesToWinows ++ Seq( + def publishToSettings: Seq[Setting[_]] = + Seq[Configuration](Debian, Universal, Windows, Rpm) flatMap makePublishToForConfig + + + val settings: Seq[Setting[_]] = packagerSettings ++ deploymentSettings ++ mapGenericFilesToLinux ++ mapGenericFilesToWinows ++ publishToSettings ++ Seq( sbtLaunchJarUrl <<= sbtVersion apply downloadUrlForVersion, sbtLaunchJarLocation <<= target apply (_ / "sbt-launch.jar"), sbtLaunchJar <<= (sbtLaunchJarUrl, sbtLaunchJarLocation) map { (uri, file) => From f51c51edbee5640ef030b4e0d75fdec98148fc47 Mon Sep 17 00:00:00 2001 From: Josh Suereth Date: Mon, 6 Jan 2014 10:41:23 -0500 Subject: [PATCH 2/2] Fix publishing to bintray to automatically make artifacts available after succesful upload. --- project/packaging.scala | 50 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 45 insertions(+), 5 deletions(-) diff --git a/project/packaging.scala b/project/packaging.scala index a2fa44648..a86d06446 100644 --- a/project/packaging.scala +++ b/project/packaging.scala @@ -15,6 +15,7 @@ object Packaging { val bintrayDebianUrl = "https://api.bintray.com/content/sbt/debian/" val bintrayRpmUrl = "https://api.bintray.com/content/sbt/rpm/" val bintrayGenericPackagesUrl = "https://api.bintray.com/content/sbt/native-packages/" + val bintrayPublishAllStaged = TaskKey[Unit]("bintray-publish-all-staged", "Publish all staged artifacts on bintray.") // Note: The legacy api. //val genericNativeReleasesUrl = "http://scalasbt.artifactoryonline.com/scalasbt/sbt-native-packages" @@ -31,9 +32,9 @@ object Packaging { /** Returns an id, url and pattern for publishing based on the given configuration. */ def getPublishSettings(config: Configuration): (String, String, String) = config.name match { - case Debian.name => ("bintray-debian", bintrayDebianUrl, bintrayLinuxPattern) - case Rpm.name => ("bintray-rpm", bintrayRpmUrl, bintrayLinuxPattern) - case _ => ("generic-native-packages-" + config.name, bintrayGenericPackagesUrl, bintrayGenericPattern) + case Debian.name => ("debian", bintrayDebianUrl, bintrayLinuxPattern) + case Rpm.name => ("rpm", bintrayRpmUrl, bintrayLinuxPattern) + case _ => ("native-packages", bintrayGenericPackagesUrl, bintrayGenericPattern) } def makePublishTo(id: String, url: String, pattern: String): Setting[_] = { @@ -45,14 +46,52 @@ object Packaging { def makePublishToForConfig(config: Configuration) = { val (id, url, pattern) = getPublishSettings(config) + + // Add the publish to and ensure global resolvers has the resolver we just configured. - inConfig(config)(Seq(makePublishTo(id, url, pattern))) ++ - Seq(resolvers <++= (publishTo in config) apply (_.toSeq)) + inConfig(config)(Seq( + makePublishTo(id, url, pattern), + bintrayPublishAllStaged <<= (credentials, version) map { (creds, version) => + publishContent(id, version, creds) + }, + // TODO - This is a little funky... + publish <<= (publish, credentials, version) apply { (publish, creds, version) => + for { + pub <- publish + creds <- creds + } yield publishContent(id, version, creds) + } + )) ++ Seq( + resolvers <++= (publishTo in config) apply (_.toSeq) + ) } def publishToSettings: Seq[Setting[_]] = Seq[Configuration](Debian, Universal, Windows, Rpm) flatMap makePublishToForConfig + def bintrayCreds(creds: Seq[sbt.Credentials]): (String, String) = { + val matching = + for { + c <- creds + if c.isInstanceOf[sbt.DirectCredentials] + val cred = c.asInstanceOf[sbt.DirectCredentials] + if cred.host == "api.bintray.com" + } yield cred.userName -> cred.passwd + + matching.headOption getOrElse sys.error("Unable to find bintray credentials (api.bintray.com)") + } + + def publishContent(repo: String, version: String, creds: Seq[sbt.Credentials]): Unit = { + val subject = "sbt" // Sbt org + val pkg = "sbt" // Sbt package + val uri = s"https://bintray.com/api/v1/content/$subject/$repo/$pkg/$version/publish" + + val (u,p) = bintrayCreds(creds) + import dispatch.classic._ + // TODO - Log the output + Http(url(uri).POST.as(u,p).>|) + } + val settings: Seq[Setting[_]] = packagerSettings ++ deploymentSettings ++ mapGenericFilesToLinux ++ mapGenericFilesToWindows ++ publishToSettings ++ Seq( sbtLaunchJarUrl <<= sbtVersion apply downloadUrlForVersion, @@ -123,6 +162,7 @@ object Packaging { // Universal ZIP download install. name in Universal := "sbt", + version in Universal <<= sbtVersion, mappings in Universal <+= sbtLaunchJar map { _ -> "bin/sbt-launch.jar" }, // Misccelaneous publishing stuff...