Skip to content
Closed
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
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ jobs:
- name: Check that workflows are up to date
run: sbt 'project ${{ matrix.project }}' '++${{ matrix.scala }}' 'project /' githubWorkflowCheck

- name: Check headers and formatting
- name: Check headers, migrations and formatting
if: matrix.java == 'temurin@8'
run: sbt 'project ${{ matrix.project }}' '++${{ matrix.scala }}' headerCheckAll scalafmtCheckAll 'project /' scalafmtSbtCheck
run: sbt 'project ${{ matrix.project }}' '++${{ matrix.scala }}' headerCheckAll scalafmtCheckAll 'scalafixAll --check' 'project /' scalafmtSbtCheck

- name: Test
run: sbt 'project ${{ matrix.project }}' '++${{ matrix.scala }}' test
Expand All @@ -81,11 +81,11 @@ jobs:

- name: Make target directories
if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main')
run: mkdir -p github/target github-actions/target kernel/target versioning/target ci-release/target .jvm/target mdocs/target site/target ci-signing/target mergify/target unidoc/target .native/target mima/target no-publish/target sonatype/target ci/target sonatype-ci-release/target core/target settings/target target .js/target project/target
run: mkdir -p github/target github-actions/target kernel/target versioning/target ci-release/target scalafix/target .jvm/target mdocs/target site/target ci-signing/target mergify/target unidoc/target .native/target mima/target no-publish/target sonatype/target ci/target sonatype-ci-release/target core/target settings/target target .js/target project/target

- name: Compress target directories
if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main')
run: tar cf targets.tar github/target github-actions/target kernel/target versioning/target ci-release/target .jvm/target mdocs/target site/target ci-signing/target mergify/target unidoc/target .native/target mima/target no-publish/target sonatype/target ci/target sonatype-ci-release/target core/target settings/target target .js/target project/target
run: tar cf targets.tar github/target github-actions/target kernel/target versioning/target ci-release/target scalafix/target .jvm/target mdocs/target site/target ci-signing/target mergify/target unidoc/target .native/target mima/target no-publish/target sonatype/target ci/target sonatype-ci-release/target core/target settings/target target .js/target project/target

- name: Upload target directories
if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main')
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,6 @@ tags
.bloop/
metals.sbt
.vscode

# Mac OS
.DS_Store
8 changes: 8 additions & 0 deletions .mergify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,14 @@ pull_request_rules:
add:
- no-publish
remove: []
- name: Label scalafix PRs
conditions:
- files~=^scalafix/
actions:
label:
add:
- scalafix
remove: []
- name: Label settings PRs
conditions:
- files~=^settings/
Expand Down
7 changes: 7 additions & 0 deletions .scalafix.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
rules = [
OrganizeImports
]

OrganizeImports {
preset = INTELLIJ_2020_3
}
Comment on lines +1 to +7

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Summoning @rossabaker to tell us how to organize our imports then @valencik can put it into typelevel.g8.

Looking at http4s I guess we are just using the default configuration, since that is best for diffs and merges?
https://github.com/http4s/http4s/blob/9ac020a92409ce86ad8d67c08ba4dcd31bb6438b/.scalafix.conf

@DavidGregory084 DavidGregory084 May 17, 2022

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I chose this configuration because although LSP users can Organize Imports straight from their editor, there will always be folks using IntelliJ which has its own way of handling import organisation, so this seems like a good choice to minimise friction for contributors.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I might otherwise agree, but the IntelliJ preset's correctness issue concerns me. And since most projects I maintain end up with maintenance branches, I appreciate the care the defaults put into diff reduction.

I won't die on this hill, though.

10 changes: 10 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ lazy val `sbt-typelevel` = tlCrossRootProject.aggregate(
versioning,
mima,
sonatype,
scalafix,
ciSigning,
sonatypeCiRelease,
ci,
Expand Down Expand Up @@ -104,6 +105,14 @@ lazy val sonatype = project
)
.dependsOn(kernel)

lazy val scalafix = project
.in(file("scalafix"))
.enablePlugins(SbtPlugin)
.settings(
name := "sbt-typelevel-scalafix"
)
.dependsOn(kernel)

lazy val ciSigning = project
.in(file("ci-signing"))
.enablePlugins(SbtPlugin)
Expand Down Expand Up @@ -152,6 +161,7 @@ lazy val core = project
)
.dependsOn(
ciRelease,
scalafix,
settings
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@
package org.typelevel.sbt

import io.crashbox.gpg.SbtGpg
import sbt._, Keys._
import org.typelevel.sbt.gha.GenerativePlugin
import org.typelevel.sbt.gha.GitHubActionsPlugin
import org.typelevel.sbt.gha.GenerativePlugin.autoImport._
import org.typelevel.sbt.gha.{GenerativePlugin, GitHubActionsPlugin}
import sbt._

import Keys._

object TypelevelCiSigningPlugin extends AutoPlugin {

Expand Down
2 changes: 1 addition & 1 deletion ci/src/main/scala/org/typelevel/sbt/CrossRootProject.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

package org.typelevel.sbt

import sbt._
import org.typelevel.sbt.gha.GenerativePlugin.autoImport._
import sbt._

/**
* Simultaneously creates a root project, a Scala JVM aggregate project, a Scala.js aggregate
Expand Down
8 changes: 4 additions & 4 deletions ci/src/main/scala/org/typelevel/sbt/TypelevelCiPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@

package org.typelevel.sbt

import sbt._
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 org.typelevel.sbt.gha.GenerativePlugin.autoImport._
import org.typelevel.sbt.gha.{GenerativePlugin, GitHubActionsPlugin}
import sbt._

import scala.language.experimental.macros

object TypelevelCiPlugin extends AutoPlugin {
Expand Down
12 changes: 7 additions & 5 deletions core/src/main/scala/org/typelevel/sbt/TypelevelPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,21 @@

package org.typelevel.sbt

import sbt._, Keys._
import org.typelevel.sbt.gha.GenerativePlugin
import org.typelevel.sbt.gha.GitHubActionsPlugin
import de.heikoseeberger.sbtheader.HeaderPlugin
import org.typelevel.sbt.gha.{GenerativePlugin, GitHubActionsPlugin}
import sbt._

import scala.collection.immutable

import Keys._

object TypelevelPlugin extends AutoPlugin {

override def requires =
TypelevelKernelPlugin &&
TypelevelSettingsPlugin &&
TypelevelCiReleasePlugin &&
TypelevelScalafixPlugin &&
GitHubActionsPlugin &&
HeaderPlugin

Expand Down Expand Up @@ -73,8 +75,8 @@ object TypelevelPlugin extends AutoPlugin {
},
githubWorkflowBuild := {
WorkflowStep.Sbt(
List("headerCheckAll", "scalafmtCheckAll", "project /", "scalafmtSbtCheck"),
name = Some("Check headers and formatting"),
List("headerCheckAll", "scalafmtCheckAll", "scalafixAll --check", "project /", "scalafmtSbtCheck"),
name = Some("Check headers, migrations and formatting"),
Comment on lines +78 to +79

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

So actually after the discussion in #247 (comment) I had an idea to do these differently.

Basically, I think the TypelevelCiPlugin should expose boolean settings for enabling header, fmt, scalafix, and mima checks in CI and then generate the CI steps based on those. Then, builds and/or other plugins can enable those settings (or if we are really clever, they can introspect plugins available on the build and set themselves).

This will also make it easier for an individual build to decide whether to opt-in or opt-out of any of these particular checks.

@armanbilge armanbilge May 17, 2022

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Oh, another thing to note here, is that scalafixAll --check I believe needs a full compile of the project, which is why it's usually called as a later step in CI.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ah of course, the semanticdb doesn't exist until then anyway! I guess it ought to be a build step then.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm going to work on what I described in #274 (comment), been putting it off long enough, and then we can try and re-integrate this PR against those changes. Thanks, and sorry!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I had a quick look at this and this is where I got to:

diff --git a/ci/src/main/scala/org/typelevel/sbt/TypelevelCiPlugin.scala b/ci/src/main/scala/org/typelevel/sbt/TypelevelCiPlugin.scala
index 335f99a..53385fa 100644
--- a/ci/src/main/scala/org/typelevel/sbt/TypelevelCiPlugin.scala
+++ b/ci/src/main/scala/org/typelevel/sbt/TypelevelCiPlugin.scala
@@ -20,33 +20,87 @@ import sbt._
 import org.typelevel.sbt.gha.GenerativePlugin
 import org.typelevel.sbt.gha.GitHubActionsPlugin
 import org.typelevel.sbt.gha.GenerativePlugin.autoImport._
+import org.typelevel.sbt.TypelevelScalafixPlugin.autoImport._
 import com.typesafe.tools.mima.plugin.MimaPlugin
 import scala.language.experimental.macros
 
 object TypelevelCiPlugin extends AutoPlugin {
 
-  override def requires = GitHubActionsPlugin && GenerativePlugin && MimaPlugin
+  override def requires =
+    GitHubActionsPlugin && GenerativePlugin && MimaPlugin && TypelevelScalafixPlugin
+
   override def trigger = allRequirements
 
   object autoImport {
     def tlCrossRootProject: CrossRootProject = macro CrossRootProjectMacros.crossRootProjectImpl
+
+    val tlCheckHeaders =
+      settingKey[Boolean]("Check for presence of copyright headers in CI (default: true)")
+    val tlCheckFormatting = settingKey[Boolean](
+      "Check code is formatted according to the project's Scalafmt config in CI (default: true)")
+    val tlCheckMigrations = settingKey[Boolean](
+      "Check configured Scalafix migrations have been applied in CI (default: true)")
   }
 
+  import autoImport._
+
   override def buildSettings = Seq(
+    tlCheckHeaders := true,
+    tlCheckFormatting := true,
+    tlCheckMigrations := true,
     githubWorkflowPublishTargetBranches := Seq(),
-    githubWorkflowBuild := Seq(
-      WorkflowStep.Sbt(List("test"), name = Some("Test")),
-      WorkflowStep.Sbt(
-        List("mimaReportBinaryIssues"),
-        name = Some("Check binary compatibility"),
-        cond = Some(primaryJavaCond.value)
-      ),
-      WorkflowStep.Sbt(
-        List("doc"),
-        name = Some("Generate API documentation"),
-        cond = Some(primaryJavaCond.value)
+    githubWorkflowBuild := {
+      val checkHeadersCommands =
+        if (tlCheckHeaders.value) List("headerCheckAll") else Nil
+
+      val checkFormattingCommands =
+        if (tlCheckFormatting.value)
+          List("scalafmtCheckAll", "project /", "scalafmtSbtCheck")
+        else
+          Nil
+
+      val checkMigrationsStep =
+        if (tlCheckMigrations.value)
+          Seq(
+            WorkflowStep.Sbt(
+              List("scalafixAll --check"),
+              name = Some("Check Scalafix migrations"),
+              cond = Some(primaryJavaCond.value)
+            )
+          )
+        else Nil
+
+      val preBuildSteps = Seq(
+        WorkflowStep.Sbt(
+          checkHeadersCommands ++ checkFormattingCommands,
+          name = Some("Check headers and formatting"),
+          cond = Some(primaryJavaCond.value)
+        )
       )
-    ),
+
+      val buildStep = Seq(
+        WorkflowStep.Sbt(List("test"), name = Some("Test"))
+      )
+
+      val postBuildSteps = checkMigrationsStep ++ Seq(
+        WorkflowStep.Sbt(
+          List("mimaReportBinaryIssues"),
+          name = Some("Check binary compatibility"),
+          cond = Some(primaryJavaCond.value)
+        ),
+        WorkflowStep.Sbt(
+          List("doc"),
+          name = Some("Generate API documentation"),
+          cond = Some(primaryJavaCond.value)
+        )
+      )
+
+      Seq(
+        preBuildSteps,
+        buildStep,
+        postBuildSteps
+      ).flatten
+    },
     githubWorkflowJavaVersions := Seq(JavaSpec.temurin("8"))
   )
 
@@ -54,5 +108,4 @@ object TypelevelCiPlugin extends AutoPlugin {
     val java = githubWorkflowJavaVersions.value.head
     s"matrix.java == '${java.render}'"
   }
-
 }

I need to take a break now though and I seem to have lost the artifact upload steps, so I think I will wait to see what your changes look like instead 😆

cond = Some(primaryJavaCond.value)
) +: githubWorkflowBuild.value
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@

package org.typelevel.sbt.gha

import sbt._, Keys._
import sbt.io.Using

import org.yaml.snakeyaml.Yaml
import sbt._
import sbt.io.Using

import scala.collection.JavaConverters._

import Keys._

object GitHubActionsPlugin extends AutoPlugin {

override def requires = plugins.JvmPlugin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@

package org.typelevel.sbt

import sbt._, Keys._
import sbt._

import scala.util.Try

import Keys._

object TypelevelGitHubPlugin extends AutoPlugin {

override def trigger = allRequirements
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@

package org.typelevel.sbt

import sbt._, Keys._
import org.scalajs.sbtplugin.ScalaJSPlugin
import com.github.sbt.git.SbtGit.git
import org.scalajs.sbtplugin.ScalaJSPlugin
import org.typelevel.sbt.kernel.GitHelper
import sbt._

import Keys._

object TypelevelScalaJSGitHubPlugin extends AutoPlugin {
override def trigger = allRequirements
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@

package org.typelevel.sbt

import sbt._, Keys._
import sbt._
import sbt.plugins.JvmPlugin

import Keys._

object TypelevelKernelPlugin extends AutoPlugin {

override def requires = JvmPlugin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@

package org.typelevel.sbt.kernel

import scala.util.Try

import scala.sys.process._
import scala.util.Try

private[sbt] object GitHelper {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@

package org.typelevel.sbt.mergify

import sbt._, Keys._
import org.typelevel.sbt.gha._
import sbt._

import java.nio.file.Path

import Keys._

object MergifyPlugin extends AutoPlugin {

object autoImport {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@

package org.typelevel.sbt

import sbt._, Keys._
import com.typesafe.tools.mima.plugin.MimaPlugin
import org.typelevel.sbt.kernel.{GitHelper, V}
import sbt._

import Keys._
import MimaPlugin.autoImport._
import org.typelevel.sbt.kernel.GitHelper
import org.typelevel.sbt.kernel.V

object TypelevelMimaPlugin extends AutoPlugin {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@

package org.typelevel.sbt

import sbt._, Keys._
import sbt._

import Keys._

object NoPublishPlugin extends AutoPlugin {
override def trigger = noTrigger
Expand Down
1 change: 1 addition & 0 deletions project/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ val modules = List(
"site",
"sonatype",
"sonatype-ci-release",
"scalafix",
"versioning"
)

Expand Down
1 change: 1 addition & 0 deletions project/scalafix.sbt
1 change: 1 addition & 0 deletions scalafix/build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.10.0")
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright 2022 Typelevel
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.typelevel.sbt

import sbt._
import scalafix.sbt.ScalafixPlugin

import Keys._
import ScalafixPlugin.autoImport._

object TypelevelScalafixPlugin extends AutoPlugin {

override def requires = ScalafixPlugin

override def trigger = allRequirements

object autoImport {}

import autoImport._

override def buildSettings = Seq[Setting[_]](
semanticdbEnabled := true,
semanticdbVersion := scalafixSemanticdb.revision,
scalafixScalaBinaryVersion := CrossVersion.binaryScalaVersion(scalaVersion.value),
scalafixDependencies ++= Seq(
"com.github.liancheng" %% "organize-imports" % "0.6.0"
)
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@

package org.typelevel.sbt

import sbt._, Keys._
import com.github.sbt.git.GitPlugin
import com.github.sbt.git.SbtGit.git
import org.typelevel.sbt.kernel.V
import org.typelevel.sbt.kernel.GitHelper
import org.typelevel.sbt.kernel.{GitHelper, V}
import sbt._

import Keys._

object TypelevelSettingsPlugin extends AutoPlugin {
override def trigger = allRequirements
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@ package org.typelevel.sbt
import laika.ast.LengthUnit._
import laika.ast._
import laika.helium.Helium
import laika.helium.config.Favicon
import laika.helium.config.HeliumIcon
import laika.helium.config.IconLink
import laika.helium.config.ImageLink
import laika.helium.config.{Favicon, HeliumIcon, IconLink, ImageLink}
import laika.sbt.LaikaPlugin
import laika.theme.ThemeProvider
import mdoc.MdocPlugin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ import cats.effect.Sync
import laika.bundle.ExtensionBundle
import laika.factory.Format
import laika.io.model.InputTree
import laika.theme.Theme
import laika.theme.ThemeProvider
import laika.theme.{Theme, ThemeProvider}

final class LaikaThemeProviderOps private[sbt] (provider: ThemeProvider) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,15 @@

package org.typelevel.sbt.site

import cats.effect.Resource
import cats.effect.Sync
import cats.effect.{Resource, Sync}
import laika.ast.Path
import laika.config.Config
import laika.io.model.InputTree
import laika.markdown.github.GitHubFlavor
import laika.parse.code.SyntaxHighlighting
import laika.parse.code.languages.DottySyntax
import laika.rewrite.DefaultTemplatePath
import laika.theme.Theme
import laika.theme.ThemeBuilder
import laika.theme.ThemeProvider
import laika.theme.{Theme, ThemeBuilder, ThemeProvider}

import java.net.URL

Expand Down
Loading