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

Update scalafmt settings #330

Merged
merged 1 commit into from
Nov 5, 2024
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
10 changes: 10 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 3 additions & 1 deletion .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
version = "2.6.2"
version = "3.8.3"
project.git = true
project.layout = StandardConvention
runner.dialect = scala212source3
Binary file removed bin/scalafmt
Binary file not shown.
34 changes: 22 additions & 12 deletions plugin/src/main/scala/com/geirsson/CiReleasePlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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.*
Expand Down Expand Up @@ -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) {
Expand All @@ -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 {
Expand All @@ -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
}
}
Expand All @@ -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
}
Expand All @@ -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")
}
Expand All @@ -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"))
Expand Down
47 changes: 37 additions & 10 deletions plugin/src/test/scala/com/geirsson/CiReleaseTest.scala
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -11,37 +11,64 @@ class CiReleaseTest extends munit.FunSuite {
}

test("Command starting with number is assumed to be a cross version") {
assertEquals(backPubVersionToCommand("[email protected]"), ";++2.12.20!;publishSigned")
assertEquals(
backPubVersionToCommand("[email protected]"),
";++2.12.20!;publishSigned"
)
assertEquals(dropBackPubCommand("[email protected]"), expectedVer)

assertEquals(backPubVersionToCommand("[email protected]"), ";++3.x;publishSigned")
assertEquals(dropBackPubCommand("[email protected]"), expectedVer)
}

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("[email protected]@foo/publishSigned"), ";++2.12.20!;foo/publishSigned")
assertEquals(dropBackPubCommand("[email protected]@foo/publishSigned"), expectedVer)
assertEquals(
backPubVersionToCommand("[email protected]@foo/publishSigned"),
";++2.12.20!;foo/publishSigned"
)
assertEquals(
dropBackPubCommand("[email protected]@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("[email protected]#comment"), ";++2.12.20!;publishSigned")
assertEquals(
backPubVersionToCommand("[email protected]#comment"),
";++2.12.20!;publishSigned"
)
assertEquals(dropBackPubCommand("[email protected]#comment"), expectedVer)

assertEquals(backPubVersionToCommand("[email protected]#comment"), ";++3.x;publishSigned")
assertEquals(
backPubVersionToCommand("[email protected]#comment"),
";++3.x;publishSigned"
)
assertEquals(dropBackPubCommand("[email protected]#comment"), expectedVer)
}
}
1 change: 1 addition & 0 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -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")