Skip to content

Commit

Permalink
Initial support for handling build matrices
Browse files Browse the repository at this point in the history
I'm sure there are lots of semantics I'm not considering with, for
example:

* folding build matrix includes with root scala versions
* matrix excludes?
* etc

But for now this solves the build matrix I created in scala/scala-abide.

Fixes #2
  • Loading branch information
dwijnand committed Nov 20, 2016
1 parent 62a67c8 commit 97a3b96
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 14 deletions.
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ Other than that, as `sbt-travisci` is an AutoPlugin that is all that is required

`crossScalaVersions in ThisBuild` will be automatically set to the scala versions in `.travis.yml`.

**NOTE**: It currently doesn't support build matrices ([#2][]).

[#2]: https://github.com/dwijnand/sbt-travisci/issues/2

## Dependencies

Depends on the presence of a `.travis.yml` file at the root of the project.
Expand Down
4 changes: 0 additions & 4 deletions notes/1.0.0.markdown
Original file line number Diff line number Diff line change
@@ -1,6 +1,2 @@
- Initial implementation.
- `crossScalaVersions in ThisBuild` will be automatically set to the scala versions in `.travis.yml`.

**NOTE**: It currently doesn't support build matrices ([#2][]).

[#2]: https://github.com/dwijnand/sbt-travisci/issues/2
24 changes: 18 additions & 6 deletions src/main/scala/sbttravisci/TravisCiPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,28 @@ object TravisCiPlugin extends AutoPlugin {
// parses Scala versions out of .travis.yml (doesn't support build matrices)
crossScalaVersions := {
import scala.collection.JavaConverters._
Using.fileInputStream(baseDirectory.value / ".travis.yml")(fis =>
Option(new org.yaml.snakeyaml.Yaml().load(fis))
.collect { case map: java.util.Map[_, _] => Option(map get "scala") }
.flatten
Using.fileInputStream(baseDirectory.value / ".travis.yml") { fis =>
val yaml = Option(new org.yaml.snakeyaml.Yaml().load(fis))
.collect { case map: java.util.Map[_, _] => map }

def fromRoot = yaml
.flatMap(map => Option(map get "scala"))
.collect {
case versions: java.util.List[_] => versions.asScala.toList map (_.toString)
case version: String => version :: Nil
}
.getOrElse(List(scalaVersion.value))
)

def fromMatrixInclude = yaml
.flatMap(map => Option(map get "matrix"))
.collect { case map: java.util.Map[_, _] => Option(map get "include") }.flatten
.collect { case versions: java.util.List[_] =>
versions.asScala.toList.collect { case map: java.util.Map[_, _] =>
Option(map get "scala") map (_.toString)
}.flatten
}

fromMatrixInclude orElse fromRoot getOrElse List(scalaVersion.value)
}
}
)
}
9 changes: 9 additions & 0 deletions src/sbt-test/travisci/build-matrix/.travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
language: scala
matrix:
include:
- scala: 2.10.6
jdk: openjdk6
- scala: 2.11.8
jdk: openjdk6
- scala: 2.12.0
jdk: oraclejdk8
3 changes: 3 additions & 0 deletions src/sbt-test/travisci/build-matrix/build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
def check[A](inc: A, exp: A) = assert(inc == exp, s"Versions mismatch: Expected $exp, Incoming $inc")

TaskKey[Unit]("check") := check(crossScalaVersions.value, Seq("2.10.6", "2.11.8", "2.12.0"))
5 changes: 5 additions & 0 deletions src/sbt-test/travisci/build-matrix/project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
sys.props.get("plugin.version") match {
case Some(x) => addSbtPlugin("com.dwijnand" % "sbt-travisci" % x)
case _ => sys.error("""|The system property 'plugin.version' is not defined.
|Specify this property using the scriptedLaunchOpts -D.""".stripMargin)
}
1 change: 1 addition & 0 deletions src/sbt-test/travisci/build-matrix/test
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
> check

0 comments on commit 97a3b96

Please sign in to comment.