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

Release workflow v3 #183

Merged
merged 6 commits into from
Feb 11, 2025
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
24 changes: 9 additions & 15 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions .scalafix.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
rules = [OrganizeImports]

OrganizeImports {
preset = INTELLIJ_2020_3
targetDialect = Auto
}
2 changes: 2 additions & 0 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
version = "3.8.6"
runner.dialect = scala213
17 changes: 11 additions & 6 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ 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

Compile / unmanagedSourceDirectories += {
if (scalaVersion.value startsWith "2")
Expand Down Expand Up @@ -61,9 +63,12 @@ developers := List(

publishTo := Some(Resolver.evolutionReleases)

releaseCrossBuild := true

//addCommandAlias("check", "all versionPolicyCheck Compile/doc")
addCommandAlias("check", "show version")
addCommandAlias(
"fmt",
"all scalafmtAll scalafmtSbt; scalafixEnable; scalafixAll"
)
addCommandAlias(
"check",
"all versionPolicyCheck Compile/doc scalafmtCheckAll scalafmtSbtCheck; scalafixEnable; scalafixAll --check"
)
addCommandAlias("build", "+all compile test")

4 changes: 2 additions & 2 deletions project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=1.9.9
sbt.version=1.10.7
8 changes: 7 additions & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@ addSbtPlugin("org.scoverage" % "sbt-scoverage" % "2.0.8")

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")
24 changes: 12 additions & 12 deletions src/main/scala-2/com/evolutiongaming/random/Random.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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] {
Expand All @@ -38,7 +36,6 @@ object Random {
}
}


type SeedT[A] = cats.data.StateT[Id, Seed, A]

object SeedT {
Expand All @@ -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)
}
}
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/com/evolutiongaming/random/SeedOf.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/test/scala/com/evolutiongaming/random/RandomSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ 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
}

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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down