From 01df1b1e46b2d53404f66a9cbf7aa3183aaadbac Mon Sep 17 00:00:00 2001 From: Ruslans Tarasovs Date: Tue, 11 Feb 2025 15:26:00 +0200 Subject: [PATCH 1/6] Migrate to latest release workflow. --- .github/workflows/release.yml | 12 ++++++------ .scalafix.conf | 6 ++++++ .scalafmt.conf | 2 ++ build.sbt | 7 +++---- project/build.properties | 2 +- project/plugins.sbt | 10 ++++++++-- 6 files changed, 26 insertions(+), 13 deletions(-) create mode 100644 .scalafix.conf create mode 100644 .scalafmt.conf diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index a8a2f2b..e95abaf 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,11 +1,11 @@ -name: Publish new Release +name: Publish Release on: - release: - types: [published] - branches: [master] + push: + tags: + - 'v*' jobs: release: - uses: evolution-gaming/scala-github-actions/.github/workflows/release.yml@v1 - secrets: inherit + uses: evolution-gaming/scala-github-actions/.github/workflows/release.yml@v3 + secrets: inherit \ No newline at end of file diff --git a/.scalafix.conf b/.scalafix.conf new file mode 100644 index 0000000..3d1bd2d --- /dev/null +++ b/.scalafix.conf @@ -0,0 +1,6 @@ +rules = [OrganizeImports] + +OrganizeImports { + preset = INTELLIJ_2020_3 + targetDialect = Auto +} \ No newline at end of file diff --git a/.scalafmt.conf b/.scalafmt.conf new file mode 100644 index 0000000..3d742f8 --- /dev/null +++ b/.scalafmt.conf @@ -0,0 +1,2 @@ +version = "3.8.6" +runner.dialect = scala213 \ No newline at end of file diff --git a/build.sbt b/build.sbt index 02fe5ea..7c4bab2 100644 --- a/build.sbt +++ b/build.sbt @@ -16,6 +16,8 @@ scalaVersion := crossScalaVersions.value.head crossScalaVersions := Seq("2.13.11", "2.12.18", "3.3.0") +versionPolicyIntention := Compatibility.BinaryCompatible + Compile / unmanagedSourceDirectories += { if (scalaVersion.value startsWith "2") sourceDirectory.value / "main" / "scala-2" @@ -61,9 +63,6 @@ developers := List( publishTo := Some(Resolver.evolutionReleases) -releaseCrossBuild := true - -//addCommandAlias("check", "all versionPolicyCheck Compile/doc") -addCommandAlias("check", "show version") +addCommandAlias("check", "all versionPolicyCheck Compile/doc scalafmtCheckAll scalafmtSbtCheck; scalafixEnable; scalafixAll --check") addCommandAlias("build", "+all compile test") diff --git a/project/build.properties b/project/build.properties index 04267b1..0a832a2 100644 --- a/project/build.properties +++ b/project/build.properties @@ -1 +1 @@ -sbt.version=1.9.9 +sbt.version=1.10.7 \ No newline at end of file diff --git a/project/plugins.sbt b/project/plugins.sbt index 5ed2424..9b288ca 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -1,9 +1,15 @@ -addSbtPlugin("org.scoverage" % "sbt-scoverage" % "2.0.8") +addSbtPlugin("org.scoverage" % "sbt-scoverage" % "2.3.0") addSbtPlugin("org.scoverage" % "sbt-coveralls" % "1.3.15") -addSbtPlugin("com.github.sbt" % "sbt-release" % "1.4.0") +addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.14.0") + +addSbtPlugin("ch.epfl.scala" % "sbt-version-policy" % "3.2.1") addSbtPlugin("com.evolution" % "sbt-scalac-opts-plugin" % "0.0.9") addSbtPlugin("com.evolution" % "sbt-artifactory-plugin" % "0.0.2") + +addSbtPlugin("com.github.sbt" % "sbt-dynver" % "5.1.0") + +addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.4") \ No newline at end of file From c0576f2fa60ab1b49fd59cfd17c0c757509318d1 Mon Sep 17 00:00:00 2001 From: Ruslans Tarasovs Date: Tue, 11 Feb 2025 15:30:00 +0200 Subject: [PATCH 2/6] Fixed scala version. --- build.sbt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.sbt b/build.sbt index 7c4bab2..d7d806f 100644 --- a/build.sbt +++ b/build.sbt @@ -14,7 +14,7 @@ organizationHomepage := Some(url("https://evolution.com")) scalaVersion := crossScalaVersions.value.head -crossScalaVersions := Seq("2.13.11", "2.12.18", "3.3.0") +crossScalaVersions := Seq("2.13.11", "2.12.18", "3.3.5") versionPolicyIntention := Compatibility.BinaryCompatible From fe7559bf43f5c99242b2e378ade50c859e9fff56 Mon Sep 17 00:00:00 2001 From: Ruslans Tarasovs Date: Tue, 11 Feb 2025 15:37:04 +0200 Subject: [PATCH 3/6] Show evicted dependencies. --- build.sbt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.sbt b/build.sbt index d7d806f..15d967c 100644 --- a/build.sbt +++ b/build.sbt @@ -64,5 +64,5 @@ developers := List( publishTo := Some(Resolver.evolutionReleases) addCommandAlias("check", "all versionPolicyCheck Compile/doc scalafmtCheckAll scalafmtSbtCheck; scalafixEnable; scalafixAll --check") -addCommandAlias("build", "+all compile test") +addCommandAlias("build", "+all evicted compile test") From f9be38a61809be8db72d1f889dff22e0d4a35d93 Mon Sep 17 00:00:00 2001 From: Ruslans Tarasovs Date: Tue, 11 Feb 2025 15:46:18 +0200 Subject: [PATCH 4/6] Update CI according to workflow --- .github/workflows/ci.yml | 24 +++++++++--------------- build.sbt | 2 +- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5edead4..32fb3cb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,15 +1,6 @@ name: CI -on: - push: - branches: ["master"] - tags: ["v*"] - pull_request: - branches: ["master"] - workflow_dispatch: - -permissions: - contents: read +on: [push, pull_request] jobs: test: @@ -24,29 +15,32 @@ jobs: - 2.12.18 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: coursier/cache-action@v6 - name: Setup Java - uses: actions/setup-java@v3 + uses: actions/setup-java@v4 with: java-version: "17" - distribution: "temurin" + distribution: "oracle" cache: "sbt" - name: setup SBT uses: sbt/setup-sbt@v1 + - name: Check code formatting + run: sbt clean check + - name: build ${{ matrix.scala }} run: sbt ++${{ matrix.scala }} clean coverage test - name: test coverage - if: success() && matrix.scala != '3.3.0' + if: success() + run: sbt ++${{ matrix.scala }} coverageAggregate coveralls env: COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }} COVERALLS_FLAG_NAME: Scala ${{ matrix.scala }} - run: sbt ++${{ matrix.scala }} coverageReport coverageAggregate coveralls - name: slack uses: homoluctus/slatify@master diff --git a/build.sbt b/build.sbt index 15d967c..d7d806f 100644 --- a/build.sbt +++ b/build.sbt @@ -64,5 +64,5 @@ developers := List( publishTo := Some(Resolver.evolutionReleases) addCommandAlias("check", "all versionPolicyCheck Compile/doc scalafmtCheckAll scalafmtSbtCheck; scalafixEnable; scalafixAll --check") -addCommandAlias("build", "+all evicted compile test") +addCommandAlias("build", "+all compile test") From 888d4ce1fbe8aa8cf50addc26e9cb29313cdf6df Mon Sep 17 00:00:00 2001 From: Ruslans Tarasovs Date: Tue, 11 Feb 2025 15:57:17 +0200 Subject: [PATCH 5/6] Downgrade a library to use older Scala version. --- project/plugins.sbt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project/plugins.sbt b/project/plugins.sbt index 9b288ca..ac9a4bf 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -1,4 +1,4 @@ -addSbtPlugin("org.scoverage" % "sbt-scoverage" % "2.3.0") +addSbtPlugin("org.scoverage" % "sbt-scoverage" % "2.0.8") addSbtPlugin("org.scoverage" % "sbt-coveralls" % "1.3.15") From eacbc1e866b38dabcbe34e44bd0950c171a4de24 Mon Sep 17 00:00:00 2001 From: Ruslans Tarasovs Date: Tue, 11 Feb 2025 16:11:27 +0200 Subject: [PATCH 6/6] Fix formatting. --- build.sbt | 10 ++++++-- project/Dependencies.scala | 4 ++-- project/plugins.sbt | 2 +- .../com/evolutiongaming/random/Random.scala | 24 +++++++++---------- .../random/RandomStateOf.scala | 4 +++- .../com/evolutiongaming/random/SeedOf.scala | 2 +- .../evolutiongaming/random/RandomSpec.scala | 4 ++-- .../random/RandomStateOfTest.scala | 10 ++++---- 8 files changed, 34 insertions(+), 26 deletions(-) diff --git a/build.sbt b/build.sbt index d7d806f..4bb3717 100644 --- a/build.sbt +++ b/build.sbt @@ -63,6 +63,12 @@ developers := List( publishTo := Some(Resolver.evolutionReleases) -addCommandAlias("check", "all versionPolicyCheck Compile/doc scalafmtCheckAll scalafmtSbtCheck; scalafixEnable; scalafixAll --check") +addCommandAlias( + "fmt", + "all scalafmtAll scalafmtSbt; scalafixEnable; scalafixAll" +) +addCommandAlias( + "check", + "all versionPolicyCheck Compile/doc scalafmtCheckAll scalafmtSbtCheck; scalafixEnable; scalafixAll --check" +) addCommandAlias("build", "+all compile test") - diff --git a/project/Dependencies.scala b/project/Dependencies.scala index d78fb68..ce54af5 100644 --- a/project/Dependencies.scala +++ b/project/Dependencies.scala @@ -3,11 +3,11 @@ import sbt._ object Dependencies { val `cats-helper` = "com.evolutiongaming" %% "cats-helper" % "3.7.0" - val scalatest = "org.scalatest" %% "scalatest" % "3.2.19" + val scalatest = "org.scalatest" %% "scalatest" % "3.2.19" object Cats { private val version = "2.9.0" - val core = "org.typelevel" %% "cats-core" % version + val core = "org.typelevel" %% "cats-core" % version } object CatsEffect { diff --git a/project/plugins.sbt b/project/plugins.sbt index ac9a4bf..58af23b 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -12,4 +12,4 @@ addSbtPlugin("com.evolution" % "sbt-artifactory-plugin" % "0.0.2") addSbtPlugin("com.github.sbt" % "sbt-dynver" % "5.1.0") -addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.4") \ No newline at end of file +addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.4") diff --git a/src/main/scala-2/com/evolutiongaming/random/Random.scala b/src/main/scala-2/com/evolutiongaming/random/Random.scala index 46991eb..6902dfc 100644 --- a/src/main/scala-2/com/evolutiongaming/random/Random.scala +++ b/src/main/scala-2/com/evolutiongaming/random/Random.scala @@ -20,10 +20,8 @@ object Random { type Seed = Long - def apply[F[_]](implicit F: Random[F]): Random[F] = F - implicit class RandomOps[F[_]](val self: Random[F]) extends AnyVal { def mapK[G[_]](f: F ~> G): Random[G] = new Random[G] { @@ -38,7 +36,6 @@ object Random { } } - type SeedT[A] = cats.data.StateT[Id, Seed, A] object SeedT { @@ -52,7 +49,7 @@ object Random { def next(bits: Int): SeedT[Int] = { SeedT { seed => val r = (seed >>> (48 - bits)).toInt - val s1 = (seed * 0x5DEECE66DL + 0xBL) & ((1L << 48) - 1) + val s1 = (seed * 0x5deece66dL + 0xbL) & ((1L << 48) - 1) (s1, r) } } @@ -64,7 +61,7 @@ object Random { def long = { for { a0 <- next(32) - a1 = a0.toLong << 32 + a1 = a0.toLong << 32 a2 <- next(32) } yield { a1 + a2 @@ -82,7 +79,7 @@ object Random { def double = { for { a0 <- next(26) - a1 = a0.toLong << 27 + a1 = a0.toLong << 27 a2 <- next(27) } yield { (a1 + a2) * doubleUnit @@ -91,12 +88,12 @@ object Random { } } - - def apply[A](f: Seed => (Seed, A)): SeedT[A] = cats.data.StateT[Id, Seed, A] { seed => f(seed) } + def apply[A](f: Seed => (Seed, A)): SeedT[A] = + cats.data.StateT[Id, Seed, A] { seed => f(seed) } } - - final case class State(seed: Seed, random: Random[SeedT] = SeedT.Random) extends Random[State.Type] { + final case class State(seed: Seed, random: Random[SeedT] = SeedT.Random) + extends Random[State.Type] { private def apply[A](stateT: SeedT[A]) = { val (seed1, a) = stateT.run(seed) @@ -116,11 +113,14 @@ object Random { type Type[A] = (State, A) - def fromClock[F[_]: Clock: FlatMap](random: Random[SeedT] = SeedT.Random): F[State] = { + def fromClock[F[_]: Clock: FlatMap]( + random: Random[SeedT] = SeedT.Random + ): F[State] = { for { nanos <- Clock[F].nanos } yield { - val seed = (nanos ^ 3447679086515839964L ^ 0x5DEECE66DL) & ((1L << 48) - 1) + val seed = + (nanos ^ 3447679086515839964L ^ 0x5deece66dL) & ((1L << 48) - 1) apply(seed, random) } } diff --git a/src/main/scala/com/evolutiongaming/random/RandomStateOf.scala b/src/main/scala/com/evolutiongaming/random/RandomStateOf.scala index 8b43c65..ab8be14 100644 --- a/src/main/scala/com/evolutiongaming/random/RandomStateOf.scala +++ b/src/main/scala/com/evolutiongaming/random/RandomStateOf.scala @@ -17,7 +17,9 @@ object RandomStateOf { .map { seedOf => new Main with RandomStateOf[F] { def apply() = { - seedOf().map { seed => Random.State((seed ^ 0x5DEECE66DL) & ((1L << 48) - 1)) } + seedOf().map { seed => + Random.State((seed ^ 0x5deece66dL) & ((1L << 48) - 1)) + } } } } diff --git a/src/main/scala/com/evolutiongaming/random/SeedOf.scala b/src/main/scala/com/evolutiongaming/random/SeedOf.scala index bc1aa03..395965e 100644 --- a/src/main/scala/com/evolutiongaming/random/SeedOf.scala +++ b/src/main/scala/com/evolutiongaming/random/SeedOf.scala @@ -18,7 +18,7 @@ object SeedOf { new FromClock with SeedOf[F] { def apply() = { for { - nanos <- Clock[F].nanos + nanos <- Clock[F].nanos uniquifier <- ref.updateAndGet { _ * 1181783497276652981L } } yield { nanos ^ uniquifier diff --git a/src/test/scala/com/evolutiongaming/random/RandomSpec.scala b/src/test/scala/com/evolutiongaming/random/RandomSpec.scala index 645f738..8a042e0 100644 --- a/src/test/scala/com/evolutiongaming/random/RandomSpec.scala +++ b/src/test/scala/com/evolutiongaming/random/RandomSpec.scala @@ -27,7 +27,7 @@ class RandomSpec extends AnyFunSuite with Matchers { test("float") { random.float shouldEqual random.float val (random1, a0) = random.float - a0 shouldEqual 4.172325E-7f + a0 shouldEqual 4.172325e-7f val (_, a1) = random1.float a1 shouldEqual 0.4238568f } @@ -35,7 +35,7 @@ class RandomSpec extends AnyFunSuite with Matchers { test("double") { random.double shouldEqual random.double val (random1, a0) = random.double - a0 shouldEqual 4.3844963359962463E-7 + a0 shouldEqual 4.3844963359962463e-7 val (_, a1) = random1.double a1 shouldEqual 0.2843758208196805 } diff --git a/src/test/scala/com/evolutiongaming/random/RandomStateOfTest.scala b/src/test/scala/com/evolutiongaming/random/RandomStateOfTest.scala index 7ac94ab..ca3fc25 100644 --- a/src/test/scala/com/evolutiongaming/random/RandomStateOfTest.scala +++ b/src/test/scala/com/evolutiongaming/random/RandomStateOfTest.scala @@ -12,11 +12,11 @@ class RandomStateOfTest extends AsyncFunSuite with Matchers { test("RandomStateOf") { val result = for { randomStateOf <- RandomStateOf.of[IO] - random <- randomStateOf() - ref <- Ref[IO].of(random) - value = ref.modify { _.double } - values <- List.fill(1000)(value).sequence - _ <- IO { + random <- randomStateOf() + ref <- Ref[IO].of(random) + value = ref.modify { _.double } + values <- List.fill(1000)(value).sequence + _ <- IO { values.foreach { value => value should be <= 1.0 value should be >= 0.0