Skip to content

Commit

Permalink
Merge pull request scalamacros#77 from olafurpg/bintray
Browse files Browse the repository at this point in the history
Publish to bintray on merge
  • Loading branch information
olafurpg authored Oct 14, 2016
2 parents 5cd2647 + 4a4964d commit e8a9069
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 17 deletions.
1 change: 1 addition & 0 deletions .drone.sec
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
eyJhbGciOiJSU0EtT0FFUCIsImVuYyI6IkExMjhHQ00ifQ.oppx3cSUjhzo5xCsV3FPEZd5Q6lhpDUnpx61GUsiuImgfC5zTd-emiJX8vV9vBHMKe_iiiCVPIGOpvqp6TIxZ7q92T28eEJGn6D1r1mwlXFpR21SV9OkUqDqtNWQMbYZKKd3fiFlrKa1_EB-8ivS3kIOUlryeAVHQfKE28s1YGkCq7hEeSfIAE9NW3Imu5hL29V4RU8PRMr_j2Nc_Fu86kGgZ7nEUfxDpqsn-mrSnTlALDARu709WTeZ3qgLl51LoXCnCcgjvsNh88UI_3BQtAJQg5OQN6Fu6tdCDCYB6_fB4R2eRRsAewUt_oHKskcwz-Es80uRJO3reNRcg_wnMg.ioaBTHD5-_-EKtSs.D_kiy4tzK6QsJRQi4z5xEY131o5cwXTOjwGcm6uRc8nDu8SU3s7h5GA0NwkG-35qExaSq7R_FwyfT5E8Qpdau0vHf359YJA6PcaUcC6mml6LGgldCiwurX50oAqZmwZyglHRqu3o6-X2gW8Kr856berPmco1hPNfA4AJ9N-_MS61urFY02ejuguxLW-k6IoHJfTlm3PLcdkvHpcLMh6D6pFZnBVbTzTqnA7Xhtf6PqsS.IqA2b51Hdgr-2wCrGsEFBA
18 changes: 14 additions & 4 deletions .drone.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
build:
image: olafurpg/scalafix:0.0.1
commands:
- ./bin/scalafmt --version 0.4.5 --test
- sbt clean test
tests:
image: olafurpg/scalafix:0.0.1
commands:
- ./bin/scalafmt --version 0.4.5 --test
- sbt clean test
publish:
image: olafurpg/scalafix:0.0.1
environment:
- BINTRAY_USERNAME=$$BINTRAY_USERNAME
- BINTRAY_API_KEY=$$BINTRAY_API_KEY
commands:
- ./bin/bintray.sh
when:
branch: [master, 4.x]
cache:
mount:
- $HOME/.scalafmt-bin
Expand Down
15 changes: 15 additions & 0 deletions bin/bintray.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env bash

if [[ "$CI_BRANCH" == "master" || "$CI_BRANCH" == "4.x" ]]; then
PUBLISH=publish
mkdir -p ~/.bintray
cat > ~/.bintray/.credentials <<EOF
realm = Bintray API Realm
host = api.bintray.com
user = $BINTRAY_USERNAME
password = $BINTRAY_API_KEY
EOF
sbt ++$SCALA_VERSION "$PUBLISH"
fi


57 changes: 44 additions & 13 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
lazy val ScalaVersions = Seq("2.11.8")
lazy val MetaOrg = "org.scalameta"
lazy val MetaVersion = "1.2.0"
import scala.util.Try

lazy val ScalaVersions = Seq("2.11.8")
lazy val MetaOrg = "org.scalameta"
lazy val MetaVersion = "1.2.0"
lazy val LibraryVersion = "3.0.0-SNAPSHOT"
lazy val isSnapshot = LibraryVersion.endsWith("SNAPSHOT")
lazy val PRVersion = latestPullRequestVersion()

// ==========================================
// Settings
Expand All @@ -11,11 +16,11 @@ lazy val sharedSettings: Seq[Def.Setting[_]] =
Seq(
scalaVersion := ScalaVersions.head,
crossVersion := CrossVersion.full,
version := "3.0.0-SNAPSHOT",
version := PRVersion.getOrElse(LibraryVersion),
organization := "org.scalameta",
description := "Empowers production Scala compiler with latest macro developments",
resolvers += Resolver.sonatypeRepo("releases"),
publishMavenStyle := true,
publishMavenStyle := !isSnapshot,
publishArtifact := false,
scalacOptions ++= Seq("-deprecation", "-feature", "-unchecked"),
logBuffered := false,
Expand Down Expand Up @@ -154,18 +159,21 @@ lazy val plugin = Project(id = "paradise", base = file("plugin"))
IO.copy(List(fatJar -> slimJar), overwrite = true)
(art, slimJar)
},
publishMavenStyle := true,
publishMavenStyle := !isSnapshot,
publishArtifact in Compile := true,
publishTo <<= version { v: String =>
publishTo := {
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")
println("PRVERSION: " + PRVersion)
if (PRVersion.isDefined) (publishTo in bintray).value
else if (isSnapshot) Some("snapshots" at nexus + "content/repositories/snapshots")
else Some("releases" at nexus + "service/local/staging/deploy/maven2")
},
pomIncludeRepository := { x =>
false
},
bintrayOrganization := Some("scalameta"),
licenses +=
"BSD" -> url("https://github.com/scalameta/paradise/blob/master/LICENSE.md"),
pomExtra := (
<url>https://github.com/scalameta/paradise</url>
<inceptionYear>2012</inceptionYear>
Expand All @@ -191,8 +199,8 @@ lazy val plugin = Project(id = "paradise", base = file("plugin"))
<url>http://xeno.by</url>
</developer>
</developers>
),
credentials ++= loadCredentials()
)
// , credentials ++= loadCredentials()
)

lazy val testsCommon = project
Expand Down Expand Up @@ -233,3 +241,26 @@ lazy val testsConverter = project
exposePaths("testsConverter", Test)
)
.dependsOn(testsCommon, plugin)

def parsePullRequestFromCommitMessage: Option[String] = {
import sys.process._
val PullRequest = "\\s+Merge pull request #(\\d+).*".r
for {
commitMsg <- Try(Seq("git", "log", "-1").!!.trim).toOption
pr <- augmentString(commitMsg).lines.collectFirst {
case PullRequest(pr) => pr
}
} yield pr
}

/** Replaces -SNAPSHOT with latest pull request number, if it exists.j */
def latestPullRequestVersion(): Option[String] = {
for {
_ <- sys.env.get("BINTRAY_API_KEY")
if isSnapshot
if !sys.env.contains("CI_PULL_REQUEST")
pullRequest <- parsePullRequestFromCommitMessage
} yield {
LibraryVersion.replace("-SNAPSHOT", s".$pullRequest")
}
}
2 changes: 2 additions & 0 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
addSbtPlugin("me.lessis" % "bintray-sbt" % "0.3.0")

addSbtPlugin("io.get-coursier" % "sbt-coursier" % "1.0.0-M14")

addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.0.0")
Expand Down

0 comments on commit e8a9069

Please sign in to comment.