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

Better prePR command #542

Merged
merged 1 commit into from
Jun 19, 2023
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
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