diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c5fbab1..8395e93 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,3 +14,13 @@ jobs: cache: sbt - uses: sbt/setup-sbt@v1 - run: sbt +test + format: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-java@v4 + with: + distribution: temurin + java-version: 8 + - uses: sbt/setup-sbt@v1 + - run: sbt scalafmtSbtCheck +scalafmtCheckAll diff --git a/.scalafmt.conf b/.scalafmt.conf index efb861c..c98cff8 100644 --- a/.scalafmt.conf +++ b/.scalafmt.conf @@ -1,2 +1,4 @@ -version = "2.6.2" +version = "3.8.3" project.git = true +project.layout = StandardConvention +runner.dialect = scala212source3 diff --git a/bin/scalafmt b/bin/scalafmt deleted file mode 100755 index 819ebcd..0000000 Binary files a/bin/scalafmt and /dev/null differ diff --git a/plugin/src/main/scala/com/geirsson/CiReleasePlugin.scala b/plugin/src/main/scala/com/geirsson/CiReleasePlugin.scala index 3c46d4f..9f85b0f 100644 --- a/plugin/src/main/scala/com/geirsson/CiReleasePlugin.scala +++ b/plugin/src/main/scala/com/geirsson/CiReleasePlugin.scala @@ -12,13 +12,13 @@ import java.nio.charset.StandardCharsets import java.util.Base64 import sbt.Def import sbt.Keys.* -import sbt.{ given, * } +import sbt.{given, *} import sbt.plugins.JvmPlugin import sbtdynver.DynVerPlugin import sbtdynver.DynVerPlugin.autoImport.* import scala.deprecated -import scala.sys.process.{ given, * } +import scala.sys.process.{given, *} import scala.util.control.NonFatal import xerial.sbt.Sonatype import xerial.sbt.Sonatype.autoImport.* @@ -143,14 +143,15 @@ object CiReleasePlugin extends AutoPlugin { case None => backPubVersionToCommand(v) } }, - version ~= dropBackPubCommand, + version ~= dropBackPubCommand ) override lazy val globalSettings: Seq[Def.Setting[_]] = List( (Test / publishArtifact) := false, publishMavenStyle := true, commands += Command.command("ci-release") { currentState => - val shouldDeployToSonatypeCentral = isDeploySetToSonatypeCentral(currentState) + val shouldDeployToSonatypeCentral = + isDeploySetToSonatypeCentral(currentState) val version = getVersion(currentState) val isSnapshot = isSnapshotVersion(version) if (!isSecure) { @@ -170,17 +171,22 @@ object CiReleasePlugin extends AutoPlugin { if (shouldDeployToSonatypeCentral) { if (isSnapshot) { - println(s"Sonatype Central does not accept snapshots, only official releases. Aborting release.") + println( + s"Sonatype Central does not accept snapshots, only official releases. Aborting release." + ) currentState } else if (!isTag) { - println(s"No tag published. Cannot publish an official release without a tag and Sonatype Central does not accept snapshot releases. Aborting release.") + println( + s"No tag published. Cannot publish an official release without a tag and Sonatype Central does not accept snapshot releases. Aborting release." + ) currentState } else { println("Tag push detected, publishing a stable release") reloadKeyFiles :: sys.env.getOrElse("CI_CLEAN", "; clean ; sonatypeBundleClean") :: publishCommand :: - sys.env.getOrElse("CI_SONATYPE_RELEASE", "sonatypeCentralRelease") :: + sys.env + .getOrElse("CI_SONATYPE_RELEASE", "sonatypeCentralRelease") :: currentState } } else { @@ -203,7 +209,8 @@ object CiReleasePlugin extends AutoPlugin { reloadKeyFiles :: sys.env.getOrElse("CI_CLEAN", "; clean ; sonatypeBundleClean") :: publishCommand :: - sys.env.getOrElse("CI_SONATYPE_RELEASE", "sonatypeBundleRelease") :: + sys.env + .getOrElse("CI_SONATYPE_RELEASE", "sonatypeBundleRelease") :: currentState } } @@ -220,7 +227,9 @@ object CiReleasePlugin extends AutoPlugin { ) def isDeploySetToSonatypeCentral(state: State): Boolean = { - (ThisBuild / sonatypeCredentialHost).get(Project.extract(state).structure.data) match { + (ThisBuild / sonatypeCredentialHost).get( + Project.extract(state).structure.data + ) match { case Some(value) if value == Sonatype.sonatypeCentralHost => { true } @@ -235,7 +244,9 @@ object CiReleasePlugin extends AutoPlugin { } def getPublishCommand(state: State): String = - (ThisBuild / cireleasePublishCommand).get(Project.extract(state).structure.data) match { + (ThisBuild / cireleasePublishCommand).get( + Project.extract(state).structure.data + ) match { case Some(v) => v case None => throw new NoSuchFieldError("cireleasePublishCommand") } @@ -255,8 +266,7 @@ object CiReleasePlugin extends AutoPlugin { if (!cmd.head.isDigit) { nonDigit = true cmd - } - else if (cmd.contains(".x")) s"++${cmd}" + } else if (cmd.contains(".x")) s"++${cmd}" else s"++${cmd}!" } }) ::: (if (nonDigit) Nil else List("publishSigned")) diff --git a/plugin/src/test/scala/com/geirsson/CiReleaseTest.scala b/plugin/src/test/scala/com/geirsson/CiReleaseTest.scala index 9de7c71..4973ab1 100644 --- a/plugin/src/test/scala/com/geirsson/CiReleaseTest.scala +++ b/plugin/src/test/scala/com/geirsson/CiReleaseTest.scala @@ -1,6 +1,6 @@ package com.geirsson -import CiReleasePlugin.{ backPubVersionToCommand, dropBackPubCommand } +import CiReleasePlugin.{backPubVersionToCommand, dropBackPubCommand} class CiReleaseTest extends munit.FunSuite { val expectedVer = "1.1.0" @@ -11,7 +11,10 @@ class CiReleaseTest extends munit.FunSuite { } test("Command starting with number is assumed to be a cross version") { - assertEquals(backPubVersionToCommand("1.1.0@2.12.20"), ";++2.12.20!;publishSigned") + assertEquals( + backPubVersionToCommand("1.1.0@2.12.20"), + ";++2.12.20!;publishSigned" + ) assertEquals(dropBackPubCommand("1.1.0@2.12.20"), expectedVer) assertEquals(backPubVersionToCommand("1.1.0@3.x"), ";++3.x;publishSigned") @@ -19,29 +22,53 @@ class CiReleaseTest extends munit.FunSuite { } test("Non-number is treated as an alternative publish command") { - assertEquals(backPubVersionToCommand("1.1.0@foo/publishSigned"), "foo/publishSigned") + assertEquals( + backPubVersionToCommand("1.1.0@foo/publishSigned"), + "foo/publishSigned" + ) assertEquals(dropBackPubCommand("1.1.0@foo/publishSigned"), expectedVer) - assertEquals(backPubVersionToCommand("1.1.0@+foo/publishSigned"), "+foo/publishSigned") + assertEquals( + backPubVersionToCommand("1.1.0@+foo/publishSigned"), + "+foo/publishSigned" + ) assertEquals(dropBackPubCommand("1.1.0@+foo/publishSigned"), expectedVer) } test("Commands can be chained") { - assertEquals(backPubVersionToCommand("1.1.0@2.12.20@foo/publishSigned"), ";++2.12.20!;foo/publishSigned") - assertEquals(dropBackPubCommand("1.1.0@2.12.20@foo/publishSigned"), expectedVer) + assertEquals( + backPubVersionToCommand("1.1.0@2.12.20@foo/publishSigned"), + ";++2.12.20!;foo/publishSigned" + ) + assertEquals( + dropBackPubCommand("1.1.0@2.12.20@foo/publishSigned"), + expectedVer + ) - assertEquals(backPubVersionToCommand("1.1.0@foo/something@bar/publishSigned"), ";foo/something;bar/publishSigned") - assertEquals(dropBackPubCommand("1.1.0@foo/something@bar/publishSigned"), expectedVer) + assertEquals( + backPubVersionToCommand("1.1.0@foo/something@bar/publishSigned"), + ";foo/something;bar/publishSigned" + ) + assertEquals( + dropBackPubCommand("1.1.0@foo/something@bar/publishSigned"), + expectedVer + ) } test("Treat # as comments") { assertEquals(backPubVersionToCommand("1.1.0#comment"), "+publishSigned") assertEquals(dropBackPubCommand("1.1.0#comment"), expectedVer) - assertEquals(backPubVersionToCommand("1.1.0@2.12.20#comment"), ";++2.12.20!;publishSigned") + assertEquals( + backPubVersionToCommand("1.1.0@2.12.20#comment"), + ";++2.12.20!;publishSigned" + ) assertEquals(dropBackPubCommand("1.1.0@2.12.20#comment"), expectedVer) - assertEquals(backPubVersionToCommand("1.1.0@3.x#comment"), ";++3.x;publishSigned") + assertEquals( + backPubVersionToCommand("1.1.0@3.x#comment"), + ";++3.x;publishSigned" + ) assertEquals(dropBackPubCommand("1.1.0@3.x#comment"), expectedVer) } } diff --git a/project/plugins.sbt b/project/plugins.sbt index b8ae257..0e82c04 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -8,3 +8,4 @@ addSbtPlugin("com.github.sbt" % "sbt-dynver" % "5.0.1") addSbtPlugin("com.github.sbt" % "sbt-git" % "2.1.0") addSbtPlugin("com.github.sbt" % "sbt-pgp" % "2.3.0") addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "3.12.2") +addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.2")