Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build only changed subprojects #419

Merged
merged 3 commits into from
Sep 18, 2017
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Build only changed subprojects
Inspired by https://github.com/akka/akka/blob/master/project/ValidatePullRequest.scala

Kept is a bit simpler for now, ignoring dependencies between projects
raboof committed Jul 19, 2017

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 0cdd8f18da6f0a7d627fac5d925277ed3bce4854
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -20,7 +20,7 @@ script:
# make 'git branch' work again
- git branch -f "$TRAVIS_BRANCH" && git checkout "$TRAVIS_BRANCH"
# check unformatted code
- git diff --exit-code --color || { echo "[error] Unformatted code found. Please run 'test:compile' and commit the reformatted code."; false; } && sbt -J-XX:ReservedCodeCacheSize=128m ++$TRAVIS_SCALA_VERSION ";test"
- git diff --exit-code --color || { echo "[error] Unformatted code found. Please run 'test:compile' and commit the reformatted code."; false; } && sbt -J-XX:ReservedCodeCacheSize=128m ++$TRAVIS_SCALA_VERSION ";testChanged"
# check policies, if on master also upload
- if [[ "$TRAVIS_BRANCH" == "master" && "$TRAVIS_EVENT_TYPE" == "push" ]]; then sbt 'set credentials += Credentials("whitesource", "whitesourcesoftware.com", "", System.getenv("WHITESOURCE_KEY"))' whitesourceCheckPolicies whitesourceUpdate; else sbt 'set credentials += Credentials("whitesource", "whitesourcesoftware.com", "", System.getenv("WHITESOURCE_KEY"))' whitesourceCheckPolicies; fi

2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
@@ -60,7 +60,7 @@ lazy val azureStorageQueue = project
.in(file("azure-storage-queue"))
.enablePlugins(AutomateHeaderPlugin)
.settings(
name := "akka-stream-azure-storage-queue",
name := "akka-stream-alpakka-azure-storage-queue",
Dependencies.AzureStorageQueue
)

51 changes: 51 additions & 0 deletions project/TestChanged.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package akka.stream.alpakka

import scala.collection.immutable

import sbt._
import sbt.Keys._

object TestChanged extends AutoPlugin {
override def trigger = allRequirements
override def requires = plugins.JvmPlugin

val changedDirectories = taskKey[immutable.Set[String]]("List of touched modules in this PR branch")
val testChanged = taskKey[Unit]("Test all subprojects with changes compared to master")

override lazy val buildSettings = Seq(
changedDirectories := {
val log = streams.value.log
val target = "master"

// TODO could use jgit
val diffOutput = s"git diff $target --name-only".!!.split("\n")
val changedDirectories =
diffOutput
.map(l => l.trim)
.map(l l.takeWhile(_ != '/'))
.map(new File(_))
.map(file => if (file.isDirectory) file.toString else "")
.toSet

log.info("Detected changes in directories: " + changedDirectories.mkString("[", ", ", "]"))
changedDirectories
}
)

override lazy val projectSettings = Seq(
testChanged := Def.taskDyn {
val skip = Def.setting { task() }
if (shouldBuild(name.value, changedDirectories.value)) test in Test
else skip
}.value
)

implicit class RegexHelper(val sc: StringContext) extends AnyVal {
def re: scala.util.matching.Regex = sc.parts.mkString.r
}

private def shouldBuild(projectName: String, changedDirectories: Set[String]) = projectName match {
case "alpakka" => false
case re"akka-stream-alpakka-(.+)$subproject" => changedDirectories.contains(subproject) || changedDirectories.contains("") || changedDirectories.contains("project")
}
}