Skip to content

Commit c0b0edd

Browse files
committed
Merge pull request #157 from sbt/bintray-releasing
Adding automation for releasing *and* directly release to bintray.
2 parents 11978c7 + 6705fc3 commit c0b0edd

File tree

4 files changed

+125
-1
lines changed

4 files changed

+125
-1
lines changed

build.sbt

+5-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ sbtVersion in Global := {
99

1010
scalaVersion in Global := "2.9.2"
1111

12+
crossScalaVersions := Seq("2.9.2", "2.10.2")
13+
1214
name := "sbt-native-packager"
1315

1416
organization := "com.typesafe.sbt"
@@ -30,14 +32,16 @@ ghpages.settings
3032

3133
git.remoteRepo := "[email protected]:sbt/sbt-native-packager.git"
3234

33-
publishTo := Some(Resolver.url("sbt-plugin-releases", new URL("http://scalasbt.artifactoryonline.com/scalasbt/sbt-plugin-releases/"))(Resolver.ivyStylePatterns))
35+
Bintray.settings
3436

3537
publishMavenStyle := false
3638

3739
scriptedSettings
3840

3941
scriptedLaunchOpts <+= version apply { v => "-Dproject.version="+v }
4042

43+
Release.settings
44+
4145

4246

4347

project/bintray.scala

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import sbt._
2+
import sbt.Keys._
3+
4+
object Bintray {
5+
val bintrayPublishAllStaged = TaskKey[Unit]("bintray-publish-all-staged", "Publish all staged artifacts on bintray.")
6+
val checkBintrayCredentials = TaskKey[Unit]("bintray-check-credentials", "Checks to see if bintray credentials are configured.")
7+
val bintrayPluginId = "sbt-plugin-releases"
8+
val bintrayPluginUrl = "https://api.bintray.com/content/sbt/sbt-plugin-releases/"
9+
val bintrayPluginLayout = "[module]/[revision]/"+ Resolver.localBasePattern
10+
11+
def bintrayCreds(creds: Seq[sbt.Credentials]): (String, String) = {
12+
val matching =
13+
for {
14+
c <- creds
15+
if c.isInstanceOf[sbt.DirectCredentials]
16+
val cred = c.asInstanceOf[sbt.DirectCredentials]
17+
if cred.host == "api.bintray.com"
18+
} yield cred.userName -> cred.passwd
19+
20+
matching.headOption getOrElse sys.error("Unable to find bintray credentials (api.bintray.com)")
21+
}
22+
23+
def publishContent(pkg: String, repo: String, version: String, creds: Seq[sbt.Credentials]): Unit = {
24+
val subject = "sbt" // Sbt org - TODO - don't hardcode
25+
val uri = s"https://bintray.com/api/v1/content/$subject/$repo/$pkg/$version/publish"
26+
27+
val (u,p) = bintrayCreds(creds)
28+
import dispatch.classic._
29+
// TODO - Log the output
30+
Http(url(uri).POST.as(u,p).>|)
31+
}
32+
33+
def settings: Seq[Setting[_]] =
34+
Seq(
35+
publishTo := {
36+
val resolver = Resolver.url("bintray-"+bintrayPluginId, new URL(bintrayPluginUrl))(Patterns(false, bintrayPluginLayout))
37+
Some(resolver)
38+
},
39+
checkBintrayCredentials := {
40+
val creds = credentials.value
41+
val (user, _) = bintrayCreds(creds)
42+
streams.value.log.info(s"Using $user for bintray login.")
43+
},
44+
bintrayPublishAllStaged := {
45+
val creds = credentials.value
46+
publishContent(projectID.value.name, bintrayPluginId, version.value, creds)
47+
}
48+
)
49+
}

project/plugins.sbt

+3
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,6 @@ libraryDependencies <+= (sbtVersion) { sv =>
1414

1515
// Scripted plugin needs to declare this as a dependency
1616
libraryDependencies += "jline" % "jline" % "2.11"
17+
18+
// For our bintray publishing
19+
libraryDependencies += "net.databinder" %% "dispatch-http" % "0.8.10"

project/release.scala

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import sbt._
2+
import Keys._
3+
4+
import complete.DefaultParsers._
5+
import complete.Parser
6+
7+
object Release {
8+
9+
val versionNumberParser: Parser[String] = {
10+
val classifier: Parser[String] = ("-" ~ ID) map {
11+
case (dash, id) => dash + id
12+
}
13+
val version: Parser[String] = (Digit ~ chars(".0123456789").* ~ classifier) map {
14+
case ((first, rest), rest2) => ((first +: rest).mkString + rest2)
15+
}
16+
val complete = (chars("v") ~ token(version, "<version number>")) map {
17+
case (v, num) => v + num
18+
}
19+
complete
20+
}
21+
22+
def releaseParser(state: State): Parser[String] =
23+
Space ~> versionNumberParser
24+
25+
26+
val releaseHelp = Help("release",
27+
"release <git tag>" -> "Runs the release script for a given version number",
28+
"""|release <git tag>
29+
|
30+
|Runs our release script. This will:
31+
|1. Run all the tests (unit + scripted) for the current OS.
32+
|2. Tag the git repo with the given tag (v<version>).
33+
|3. Reload the build with the new version number from the git tag.
34+
|4. publish all the artifacts to bintray.""".stripMargin
35+
)
36+
37+
def scriptedForPlatform: String = {
38+
// TODO - Implement. Instead of only running tests we can, we should
39+
// probably ping some service to see if all platform tests have
40+
// succeeded.
41+
"scripted universal/* debian/* rpm/*"
42+
}
43+
44+
def releaseAction(state: State, tag: String): State = {
45+
// TODO - Ensure we're releasing on JDK 6, so we're binary compatible.
46+
// First check to ensure we have a sane publishing environment...
47+
"bintrayCheckCredentials" ::
48+
"+ test" ::
49+
// Workaround for 0.12.4 scripted issue
50+
"set scalaVersion in Global := \"2.10.2\"" ::
51+
scriptedForPlatform ::
52+
// TODO - Signed tags, possibly using pgp keys?
53+
("git tag " + tag) ::
54+
"reload" ::
55+
// TODO - once we figure out bintray + pubishSigned, switch to signed
56+
// releases.
57+
"+ publishSigned" ::
58+
"bintrayPublishAllStaged" ::
59+
("git push origin " + tag) ::
60+
state
61+
}
62+
63+
val releaseCommand =
64+
Command("release", releaseHelp)(releaseParser)(releaseAction)
65+
66+
def settings: Seq[Setting[_]]=
67+
Seq(commands += releaseCommand)
68+
}

0 commit comments

Comments
 (0)