Skip to content

Commit

Permalink
Merge pull request #542 from typelevel/pr/better-prepr
Browse files Browse the repository at this point in the history
Better `prePR` command
  • Loading branch information
armanbilge authored Jun 19, 2023
2 parents caa5440 + d7ba294 commit 75a7c8f
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 26 deletions.
52 changes: 28 additions & 24 deletions core/src/main/scala/org/typelevel/sbt/TypelevelPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,18 @@ object TypelevelPlugin extends AutoPlugin {
override def trigger = allRequirements

object autoImport {
@deprecated("No longer has an effect. Use `tlFatalWarnings` instead.", "0.5.0")
lazy val tlFatalWarningsInCi = settingKey[Boolean](
"Convert compiler warnings into errors under CI builds (default: true)")
}

import autoImport._
import TypelevelKernelPlugin.mkCommand
import TypelevelCiPlugin.autoImport._
import TypelevelSettingsPlugin.autoImport._
import TypelevelSonatypeCiReleasePlugin.autoImport._
import GenerativePlugin.autoImport._
import GitHubActionsPlugin.autoImport._

override def globalSettings = Seq(
tlFatalWarningsInCi := true
)

override def buildSettings = Seq(
organization := "org.typelevel",
organizationName := "Typelevel",
Expand All @@ -70,7 +66,7 @@ object TypelevelPlugin extends AutoPlugin {
tlCiHeaderCheck := true,
tlCiScalafmtCheck := true,
tlCiReleaseBranches := Seq("main"),
Def.derive(tlFatalWarnings := (tlFatalWarningsInCi.value && githubIsWorkflowBuild.value)),
Def.derive(tlFatalWarnings := githubIsWorkflowBuild.value),
githubWorkflowJavaVersions := {
Seq(JavaSpec.temurin(tlJdkRelease.value.getOrElse(8).toString))
},
Expand All @@ -81,24 +77,7 @@ object TypelevelPlugin extends AutoPlugin {
java <- githubWorkflowJavaVersions.value.tail // default java is head
} yield MatrixExclude(Map("scala" -> scala, "java" -> java.render))
}
) ++ addCommandAlias(
"prePR",
mkCommand(
List(
"reload",
"project /",
"clean",
"githubWorkflowGenerate",
"headerCreateAll",
"scalafmtAll",
"scalafmtSbt",
"set ThisBuild / tlFatalWarnings := tlFatalWarningsInCi.value",
"Test / compile",
"doc",
"session clear"
)
)
) ++ addCommandAlias(
) ++ addPrePRCommandAlias ++ addCommandAlias(
"tlPrePrBotHook",
mkCommand(
List(
Expand All @@ -110,4 +89,29 @@ object TypelevelPlugin extends AutoPlugin {
)
)

// partially re-implemnents addCommandAlias
// this is so we can use the value of other settings to generate command
private def addPrePRCommandAlias: Seq[Setting[_]] = Seq(
GlobalScope / onLoad := {
val header = tlCiHeaderCheck.value
val scalafmt = tlCiScalafmtCheck.value
val scalafix = tlCiScalafixCheck.value

(GlobalScope / Keys.onLoad).value.compose { (state: State) =>
val command = mkCommand(
List("project /", "githubWorkflowGenerate") ++
List("+headerCreateAll").filter(_ => header) ++
List("+scalafmtAll", "scalafmtSbt").filter(_ => scalafmt) ++
List("+scalafixAll").filter(_ => scalafix)
)
BasicCommands.addAlias(state, "prePR", command)
}
},
GlobalScope / Keys.onUnload := {
(GlobalScope / Keys.onUnload)
.value
.compose((state: State) => BasicCommands.removeAlias(state, "prePR"))
}
)

}
1 change: 0 additions & 1 deletion docs/customization.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ Instead of using the super-plugins, for finer-grained control you can always add

### sbt-typelevel
- `TypelevelPlugin`: The super-super-plugin intended for bootstrapping the typical Typelevel project. Sets up CI release including snapshots, scalac settings, headers, and formatting.
- `tlFatalWarningsInCi` (setting): Convert compiler warnings into errors under CI builds (default: true).

### sbt-typelevel-site
- `TypelevelSitePlugin`: Sets up an [mdoc](https://scalameta.org/mdoc/)/[Laika](https://typelevel.org/Laika/)-generated website, automatically published to GitHub pages in CI.
Expand Down
2 changes: 1 addition & 1 deletion docs/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ You may also want to (globally) install the [sbt-rewarn](https://github.com/rtim
If you are using **sbt-typelevel** fatal warnings are on by default in CI.

```scala
ThisBuild / tlFatalWarningsInCi := false
ThisBuild / tlFatalWarnings := false
```

If you are only using **sbt-typelevel-ci-release**, you are completely in charge of your own `scalacOptions`, including fatal warnings.
Expand Down

0 comments on commit 75a7c8f

Please sign in to comment.