Skip to content

Commit

Permalink
Merge pull request #283 from armanbilge/feature/scalafix
Browse files Browse the repository at this point in the history
Add Scalafix integration
  • Loading branch information
armanbilge authored Jun 1, 2022
2 parents 9811d33 + df10d98 commit 235623c
Show file tree
Hide file tree
Showing 25 changed files with 142 additions and 35 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ jobs:
- name: Test
run: sbt 'project ${{ matrix.project }}' '++${{ matrix.scala }}' test

- name: Check scalafix lints
if: matrix.java == 'temurin@8'
run: sbt 'project ${{ matrix.project }}' '++${{ matrix.scala }}' 'scalafixAll --check'

- name: Check binary compatibility
if: matrix.java == 'temurin@8'
run: sbt 'project ${{ matrix.project }}' '++${{ matrix.scala }}' mimaReportBinaryIssues
Expand All @@ -86,11 +90,11 @@ jobs:

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

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

- name: Upload target directories
if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/series/0.4')
Expand Down
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
3 changes: 3 additions & 0 deletions .scalafix.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
rules = [
OrganizeImports
]
13 changes: 13 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ ThisBuild / mergifyStewardConfig ~= { _.map(_.copy(mergeMinors = true)) }
ThisBuild / mergifySuccessConditions += MergifyCondition.Custom("#approved-reviews-by>=1")
ThisBuild / mergifyLabelPaths += { "docs" -> file("docs") }

ThisBuild / scalafixDependencies ++= Seq(
"com.github.liancheng" %% "organize-imports" % "0.6.0"
)

lazy val root = tlCrossRootProject.aggregate(
kernel,
noPublish,
Expand All @@ -25,6 +29,7 @@ lazy val root = tlCrossRootProject.aggregate(
versioning,
mima,
sonatype,
scalafix,
ciSigning,
sonatypeCiRelease,
ci,
Expand Down Expand Up @@ -105,6 +110,14 @@ lazy val sonatype = project
)
.dependsOn(kernel)

lazy val scalafix = project
.in(file("scalafix"))
.enablePlugins(SbtPlugin)
.settings(
name := "sbt-typelevel-scalafix",
tlVersionIntroduced := Map("2.12" -> "0.4.10")
)

lazy val ciSigning = project
.in(file("ci-signing"))
.enablePlugins(SbtPlugin)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@
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.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`, `rootJVM`, `rootJS`, and `rootNative` project, and
Expand Down
22 changes: 18 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 com.typesafe.tools.mima.plugin.MimaPlugin
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.GitHubActionsPlugin
import sbt._

object TypelevelCiPlugin extends AutoPlugin {

Expand All @@ -34,6 +34,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 tlCiScalafixCheck =
settingKey[Boolean]("Whether to do scalafix check in CI (default: false)")
lazy val tlCiMimaBinaryIssueCheck =
settingKey[Boolean]("Whether to do MiMa binary issues check in CI (default: true)")
lazy val tlCiDocCheck =
Expand All @@ -45,6 +47,7 @@ object TypelevelCiPlugin extends AutoPlugin {
override def buildSettings = Seq(
tlCiHeaderCheck := false,
tlCiScalafmtCheck := false,
tlCiScalafixCheck := false,
tlCiMimaBinaryIssueCheck := true,
tlCiDocCheck := true,
githubWorkflowPublishTargetBranches := Seq(),
Expand Down Expand Up @@ -82,6 +85,17 @@ object TypelevelCiPlugin extends AutoPlugin {
WorkflowStep.Sbt(List("test"), name = Some("Test"))
)

val scalafix =
if (tlCiScalafixCheck.value)
List(
WorkflowStep.Sbt(
List("scalafixAll --check"),
name = Some("Check scalafix lints"),
cond = Some(primaryJavaCond.value)
)
)
else Nil

val mima =
if (tlCiMimaBinaryIssueCheck.value)
List(
Expand All @@ -103,7 +117,7 @@ object TypelevelCiPlugin extends AutoPlugin {
)
else Nil

style ++ test ++ mima ++ doc
style ++ test ++ scalafix ++ mima ++ doc
},
githubWorkflowJavaVersions := Seq(JavaSpec.temurin("8"))
)
Expand Down
6 changes: 4 additions & 2 deletions core/src/main/scala/org/typelevel/sbt/TypelevelPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@

package org.typelevel.sbt

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

import scala.collection.immutable

import Keys._

/**
* The [[TypelevelPlugin]] brings together the [[TypelevelCiReleasePlugin]] and the
* [[TypelevelSettingsPlugin]]
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.typesafe.sbt.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,13 @@

package org.typelevel.sbt

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

import Keys._
import MimaPlugin.autoImport._

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 @@ -9,6 +9,7 @@ val modules = List(
"mergify",
"mima",
"no-publish",
"scalafix",
"settings",
"site",
"sonatype",
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,36 @@
/*
* 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

override def buildSettings = Seq[Setting[_]](
semanticdbEnabled := true,
semanticdbVersion := scalafixSemanticdb.revision,
SettingKey[Boolean]("tlCiScalafixCheck") := true
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,20 @@

package org.typelevel.sbt

import sbt._, Keys._
import com.typesafe.sbt.GitPlugin
import com.typesafe.sbt.SbtGit.git
import java.io.File
import java.lang.management.ManagementFactory
import org.typelevel.sbt.kernel.V
import org.typelevel.sbt.kernel.GitHelper
import org.typelevel.sbt.kernel.V
import sbt._
import sbtcrossproject.CrossPlugin.autoImport._
import sbtcrossproject.CrossType

import java.io.File
import java.lang.management.ManagementFactory
import scala.util.Try

import Keys._

object TypelevelSettingsPlugin extends AutoPlugin {
override def trigger = allRequirements
override def requires = TypelevelKernelPlugin && GitPlugin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@

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 org.typelevel.sbt.gha.GitHubActionsPlugin
import sbt._

object TypelevelSonatypeCiReleasePlugin extends AutoPlugin {

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

package org.typelevel.sbt

import sbt._, Keys._
import com.typesafe.tools.mima.plugin.MimaPlugin
import xerial.sbt.Sonatype, Sonatype.autoImport._
import sbt._
import xerial.sbt.Sonatype

import Keys._
import Sonatype.autoImport._
import TypelevelKernelPlugin.mkCommand

object TypelevelSonatypePlugin extends AutoPlugin {
Expand Down
Loading

0 comments on commit 235623c

Please sign in to comment.