-
-
Save xuwei-k/c291164f930374799cb2e4dcc9107a2e to your computer and use it in GitHub Desktop.
並列、かつ指定したprojectだけdocker:publishする
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sbt.complete.DefaultParsers._ | |
import sbt.complete.Parser | |
val dockerPublish = taskKey[Unit]("ダミーのタスク。本来sbt-native-packagerのやつ") | |
val dockerPublishParallel = inputKey[Unit]("今回追加するtask") | |
lazy val commonSettings = Def.settings( | |
dockerPublish := { | |
import java.time.LocalTime | |
println(s"${LocalTime.now()} ${name.value} のpublish開始") | |
// 並列で実行されるのがわかりやすいように、途中sleepする | |
Thread.sleep(3000) | |
println(s"${LocalTime.now()} ${name.value} のpublish終了") | |
} | |
) | |
val allProjects = Seq[ProjectReference](a, b, c) | |
def distinctParser(exs: Set[String]): Parser[Seq[String]] = { | |
val base = token(Space) ~> token(NotSpace examples exs) | |
base.flatMap { ex => | |
val (_, notMatching) = exs.partition(GlobFilter(ex).accept) | |
distinctParser(notMatching).map { result => ex +: result } | |
} ?? Nil | |
} | |
dockerPublishParallel := InputTask.createDyn( | |
Def.setting{ (_: State) => | |
val projectIds = allProjects.collect{ case p: LocalProject => p.project }.toSet | |
distinctParser(projectIds) | |
} | |
){ | |
Def.task( | |
(projects: Seq[String]) => { | |
// TODO projects.isEmpty なら逆に全部publish実行、みたいにしておいてもいいかも? | |
projects.map { p => | |
dockerPublish in LocalProject(p) | |
}.join | |
} | |
) | |
}.evaluated | |
lazy val a = project | |
.settings( | |
commonSettings | |
) | |
lazy val b = project | |
.settings( | |
commonSettings | |
) | |
lazy val c = project | |
.settings( | |
commonSettings | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment