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

Support checking Java formatting #711

Merged
merged 2 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
53 changes: 28 additions & 25 deletions ci/src/main/scala/org/typelevel/sbt/TypelevelCiPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ object TypelevelCiPlugin extends AutoPlugin {
settingKey[Boolean]("Whether to do header check in CI (default: false)")
lazy val tlCiScalafmtCheck =
settingKey[Boolean]("Whether to do scalafmt check in CI (default: false)")
lazy val tlCiJavafmtCheck =
settingKey[Boolean]("Whether to do javafmt check in CI (default: false)")
lazy val tlCiScalafixCheck =
settingKey[Boolean]("Whether to do scalafix check in CI (default: false)")
lazy val tlCiMimaBinaryIssueCheck =
Expand All @@ -57,6 +59,7 @@ object TypelevelCiPlugin extends AutoPlugin {
override def buildSettings = Seq(
tlCiHeaderCheck := false,
tlCiScalafmtCheck := false,
tlCiJavafmtCheck := false,
tlCiScalafixCheck := false,
tlCiMimaBinaryIssueCheck := false,
tlCiDocCheck := false,
Expand All @@ -68,32 +71,32 @@ object TypelevelCiPlugin extends AutoPlugin {
githubWorkflowPublishTargetBranches := Seq(),
githubWorkflowBuild := {

val style = (tlCiHeaderCheck.value, tlCiScalafmtCheck.value) match {
case (true, true) => // headers + formatting
List(
WorkflowStep.Sbt(
List("headerCheckAll", "scalafmtCheckAll", "project /", "scalafmtSbtCheck"),
name = Some("Check headers and formatting"),
cond = Some(primaryAxisCond.value)
)
)
case (true, false) => // headers
List(
WorkflowStep.Sbt(
List("headerCheckAll"),
name = Some("Check headers"),
cond = Some(primaryAxisCond.value)
)
)
case (false, true) => // formatting
List(
WorkflowStep.Sbt(
List("scalafmtCheckAll", "project /", "scalafmtSbtCheck"),
name = Some("Check formatting"),
cond = Some(primaryAxisCond.value)
)
val style = {
val headers = List("headerCheckAll").filter(_ => tlCiHeaderCheck.value)

val scalafmt = List(
"scalafmtCheckAll",
"project /",
"scalafmtSbtCheck"
).filter(_ => tlCiScalafmtCheck.value)

val javafmt = List("javafmtCheckAll").filter(_ => tlCiJavafmtCheck.value)

val formatting = javafmt ++ scalafmt

val headersFormatting = headers ++ formatting

val names =
List("headers").filter(_ => headers.nonEmpty) ++ List("formatting").filter(_ =>
formatting.nonEmpty)

List(
WorkflowStep.Sbt(
headers ++ formatting,
name = Some(s"Check ${names.mkString(" and ")}"),
cond = Some(primaryAxisCond.value)
)
case (false, false) => Nil // nada
).filter(_ => headersFormatting.nonEmpty)
}

val test = List(
Expand Down
4 changes: 3 additions & 1 deletion core/src/main/scala/org/typelevel/sbt/TypelevelPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,14 @@ object TypelevelPlugin extends AutoPlugin {
GlobalScope / tlCommandAliases ++= {
val header = tlCiHeaderCheck.value
val scalafmt = tlCiScalafmtCheck.value
val javafmt = tlCiJavafmtCheck.value
val scalafix = tlCiScalafixCheck.value

val prePR = List("project /", "githubWorkflowGenerate") ++
List("+headerCreateAll").filter(_ => header) ++
List("+scalafixAll").filter(_ => scalafix) ++
List("+scalafmtAll", "scalafmtSbt").filter(_ => scalafmt)
List("+scalafmtAll", "scalafmtSbt").filter(_ => scalafmt) ++
List("javafmtAll").filter(_ => javafmt)

val botHook = List("githubWorkflowGenerate") ++
List("+headerCreateAll").filter(_ => header) ++
Expand Down
1 change: 1 addition & 0 deletions docs/customization.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ Both plugins are documented in [**sbt-typelevel-github-actions**](gha.md).

- `tlCiHeaderCheck` (setting): Whether to do header check in CI (default: `false`).
- `tlCiScalafmtCheck` (setting): Whether to do scalafmt check in CI (default: `false`).
- `tlCiJavafmtCheck` (setting): Whether to do javafmt check in CI (default: `false`).
- `tlCiScalafixCheck` (setting): Whether to do scalafix check in CI (default: `false`).
- `tlCiMimaBinaryIssueCheck` (setting): Whether to do MiMa binary issues check in CI (default: `false`).
- `tlCiDocCheck` (setting): Whether to build API docs in CI (default: `false`).
Expand Down
Loading