-
Notifications
You must be signed in to change notification settings - Fork 5
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
chore: Migrate project to sbt-projectmatrix #33
Changes from all commits
8f20c28
befbfd8
4f37b69
ecb0576
6a79508
22122a7
a0014ad
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,24 @@ | ||
import sbt.internal.ProjectMatrix | ||
import sbtghactions.JavaSpec | ||
import complete.DefaultParsers._ | ||
import sbt.Reference.display | ||
|
||
val munitVersion = "0.7.29" | ||
val catsVersion = "2.9.0" | ||
val scalatestVersion = "3.2.16" | ||
val weaverVersion = "0.8.3" | ||
|
||
val scala213 = "2.13.11" | ||
val scala3 = "3.3.0" | ||
|
||
val isScala3 = Def.setting { | ||
// doesn't work well with >= 3.0.0 for `3.0.0-M1` | ||
scalaVersion.value.startsWith("3") | ||
} | ||
|
||
val mainScalaVersion = Build.Scala213 | ||
val jvmScalaVersions = Seq(Build.Scala213, Build.Scala3) | ||
|
||
inThisBuild( | ||
List( | ||
scalaVersion := scala213, | ||
crossScalaVersions := Seq(scala213, scala3), | ||
scalaVersion := mainScalaVersion, | ||
organization := "com.github.jatcwang", | ||
homepage := Some(url("https://github.com/jatcwang/difflicious")), | ||
licenses := List("Apache-2.0" -> url("http://www.apache.org/licenses/LICENSE-2.0")), | ||
|
@@ -28,16 +30,21 @@ inThisBuild( | |
url("https://almostfunctional.com"), | ||
), | ||
), | ||
commands ++= Build.createBuildCommands(allModules), | ||
), | ||
) | ||
|
||
lazy val allModules = Seq(core, coretest, munit, scalatest, weaver, cats, benchmarks, docs).flatMap(_.projectRefs) | ||
|
||
lazy val difflicious = Project("difflicious", file(".")) | ||
.aggregate(core, coretest, benchmarks, cats, docs, munit, scalatest, weaver) | ||
.aggregate(allModules: _*) | ||
.settings(commonSettings, noPublishSettings) | ||
|
||
lazy val core = Project("difflicious-core", file("modules/core")) | ||
lazy val core = projectMatrix | ||
.in(file("modules/core")) | ||
.settings(commonSettings) | ||
.settings( | ||
name := "difflicious-core", | ||
libraryDependencies ++= Seq( | ||
"dev.zio" %% "izumi-reflect" % "2.3.8", | ||
"com.lihaoyi" %% "fansi" % "0.4.0", | ||
|
@@ -46,58 +53,73 @@ lazy val core = Project("difflicious-core", file("modules/core")) | |
} else | ||
Seq( | ||
"com.softwaremill.magnolia1_2" %% "magnolia" % "1.0.0", | ||
"org.scala-lang" % "scala-reflect" % scala213, | ||
"org.scala-lang" % "scala-reflect" % Build.Scala213, | ||
)), | ||
Compile / sourceGenerators += Def.task { | ||
val file = (Compile / sourceManaged).value / "difflicious" / "TupleDifferInstances.scala" | ||
IO.write(file, TupleDifferInstancesGen.fileContent) | ||
Seq(file) | ||
}.taskValue, | ||
) | ||
.jvmPlatform(jvmScalaVersions) | ||
|
||
lazy val munit = Project("difflicious-munit", file("modules/munit")) | ||
lazy val munit = projectMatrix | ||
.in(file("modules/munit")) | ||
.dependsOn(core) | ||
.settings(commonSettings) | ||
.settings( | ||
name := "difflicious-munit", | ||
libraryDependencies ++= Seq( | ||
"org.scalameta" %% "munit" % munitVersion, | ||
), | ||
) | ||
.jvmPlatform(jvmScalaVersions) | ||
|
||
lazy val scalatest = Project("difflicious-scalatest", file("modules/scalatest")) | ||
lazy val scalatest = projectMatrix | ||
.in(file("modules/scalatest")) | ||
.dependsOn(core) | ||
.settings(commonSettings) | ||
.settings( | ||
name := "difflicious-scalatest", | ||
libraryDependencies ++= Seq( | ||
"org.scalatest" %% "scalatest-core" % scalatestVersion, | ||
), | ||
) | ||
.jvmPlatform(jvmScalaVersions) | ||
|
||
lazy val weaver = Project("difflicious-weaver", file("modules/weaver")) | ||
lazy val weaver = projectMatrix | ||
.in(file("modules/weaver")) | ||
.dependsOn(core) | ||
.settings(commonSettings) | ||
.settings( | ||
name := "difflicious-weaver", | ||
libraryDependencies ++= Seq( | ||
"com.disneystreaming" %% "weaver-core" % weaverVersion, | ||
), | ||
) | ||
.jvmPlatform(jvmScalaVersions) | ||
|
||
lazy val cats = Project("difflicious-cats", file("modules/cats")) | ||
lazy val cats = projectMatrix | ||
.in(file("modules/cats")) | ||
.dependsOn(core, coretest % "test->test") | ||
.settings(commonSettings) | ||
.settings( | ||
name := "difflicious-cats", | ||
libraryDependencies ++= Seq( | ||
"org.typelevel" %% "cats-core" % catsVersion, | ||
), | ||
libraryDependencies ++= Seq( | ||
"org.typelevel" %% "cats-laws" % catsVersion, | ||
).map(_ % Test), | ||
) | ||
.jvmPlatform(jvmScalaVersions) | ||
|
||
lazy val coretest = Project("coretest", file("modules/coretest")) | ||
lazy val coretest = projectMatrix | ||
.in(file("modules/coretest")) | ||
.dependsOn(core) | ||
.settings(commonSettings, noPublishSettings) | ||
.settings( | ||
name := "coretest", | ||
libraryDependencies ++= Seq( | ||
"org.typelevel" %% "cats-core" % catsVersion, | ||
), | ||
|
@@ -107,11 +129,13 @@ lazy val coretest = Project("coretest", file("modules/coretest")) | |
"org.scalameta" %% "munit-scalacheck" % munitVersion, | ||
).map(_ % Test), | ||
) | ||
.jvmPlatform(jvmScalaVersions) | ||
|
||
lazy val docs: Project = project | ||
lazy val docs: ProjectMatrix = projectMatrix | ||
.dependsOn(core, coretest, cats, munit, scalatest, weaver) | ||
.enablePlugins(MicrositesPlugin) | ||
.settings( | ||
name := "docs", | ||
commonSettings, | ||
publish / skip := true, | ||
) | ||
|
@@ -157,12 +181,15 @@ lazy val docs: Project = project | |
(opts ++ extraOpts).filterNot(removes) | ||
}, | ||
) | ||
.jvmPlatform(Seq(Build.Scala213)) | ||
|
||
lazy val benchmarks = Project("benchmarks", file("modules/benchmarks")) | ||
lazy val benchmarks = projectMatrix | ||
.in(file("modules/benchmarks")) | ||
.dependsOn(coretest) | ||
.enablePlugins(JmhPlugin) | ||
.settings(commonSettings) | ||
.settings(noPublishSettings) | ||
.jvmPlatform(jvmScalaVersions) | ||
|
||
lazy val commonSettings = Seq( | ||
scalacOptions --= { | ||
|
@@ -213,15 +240,25 @@ val setupJekyllSteps = Seq( | |
), | ||
) | ||
|
||
ThisBuild / githubWorkflowBuildMatrixAdditions += ("scalaPlatform", List("jvm")) | ||
|
||
ThisBuild / githubWorkflowBuildPreamble ++= setupJekyllSteps | ||
|
||
ThisBuild / githubWorkflowPublishPreamble ++= setupJekyllSteps | ||
|
||
ThisBuild / githubWorkflowScalaVersions := Seq("2_13", "3_0") | ||
|
||
ThisBuild / githubWorkflowBuildSbtStepPreamble := Seq.empty | ||
|
||
ThisBuild / githubWorkflowArtifactUpload := false | ||
|
||
// Add makeMicrosite to the build step | ||
ThisBuild / githubWorkflowBuild ~= { steps => | ||
steps.map { | ||
case w: WorkflowStep.Sbt if w.commands == List("test") => | ||
w.copy(commands = List("test", "makeMicrosite", "publishLocal")) | ||
w.copy(commands = | ||
List("test", "publishLocal").map(_ + "_${{ matrix.scala }}_${{ matrix.scalaPlatform }}") :+ "makeMicrosite", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks no biggie we can fix that later. |
||
) | ||
case w => w | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import sbt._ | ||
import sbt.Keys._ | ||
import com.jsuereth.sbtpgp.PgpKeys._ | ||
import sbt.internal.LogManager | ||
import sbt.internal.util.BufferedAppender | ||
import java.io.PrintStream | ||
import sbt.internal.ProjectMatrix | ||
import sbtprojectmatrix.ProjectMatrixPlugin.autoImport.virtualAxes | ||
|
||
object Build { | ||
|
||
val Scala213 = "2.13.11" | ||
val Scala3 = "3.3.0" | ||
|
||
// copied from: https://github.com/disneystreaming/smithy4s/blob/21a6fb04ab3485c0a4b40fe205a628c6f4750813/project/Smithy4sBuildPlugin.scala#L508 | ||
def createBuildCommands(projects: Seq[ProjectReference]) = { | ||
case class Doublet(scala: String, platform: String) | ||
|
||
val scala3Suffix = VirtualAxis.scalaABIVersion(Scala3).idSuffix | ||
val scala213Suffix = VirtualAxis.scalaABIVersion(Scala213).idSuffix | ||
val jsSuffix = VirtualAxis.js.idSuffix | ||
val nativeSuffix = VirtualAxis.native.idSuffix | ||
|
||
val all: List[(Doublet, Seq[String])] = | ||
projects | ||
.collect { case lp: LocalProject => | ||
var projectId = lp.project | ||
|
||
val scalaAxis = | ||
if (projectId.endsWith(scala3Suffix)) { | ||
projectId = projectId.dropRight(scala3Suffix.length) | ||
"3_0" | ||
} else "2_13" | ||
|
||
val platformAxis = | ||
if (projectId.endsWith(jsSuffix)) { | ||
projectId = projectId.dropRight(jsSuffix.length) | ||
"js" | ||
} else if (projectId.endsWith(nativeSuffix)) { | ||
projectId = projectId.dropRight(nativeSuffix.length) | ||
"native" | ||
} else { | ||
"jvm" | ||
} | ||
|
||
Doublet(scalaAxis, platformAxis) -> lp.project | ||
} | ||
.groupBy(_._1) | ||
.mapValues(_.map(_._2)) | ||
.toList | ||
|
||
// some commands, like test and compile, are setup for all modules | ||
val any = (t: Doublet) => true | ||
// things like scalafix and scalafmt are only enabled on jvm 2.13 projects | ||
val jvm2_13 = (t: Doublet) => t.scala == "2_13" && t.platform == "jvm" | ||
|
||
val jvm = (t: Doublet) => t.platform == "jvm" | ||
|
||
val desiredCommands: Map[String, (String, Doublet => Boolean)] = Map( | ||
"test" -> ("test", any), | ||
"compile" -> ("compile", any), | ||
"publishLocal" -> ("publishLocal", any), | ||
) | ||
|
||
val cmds = all.flatMap { case (doublet, projects) => | ||
desiredCommands.filter(_._2._2(doublet)).map { case (name, (cmd, _)) => | ||
Command.command( | ||
s"${name}_${doublet.scala}_${doublet.platform}", | ||
) { state => | ||
projects.foldLeft(state) { case (st, proj) => | ||
s"$proj/$cmd" :: st | ||
} | ||
} | ||
} | ||
} | ||
|
||
cmds | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had to disable uploading of artifacts as sbt-gha does not generate list of artifacts to upload based on the matrix values but it generates it for all modules and there is no builtin way to configure it to this use-case. It fails with directory does not exist in our case as jvm-2.13 is not present when building for scala 3. There a workaround mentioned in sbt/sbt-github-actions#9 but I think that it doesn't apply to our case.
Maybe this can be fixed by overriding
githubWorkflowGeneratedUploadSteps
but readme discourages such actions.