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

Split CI into multiple steps #65

Merged
merged 25 commits into from
Jan 16, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
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
12 changes: 9 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
os: [ubuntu-latest]
scala: [2.12.15]
java: [temurin@8]
ci: [ciJVM]
project: [rootJVM]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout current branch (full)
Expand Down Expand Up @@ -57,9 +57,15 @@ jobs:
key: ${{ runner.os }}-sbt-cache-v2-${{ hashFiles('**/*.sbt') }}-${{ hashFiles('project/build.properties') }}

- name: Check that workflows are up to date
run: sbt '++${{ matrix.scala }}' 'project /' githubWorkflowCheck
run: sbt 'project ${{ matrix.project }}' '++${{ matrix.scala }}' 'project /' githubWorkflowCheck

- run: sbt '++${{ matrix.scala }}' '${{ matrix.ci }}'
- run: sbt 'project ${{ matrix.project }}' '++${{ matrix.scala }}' headerCheckAll scalafmtCheckAll scalafmtSbtCheck

- run: sbt 'project ${{ matrix.project }}' '++${{ matrix.scala }}' clean

- run: sbt 'project ${{ matrix.project }}' '++${{ matrix.scala }}' test

- run: sbt 'project ${{ matrix.project }}' '++${{ matrix.scala }}' mimaReportBinaryIssues

- name: Make target directories
run: mkdir -p github/target github-actions/target kernel/target versioning/target ci-release/target target .js/target ci-signing/target mima/target .jvm/target .native/target no-publish/target sonatype/target ci/target sonatype-ci-release/target core/target settings/target project/target
Expand Down
88 changes: 41 additions & 47 deletions ci/src/main/scala/org/typelevel/sbt/CrossRootProject.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ package org.typelevel.sbt

import sbt._
import org.typelevel.sbt.gha.GenerativePlugin.autoImport._
import TypelevelCiPlugin.ciCommands
import TypelevelKernelPlugin.mkCommand

/**
* Simultaneously creates a `root`, `rootJVM`, `rootJS`, and `rootNative` project, and
Expand Down Expand Up @@ -113,12 +111,8 @@ object TypelevelCiCrossPlugin extends AutoPlugin {
override def requires = TypelevelCiPlugin

override def buildSettings = Seq(
githubWorkflowBuild ~= { steps =>
// remove the usual ci step and replace with matrix ci
steps.diff(Seq(WorkflowStep.Sbt(List("ci")))) :+
WorkflowStep.Sbt(List(s"$${{ matrix.ci }}"))
},
githubWorkflowBuildMatrixAdditions += "ci" -> Nil
githubWorkflowBuildSbtStepPreamble ~= { s"project $${{ matrix.project }}" +: _ },
githubWorkflowBuildMatrixAdditions += "project" -> Nil
)
}

Expand All @@ -127,56 +121,56 @@ object TypelevelCiCrossPlugin extends AutoPlugin {
object TypelevelCiJVMPlugin extends AutoPlugin {
override def requires = TypelevelCiCrossPlugin

override def buildSettings: Seq[Setting[_]] =
addCommandAlias("ciJVM", mkCommand(ciJVMCommands)) ++ Seq(
githubWorkflowBuildMatrixAdditions ~= { matrix =>
matrix.updated("ci", matrix("ci") ::: "ciJVM" :: Nil)
}
)

val ciJVMCommands = "project rootJVM" :: ciCommands.tail
override def buildSettings: Seq[Setting[_]] = Seq(
githubWorkflowBuildMatrixAdditions ~= { matrix =>
matrix.updated("project", matrix("project") ::: "rootJVM" :: Nil)
}
)
}

object TypelevelCiJSPlugin extends AutoPlugin {
override def requires = TypelevelCiCrossPlugin

override def buildSettings: Seq[Setting[_]] =
addCommandAlias("ciJS", mkCommand(ciJSCommands)) ++ Seq(
githubWorkflowBuildMatrixAdditions ~= { matrix =>
matrix.updated("ci", matrix("ci") ::: "ciJS" :: Nil)
},
githubWorkflowBuildMatrixExclusions ++= {
githubWorkflowJavaVersions
.value
.tail
.map(java => MatrixExclude(Map("ci" -> "ciJS", "java" -> java.render)))
override def buildSettings: Seq[Setting[_]] = Seq(
githubWorkflowBuildMatrixAdditions ~= { matrix =>
matrix.updated("project", matrix("project") ::: "rootJS" :: Nil)
},
githubWorkflowBuildMatrixExclusions ++= {
githubWorkflowJavaVersions
.value
.tail
.map(java => MatrixExclude(Map("project" -> "rootJS", "java" -> java.render)))
},
githubWorkflowBuild ~= { steps =>
steps.flatMap {
case testStep @ WorkflowStep.Sbt(List("test"), _, _, _, _, _) =>
List(WorkflowStep.Sbt(List("Test/fastOptJS")), testStep)
case step => List(step)
}
)
}
)

val ciJSCommands = "project rootJS" :: ciCommands.tail.flatMap {
case "test" => List("Test/fastOptJS", "test")
case x => List(x)
}
}

object TypelevelCiNativePlugin extends AutoPlugin {
override def requires = TypelevelCiCrossPlugin

override def buildSettings: Seq[Setting[_]] =
addCommandAlias("ciNative", mkCommand(ciNativeCommands)) ++ Seq(
githubWorkflowBuildMatrixAdditions ~= { matrix =>
matrix.updated("ci", matrix("ci") ::: "ciNative" :: Nil)
},
githubWorkflowBuildMatrixExclusions ++= {
githubWorkflowJavaVersions
.value
.tail
.map(java => MatrixExclude(Map("ci" -> "ciNative", "java" -> java.render)))
override def buildSettings: Seq[Setting[_]] = Seq(
githubWorkflowBuildMatrixAdditions ~= { matrix =>
matrix.updated("project", matrix("project") ::: "rootNative" :: Nil)
},
githubWorkflowBuildMatrixExclusions ++= {
githubWorkflowJavaVersions
.value
.tail
.map(java => MatrixExclude(Map("project" -> "rootNative", "java" -> java.render)))
},
githubWorkflowBuild ~= { steps =>
steps.flatMap {
case testStep @ WorkflowStep.Sbt(List("test"), _, _, _, _, _) =>
List(WorkflowStep.Sbt(List("Test/nativeLink")), testStep)
case step => List(step)
}
)

val ciNativeCommands = "project rootNative" :: ciCommands.tail.flatMap {
case "test" => List("Test/nativeLink", "test")
case x => List(x)
}
}
)
}
47 changes: 21 additions & 26 deletions ci/src/main/scala/org/typelevel/sbt/TypelevelCiPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import org.typelevel.sbt.gha.GenerativePlugin
import org.typelevel.sbt.gha.GitHubActionsPlugin
import org.typelevel.sbt.gha.GenerativePlugin.autoImport._
import com.typesafe.tools.mima.plugin.MimaPlugin
import TypelevelKernelPlugin.mkCommand

object TypelevelCiPlugin extends AutoPlugin {

Expand All @@ -32,32 +31,28 @@ object TypelevelCiPlugin extends AutoPlugin {
def tlCrossRootProject: CrossRootProject = CrossRootProject()
}

override def buildSettings =
addCommandAlias("ci", mkCommand(ciCommands)) ++ Seq(
githubWorkflowPublishTargetBranches := Seq(),
githubWorkflowBuild := Seq(WorkflowStep.Sbt(List("ci"))),
githubWorkflowJavaVersions := Seq(JavaSpec.temurin("8")),
githubWorkflowGeneratedUploadSteps ~= { steps =>
// hack hack hack until upstreamed
// workaround for https://github.com/djspiewak/sbt-github-actions/pull/66
steps.flatMap {
case compressStep @ WorkflowStep
.Run(command :: _, _, Some("Compress target directories"), _, _, _) =>
val mkdirStep = WorkflowStep.Run(
commands = List(command.replace("tar cf targets.tar", "mkdir -p")),
name = Some("Make target directories")
)
List(mkdirStep, compressStep)
case step => List(step)
}
override def buildSettings = Seq(
githubWorkflowPublishTargetBranches := Seq(),
githubWorkflowBuild := Seq(
WorkflowStep.Sbt(List("clean")),
WorkflowStep.Sbt(List("test")),
WorkflowStep.Sbt(List("mimaReportBinaryIssues"))
),
githubWorkflowJavaVersions := Seq(JavaSpec.temurin("8")),
githubWorkflowGeneratedUploadSteps ~= { steps =>
// hack hack hack until upstreamed
// workaround for https://github.com/djspiewak/sbt-github-actions/pull/66
steps.flatMap {
case compressStep @ WorkflowStep
.Run(command :: _, _, Some("Compress target directories"), _, _, _) =>
val mkdirStep = WorkflowStep.Run(
commands = List(command.replace("tar cf targets.tar", "mkdir -p")),
name = Some("Make target directories")
)
List(mkdirStep, compressStep)
case step => List(step)
}
)

val ciCommands = List(
"project /",
"clean",
"test",
"mimaReportBinaryIssues"
}
)

}
37 changes: 4 additions & 33 deletions core/src/main/scala/org/typelevel/sbt/TypelevelPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ import sbt._, Keys._
import org.typelevel.sbt.gha.GenerativePlugin
import org.typelevel.sbt.gha.GitHubActionsPlugin
import de.heikoseeberger.sbtheader.AutomateHeaderPlugin
import TypelevelCiPlugin.ciCommands
import TypelevelKernelPlugin.mkCommand

object TypelevelPlugin extends AutoPlugin {

Expand All @@ -39,7 +37,6 @@ object TypelevelPlugin extends AutoPlugin {
}

import autoImport._
import TypelevelKernelPlugin.autoImport._
import TypelevelSettingsPlugin.autoImport._
import TypelevelSonatypeCiReleasePlugin.autoImport._
import GenerativePlugin.autoImport._
Expand All @@ -62,38 +59,12 @@ object TypelevelPlugin extends AutoPlugin {
scala <- githubWorkflowScalaVersions.value.init
java <- githubWorkflowJavaVersions.value.tail
} yield MatrixExclude(Map("scala" -> scala, "java" -> java.render))
},
githubWorkflowBuild ~= { steps =>
WorkflowStep.Sbt(List("headerCheckAll", "scalafmtCheckAll", "scalafmtSbtCheck")) +: steps
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can these steps take arguments, even if just as one string? Some of the scalafix linters require an arg.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good question. Yes, it seems we are already using that in http4s:
https://github.com/http4s/http4s/blob/1baf3d4f5fb135098b6b857a488b36cd39ca4a56/build.sbt#L41

}
) ++ tlReplaceCommandAlias("ci", mkCommand(fmtCheckCommands ::: ciCommands.tail))
)

override def projectSettings = AutomateHeaderPlugin.projectSettings

val fmtCheckCommands =
List("project /", "headerCheckAll", "scalafmtCheckAll", "scalafmtSbtCheck")
}

import TypelevelKernelPlugin.autoImport._
import TypelevelPlugin.fmtCheckCommands
import TypelevelCiJVMPlugin.ciJVMCommands
import TypelevelCiJSPlugin.ciJSCommands
import TypelevelCiNativePlugin.ciNativeCommands

object TypelevelJVMPlugin extends AutoPlugin {
override def requires = TypelevelCiJVMPlugin
override def trigger = allRequirements
override def buildSettings =
tlReplaceCommandAlias("ciJVM", mkCommand(fmtCheckCommands ++ ciJVMCommands))
}

object TypelevelJSPlugin extends AutoPlugin {
override def requires = TypelevelCiJSPlugin
override def trigger = allRequirements
override def buildSettings =
tlReplaceCommandAlias("ciJS", mkCommand(fmtCheckCommands ++ ciJSCommands))
}

object TypelevelNativePlugin extends AutoPlugin {
override def requires = TypelevelCiNativePlugin
override def trigger = allRequirements
override def buildSettings =
tlReplaceCommandAlias("ciNative", mkCommand(fmtCheckCommands ++ ciNativeCommands))
}