From f468514575d12cdd31404533338465aa6fef63bf Mon Sep 17 00:00:00 2001 From: Adam Rosien Date: Tue, 20 Jul 2021 14:56:08 -0700 Subject: [PATCH 1/9] Update link to microsite to point to davenverse. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 23f350a..e358649 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # keysemaphore - Keyed Semaphores [![Build Status](https://travis-ci.com/ChristopherDavenport/keysemaphore.svg?branch=master)](https://travis-ci.com/ChristopherDavenport/keysemaphore) [![Maven Central](https://maven-badges.herokuapp.com/maven-central/io.chrisdavenport/keysemaphore_2.12/badge.svg)](https://maven-badges.herokuapp.com/maven-central/io.chrisdavenport/keysemaphore_2.12) ![Code of Consuct](https://img.shields.io/badge/Code%20of%20Conduct-Scala-blue.svg) -## [Head on over to the microsite](https://ChristopherDavenport.github.io/keysemaphore) +## [Head on over to the microsite](https://davenverse.github.io/keysemaphore) ## Quick Start From 3fda7996766897659e2cbf16bfa9ec1b9694cbbf Mon Sep 17 00:00:00 2001 From: Anthony Ascencio Date: Wed, 28 Jul 2021 23:03:18 +0000 Subject: [PATCH 2/9] tests, tut -> mdoc --- .scalafmt.conf | 2 +- .travis.yml | 4 +- build.sbt | 13 +-- .../keysemaphore/KeySemaphoreSpec.scala | 94 +++++++++---------- docs/{src/main/tut => }/index.md | 4 +- project/plugins.sbt | 5 +- 6 files changed, 56 insertions(+), 66 deletions(-) rename docs/{src/main/tut => }/index.md (98%) diff --git a/.scalafmt.conf b/.scalafmt.conf index 136118a..f474826 100644 --- a/.scalafmt.conf +++ b/.scalafmt.conf @@ -16,7 +16,7 @@ align { openParenCallSite = false openParenDefnSite = false - tokens = ["%", "%%"] + tokens = ["%", "%%", "%%%"] } docstrings.style = Asterisk diff --git a/.travis.yml b/.travis.yml index 8c95abf..0100308 100644 --- a/.travis.yml +++ b/.travis.yml @@ -31,7 +31,7 @@ jobs: # script: sbt +mimaReportBinaryIssues - name: docs - scala: 2.12.14 + scala: 2.13.6 install: - rvm use 2.6.0 --install --fuzzy - gem update --system @@ -45,7 +45,7 @@ jobs: - sbt ci-release - stage: release name: microsite - scala: 2.12.14 + scala: 2.13.6 install: - rvm use 2.6.0 --install --fuzzy - gem update --system diff --git a/build.sbt b/build.sbt index 056e0b0..d8a0576 100644 --- a/build.sbt +++ b/build.sbt @@ -17,7 +17,6 @@ lazy val docs = project.in(file("docs")) .dependsOn(core) .disablePlugins(MimaPlugin) .enablePlugins(MicrositesPlugin) - .enablePlugins(TutPlugin) .settings(publish / skip := true) .settings{ import microsites._ @@ -41,7 +40,6 @@ lazy val docs = project.in(file("docs")) "gray-lighter" -> "#F4F3F4", "white-color" -> "#FFFFFF" ), - tut / fork := true, scalacOptions --= Seq( "-Xfatal-warnings", "-Ywarn-unused-import", @@ -61,22 +59,19 @@ lazy val docs = project.in(file("docs")) } val catsV = "2.6.1" -val catsEffectV = "3.1.1" -val specs2V = "4.12.3" +val catsEffectV = "3.2.0" +val munitCatsEffectV = "1.0.5" val kindProjectorV = "0.13.0" // General Settings lazy val commonSettings = Seq( scalaVersion := "2.13.6", crossScalaVersions := Seq(scalaVersion.value, "2.12.14"), - - addCompilerPlugin("org.typelevel" % "kind-projector" % kindProjectorV cross CrossVersion.full), libraryDependencies ++= Seq( "org.typelevel" %% "cats-core" % catsV, "org.typelevel" %% "cats-effect" % catsEffectV, - "org.specs2" %% "specs2-core" % specs2V % Test, - "org.specs2" %% "specs2-scalacheck" % specs2V % Test - ) ++ + "org.typelevel" %%% "munit-cats-effect-3" % munitCatsEffectV % Test + ) ++ // format: off (if (scalaVersion.value.startsWith("2")) Seq(compilerPlugin("org.typelevel" %% "kind-projector" % kindProjectorV).cross(CrossVersion.full)) diff --git a/core/src/test/scala/io/chrisdavenport/keysemaphore/KeySemaphoreSpec.scala b/core/src/test/scala/io/chrisdavenport/keysemaphore/KeySemaphoreSpec.scala index 71bf88b..8a11153 100644 --- a/core/src/test/scala/io/chrisdavenport/keysemaphore/KeySemaphoreSpec.scala +++ b/core/src/test/scala/io/chrisdavenport/keysemaphore/KeySemaphoreSpec.scala @@ -1,58 +1,54 @@ package io.chrisdavenport.keysemaphore -import org.specs2.mutable.Specification -import cats.effect._ -import scala.concurrent.ExecutionContext.global +import cats.effect.IO +import munit.CatsEffectSuite -class KeySemaphoreSpec extends Specification { - "KeySemaphore" should { - "only take the maximum values per key" in { - implicit val CS = IO.contextShift(global) - val test = for { - sem <- KeySemaphore.of[IO, Unit]{_: Unit => 1L} - first <- sem(()).tryAcquire - second <- sem(()).tryAcquire - } yield (first, second) - test.unsafeRunSync() must_=== ((true, false)) - } +class KeySemaphoreSpec extends CatsEffectSuite { + test("only take the maximum values per key") { + val test = for { + sem <- KeySemaphore.of[IO, Unit]{_: Unit => 1L} + first <- sem(()).tryAcquire + second <- sem(()).tryAcquire + } yield (first, second) + val expected = (true, false) + assertIO(expected, test) + } - "not be affected by other keys" in { - implicit val CS = IO.contextShift(global) - val test = for { - sem <- KeySemaphore.of[IO, Int]{_: Int => 1L} - first <- sem(1).tryAcquire - second <- sem(2).tryAcquire - third <- sem(1).tryAcquire - } yield (first, second, third) - test.unsafeRunSync() must_=== ((true, true, false)) - } + test("not be affected by other keys") { + val test = for { + sem <- KeySemaphore.of[IO, Int]{_: Int => 1L} + first <- sem(1).tryAcquire + second <- sem(2).tryAcquire + third <- sem(1).tryAcquire + } yield (first, second, third) + val expected = (true, true, false) + assertIO(expected, test) + } - "restore on finished" in { - implicit val CS = IO.contextShift(global) - val test = for { - sem <- KeySemaphore.of[IO, Int]{_: Int => 1L} - first <- sem(1).tryAcquire - second <- sem(1).tryAcquire - _ <- sem(1).release - third <- sem(1).tryAcquire - } yield (first, second, third) - test.unsafeRunSync() must_=== ((true,false, true)) - } + test("restore on finished") { + val test = for { + sem <- KeySemaphore.of[IO, Int]{_: Int => 1L} + first <- sem(1).tryAcquire + second <- sem(1).tryAcquire + _ <- sem(1).release + third <- sem(1).tryAcquire + } yield (first, second, third) + val expected = (true, false, true) + assertIO(expected, test) + } - "not allow more than the key" in { - implicit val CS = IO.contextShift(global) - val test = for { - sem <- KeySemaphore.of[IO, Int]{_: Int => 1L} - first <- sem(1).tryAcquire - _ <- sem(1).releaseN(10) - second <- sem(1).tryAcquire - third <- sem(1).tryAcquire - } yield (first, second, third) - test.unsafeRunSync() must_=== ((true, true, false)) - } + test("not allow more than the key") { + val test = for { + sem <- KeySemaphore.of[IO, Int]{_: Int => 1L} + first <- sem(1).tryAcquire + _ <- sem(1).releaseN(10) + second <- sem(1).tryAcquire + third <- sem(1).tryAcquire + } yield (first, second, third) + val expected = (true, true, false) + assertIO(expected, test) } - // def printState(sem: KeySemaphore.AbstractKeySemaphore[IO, _]): IO[Unit] = + // def printState(sem: KeySemaphore.AbstractKeySemaphore[IO, _]): IO[Unit] = // sem.getState.flatMap(st => IO.delay(println(st))) - -} \ No newline at end of file +} diff --git a/docs/src/main/tut/index.md b/docs/index.md similarity index 98% rename from docs/src/main/tut/index.md rename to docs/index.md index 1df62ec..5cb7936 100644 --- a/docs/src/main/tut/index.md +++ b/docs/index.md @@ -20,7 +20,7 @@ libraryDependencies ++= Seq( Quick Imports -```tut:silent +```scala mdoc:silent import cats.effect._ import io.chrisdavenport.keysemaphore.KeySemaphore implicit val CS = IO.contextShift(scala.concurrent.ExecutionContext.global) @@ -28,7 +28,7 @@ implicit val CS = IO.contextShift(scala.concurrent.ExecutionContext.global) Then we build some operations -```tut +```scala mdoc // Second Action Can't Get Permit val action1 = { for { diff --git a/project/plugins.sbt b/project/plugins.sbt index 2612eac..f1707ae 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -1,9 +1,8 @@ -addSbtPlugin("com.geirsson" % "sbt-ci-release" % "1.5.7") addSbtPlugin("io.github.davidgregory084" % "sbt-tpolecat" % "0.1.20") +addSbtPlugin("com.geirsson" % "sbt-ci-release" % "1.5.7") addSbtPlugin("com.typesafe" % "sbt-mima-plugin" % "0.9.2") -addSbtPlugin("org.tpolecat" % "tut-plugin" % "0.6.13") addSbtPlugin("com.47deg" % "sbt-microsites" % "1.3.4") -addSbtPlugin("com.typesafe.sbt" % "sbt-ghpages" % "0.6.3") addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % "1.1.0") addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.6.0") addSbtPlugin("io.chrisdavenport" % "sbt-mima-version-check" % "0.1.2") +addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.4.3") From 76ecb32ed4d293ce8491f44cc33161fc2030cb74 Mon Sep 17 00:00:00 2001 From: Christopher Davenport Date: Tue, 3 Aug 2021 21:06:16 -0700 Subject: [PATCH 3/9] Update Build --- .gitignore | 3 +- .travis.yml | 58 ---------- build.sbt | 109 ++++-------------- .../keysemaphore/KeySemaphoreSpec.scala | 8 +- project/build.properties | 2 +- project/plugins.sbt | 11 +- {docs/src/main/tut => site/docs}/index.md | 6 +- 7 files changed, 34 insertions(+), 163 deletions(-) delete mode 100644 .travis.yml rename {docs/src/main/tut => site/docs}/index.md (77%) diff --git a/.gitignore b/.gitignore index e620014..86a261c 100644 --- a/.gitignore +++ b/.gitignore @@ -8,4 +8,5 @@ tags .bloop .metals -project/metals.sbt \ No newline at end of file +metals.sbt +.vscode \ No newline at end of file diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index ebc06e2..0000000 --- a/.travis.yml +++ /dev/null @@ -1,58 +0,0 @@ -sudo: false -language: scala - -jdk: - - openjdk11 - -before_install: - - git fetch --tags - - export PATH=${PATH}:./vendor/bundle - -stages: - - name: test - - name: release - if: ((branch = master AND type = push) OR (tag IS present)) AND NOT fork - - -jobs: - include: - # stage="test" if no stage is specified - - - name: test 2.13 - scala: 2.13.0 - script: sbt ++$TRAVIS_SCALA_VERSION test - - name: test 2.12 - scala: 2.12.9 - script: sbt ++$TRAVIS_SCALA_VERSION test - # - - # name: mima - # script: sbt +mimaReportBinaryIssues - - - name: docs - scala: 2.12.9 - install: - - rvm use 2.6.0 --install --fuzzy - - gem update --system - - gem install sass - - gem install jekyll -v 3.2.1 - script: sbt ++$TRAVIS_SCALA_VERSION docs/makeMicrosite - # run ci-release only if previous stages passed - - stage: release - name: release - script: - - sbt ci-release - - stage: release - name: microsite - scala: 2.12.9 - install: - - rvm use 2.6.0 --install --fuzzy - - gem update --system - - gem install sass - - gem install jekyll -v 3.2.1 - script: sbt ++$TRAVIS_SCALA_VERSION docs/publishMicrosite - -cache: - directories: - - $HOME/.ivy2/cache - - $HOME/.coursier/cache - - $HOME/.sbt \ No newline at end of file diff --git a/build.sbt b/build.sbt index b971ace..24e0a67 100644 --- a/build.sbt +++ b/build.sbt @@ -1,102 +1,37 @@ import sbtcrossproject.CrossPlugin.autoImport.{crossProject, CrossType} +val catsV = "2.6.1" +val catsEffectV = "2.5.2" +val specs2V = "4.12.3" + +ThisBuild / crossScalaVersions := Seq("2.12.14", "2.13.6", "3.0.1") + lazy val `keysemaphore` = project.in(file(".")) .disablePlugins(MimaPlugin) - .settings(skip in publish := true) - .aggregate(core, docs) + .enablePlugins(NoPublishPlugin) + .aggregate(core.jvm, core.js, docs) -lazy val core = project.in(file("core")) +lazy val core = crossProject(JSPlatform, JVMPlatform) + .crossType(CrossType.Pure).in(file("core")) .disablePlugins(MimaPlugin) - .settings(commonSettings) .settings( - name := "keysemaphore" + name := "keysemaphore", + libraryDependencies ++= Seq( + "org.typelevel" %%% "cats-core" % catsV, + "org.typelevel" %%% "cats-effect" % catsEffectV, + + ("org.specs2" %%% "specs2-core" % specs2V % Test).cross(CrossVersion.for3Use2_13), + ("org.specs2" %%% "specs2-scalacheck" % specs2V % Test).cross(CrossVersion.for3Use2_13) + ) ) lazy val docs = project.in(file("docs")) - .settings(commonSettings) - .dependsOn(core) + .dependsOn(core.jvm) .disablePlugins(MimaPlugin) - .enablePlugins(MicrositesPlugin) - .enablePlugins(TutPlugin) - .settings(skip in publish := true) + .enablePlugins(NoPublishPlugin) + .enablePlugins(DavenverseMicrositePlugin) .settings{ - import microsites._ - Seq( - micrositeName := "keysemaphore", - micrositeDescription := "Keyed Semaphores", - micrositeAuthor := "Christopher Davenport", - micrositeGithubOwner := "ChristopherDavenport", - micrositeGithubRepo := "keysemaphore", - micrositeBaseUrl := "/keysemaphore", - micrositeDocumentationUrl := "https://www.javadoc.io/doc/io.chrisdavenport/keysemaphore_2.12", - micrositeFooterText := None, - micrositeHighlightTheme := "atom-one-light", - micrositePalette := Map( - "brand-primary" -> "#3e5b95", - "brand-secondary" -> "#294066", - "brand-tertiary" -> "#2d5799", - "gray-dark" -> "#49494B", - "gray" -> "#7B7B7E", - "gray-light" -> "#E5E5E6", - "gray-lighter" -> "#F4F3F4", - "white-color" -> "#FFFFFF" - ), - fork in tut := true, - scalacOptions in Tut --= Seq( - "-Xfatal-warnings", - "-Ywarn-unused-import", - "-Ywarn-numeric-widen", - "-Ywarn-dead-code", - "-Ywarn-unused:imports", - "-Xlint:-missing-interpolator,_" - ), - micrositePushSiteWith := GitHub4s, - micrositeGithubToken := sys.env.get("GITHUB_TOKEN"), - micrositeExtraMdFiles := Map( - file("CHANGELOG.md") -> ExtraMdFileConfig("changelog.md", "page", Map("title" -> "changelog", "section" -> "changelog", "position" -> "100")), - file("CODE_OF_CONDUCT.md") -> ExtraMdFileConfig("code-of-conduct.md", "page", Map("title" -> "code of conduct", "section" -> "code of conduct", "position" -> "101")), - file("LICENSE") -> ExtraMdFileConfig("license.md", "page", Map("title" -> "license", "section" -> "license", "position" -> "102")) - ) - ) + micrositeDescription := "Keyed Semaphores" } -val catsV = "2.1.1" -val catsEffectV = "2.1.4" -val specs2V = "4.8.3" - -val kindProjectorV = "0.11.3" -val betterMonadicForV = "0.3.1" - -// General Settings -lazy val commonSettings = Seq( - scalaVersion := "2.13.1", - crossScalaVersions := Seq(scalaVersion.value, "2.12.10"), - - addCompilerPlugin("org.typelevel" % "kind-projector" % kindProjectorV cross CrossVersion.full), - addCompilerPlugin("com.olegpy" %% "better-monadic-for" % betterMonadicForV), - libraryDependencies ++= Seq( - "org.typelevel" %% "cats-core" % catsV, - "org.typelevel" %% "cats-effect" % catsEffectV, - - "org.specs2" %% "specs2-core" % specs2V % Test, - "org.specs2" %% "specs2-scalacheck" % specs2V % Test - ) -) - -// General Settings -inThisBuild(List( - organization := "io.chrisdavenport", - developers := List( - Developer("ChristopherDavenport", "Christopher Davenport", "chris@christopherdavenport.tech", url("https://github.com/ChristopherDavenport")) - ), - - homepage := Some(url("https://github.com/ChristopherDavenport/keysemaphore")), - licenses += ("MIT", url("http://opensource.org/licenses/MIT")), - pomIncludeRepository := { _ => false}, - scalacOptions in (Compile, doc) ++= Seq( - "-groups", - "-sourcepath", (baseDirectory in LocalRootProject).value.getAbsolutePath, - "-doc-source-url", "https://github.com/ChristopherDavenport/keysemaphore/blob/v" + version.value + "€{FILE_PATH}.scala" - ), -)) diff --git a/core/src/test/scala/io/chrisdavenport/keysemaphore/KeySemaphoreSpec.scala b/core/src/test/scala/io/chrisdavenport/keysemaphore/KeySemaphoreSpec.scala index 71bf88b..27d4e5e 100644 --- a/core/src/test/scala/io/chrisdavenport/keysemaphore/KeySemaphoreSpec.scala +++ b/core/src/test/scala/io/chrisdavenport/keysemaphore/KeySemaphoreSpec.scala @@ -9,7 +9,7 @@ class KeySemaphoreSpec extends Specification { "only take the maximum values per key" in { implicit val CS = IO.contextShift(global) val test = for { - sem <- KeySemaphore.of[IO, Unit]{_: Unit => 1L} + sem <- KeySemaphore.of[IO, Unit]{(_: Unit) => 1L} first <- sem(()).tryAcquire second <- sem(()).tryAcquire } yield (first, second) @@ -19,7 +19,7 @@ class KeySemaphoreSpec extends Specification { "not be affected by other keys" in { implicit val CS = IO.contextShift(global) val test = for { - sem <- KeySemaphore.of[IO, Int]{_: Int => 1L} + sem <- KeySemaphore.of[IO, Int]{(_: Int) => 1L} first <- sem(1).tryAcquire second <- sem(2).tryAcquire third <- sem(1).tryAcquire @@ -30,7 +30,7 @@ class KeySemaphoreSpec extends Specification { "restore on finished" in { implicit val CS = IO.contextShift(global) val test = for { - sem <- KeySemaphore.of[IO, Int]{_: Int => 1L} + sem <- KeySemaphore.of[IO, Int]{(_: Int) => 1L} first <- sem(1).tryAcquire second <- sem(1).tryAcquire _ <- sem(1).release @@ -42,7 +42,7 @@ class KeySemaphoreSpec extends Specification { "not allow more than the key" in { implicit val CS = IO.contextShift(global) val test = for { - sem <- KeySemaphore.of[IO, Int]{_: Int => 1L} + sem <- KeySemaphore.of[IO, Int]{(_: Int) => 1L} first <- sem(1).tryAcquire _ <- sem(1).releaseN(10) second <- sem(1).tryAcquire diff --git a/project/build.properties b/project/build.properties index 0837f7a..10fd9ee 100644 --- a/project/build.properties +++ b/project/build.properties @@ -1 +1 @@ -sbt.version=1.3.13 +sbt.version=1.5.5 diff --git a/project/plugins.sbt b/project/plugins.sbt index fef6b2c..f23bde1 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -1,9 +1,2 @@ -addSbtPlugin("com.geirsson" % "sbt-ci-release" % "1.5.5") -addSbtPlugin("io.github.davidgregory084" % "sbt-tpolecat" % "0.1.16") -addSbtPlugin("com.typesafe" % "sbt-mima-plugin" % "0.6.4") -addSbtPlugin("org.tpolecat" % "tut-plugin" % "0.6.13") -addSbtPlugin("com.47deg" % "sbt-microsites" % "0.9.7") -addSbtPlugin("com.typesafe.sbt" % "sbt-ghpages" % "0.6.3") -addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % "0.6.1") -addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.33") -addSbtPlugin("io.chrisdavenport" % "sbt-mima-version-check" % "0.1.2") \ No newline at end of file +addSbtPlugin("io.github.davidgregory084" % "sbt-tpolecat" % "0.1.20") +addSbtPlugin("io.chrisdavenport" % "sbt-davenverse" % "0.0.7") diff --git a/docs/src/main/tut/index.md b/site/docs/index.md similarity index 77% rename from docs/src/main/tut/index.md rename to site/docs/index.md index d5c83e4..17d4780 100644 --- a/docs/src/main/tut/index.md +++ b/site/docs/index.md @@ -3,7 +3,7 @@ layout: home --- -# keysemaphore - Keyed Semaphores [![Build Status](https://travis-ci.com/ChristopherDavenport/keysemaphore.svg?branch=master)](https://travis-ci.com/ChristopherDavenport/keysemaphore) [![Maven Central](https://maven-badges.herokuapp.com/maven-central/io.chrisdavenport/keysemaphore_2.12/badge.svg)](https://maven-badges.herokuapp.com/maven-central/io.chrisdavenport/keysemaphore_2.12) +# keysemaphore - Keyed Semaphores [![Maven Central](https://maven-badges.herokuapp.com/maven-central/io.chrisdavenport/keysemaphore_2.12/badge.svg)](https://maven-badges.herokuapp.com/maven-central/io.chrisdavenport/keysemaphore_2.12) ## Quick Start @@ -20,7 +20,7 @@ libraryDependencies ++= Seq( Quick Imports -```tut:silent +```scala mdoc:silent import cats.effect._ import io.chrisdavenport.keysemaphore.KeySemaphore implicit val CS = IO.contextShift(scala.concurrent.ExecutionContext.global) @@ -28,7 +28,7 @@ implicit val CS = IO.contextShift(scala.concurrent.ExecutionContext.global) Then we build some operations -```tut +```scala mdoc // Second Action Can't Get Permit val action1 = { for { From 21f8ec900f2bd11e174a0f78fbc427f80c4614fa Mon Sep 17 00:00:00 2001 From: Christopher Davenport Date: Tue, 3 Aug 2021 21:08:25 -0700 Subject: [PATCH 4/9] Workflow --- .github/workflows/ci.yml | 128 ++++++++++++++++++++++++++++++++++++ .github/workflows/clean.yml | 59 +++++++++++++++++ 2 files changed, 187 insertions(+) create mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/clean.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..6a7c014 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,128 @@ +# This file was automatically generated by sbt-github-actions using the +# githubWorkflowGenerate task. You should add and commit this file to +# your git repository. It goes without saying that you shouldn't edit +# this file by hand! Instead, if you wish to make changes, you should +# change your sbt build configuration to revise the workflow description +# to meet your needs, then regenerate this file. + +name: Continuous Integration + +on: + pull_request: + branches: ['**'] + push: + branches: ['**'] + tags: [v*] + +env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + +jobs: + build: + name: Build and Test + strategy: + matrix: + os: [ubuntu-latest] + scala: [2.12.14, 2.13.6, 3.0.1] + java: [adopt@1.8, adopt@1.11] + runs-on: ${{ matrix.os }} + steps: + - name: Checkout current branch (full) + uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: Setup Java and Scala + uses: olafurpg/setup-scala@v12 + with: + java-version: ${{ matrix.java }} + + - name: Cache sbt + uses: actions/cache@v2 + with: + path: | + ~/.sbt + ~/.ivy2/cache + ~/.coursier/cache/v1 + ~/.cache/coursier/v1 + ~/AppData/Local/Coursier/Cache/v1 + ~/Library/Caches/Coursier/v1 + key: ${{ runner.os }}-sbt-cache-v2-${{ hashFiles('**/*.sbt') }}-${{ hashFiles('project/build.properties') }} + + - name: Setup Ruby + if: matrix.scala == '2.13.6' + uses: ruby/setup-ruby@v1 + with: + ruby-version: 3.0.1 + + - name: Install microsite dependencies + if: matrix.scala == '2.13.6' + run: | + gem install saas + gem install jekyll -v 4.2.0 + + - name: Check that workflows are up to date + run: sbt --client '++${{ matrix.scala }}; githubWorkflowCheck' + + - run: sbt --client '++${{ matrix.scala }}; test; mimaReportBinaryIssues' + + - if: matrix.scala == '2.13.6' + run: sbt --client '++${{ matrix.scala }}; site/makeMicrosite' + + publish: + name: Publish Artifacts + needs: [build] + if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main') + strategy: + matrix: + os: [ubuntu-latest] + scala: [3.0.1] + java: [adopt@1.8] + runs-on: ${{ matrix.os }} + steps: + - name: Checkout current branch (full) + uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: Setup Java and Scala + uses: olafurpg/setup-scala@v12 + with: + java-version: ${{ matrix.java }} + + - name: Cache sbt + uses: actions/cache@v2 + with: + path: | + ~/.sbt + ~/.ivy2/cache + ~/.coursier/cache/v1 + ~/.cache/coursier/v1 + ~/AppData/Local/Coursier/Cache/v1 + ~/Library/Caches/Coursier/v1 + key: ${{ runner.os }}-sbt-cache-v2-${{ hashFiles('**/*.sbt') }}-${{ hashFiles('project/build.properties') }} + + - uses: olafurpg/setup-gpg@v3 + + - name: Setup Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: 3.0.1 + + - name: Install microsite dependencies + run: | + gem install saas + gem install jekyll -v 4.2.0 + + - name: Publish artifacts to Sonatype + env: + PGP_PASSPHRASE: ${{ secrets.PGP_PASSPHRASE }} + PGP_SECRET: ${{ secrets.PGP_SECRET }} + SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }} + SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }} + run: sbt --client '++${{ matrix.scala }}; ci-release' + + - uses: christopherdavenport/create-ghpages-ifnotexists@v1 + + - name: Publish microsite + run: sbt --client '++${{ matrix.scala }}; site/publishMicrosite' \ No newline at end of file diff --git a/.github/workflows/clean.yml b/.github/workflows/clean.yml new file mode 100644 index 0000000..b535fcc --- /dev/null +++ b/.github/workflows/clean.yml @@ -0,0 +1,59 @@ +# This file was automatically generated by sbt-github-actions using the +# githubWorkflowGenerate task. You should add and commit this file to +# your git repository. It goes without saying that you shouldn't edit +# this file by hand! Instead, if you wish to make changes, you should +# change your sbt build configuration to revise the workflow description +# to meet your needs, then regenerate this file. + +name: Clean + +on: push + +jobs: + delete-artifacts: + name: Delete Artifacts + runs-on: ubuntu-latest + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + steps: + - name: Delete artifacts + run: | + # Customize those three lines with your repository and credentials: + REPO=${GITHUB_API_URL}/repos/${{ github.repository }} + + # A shortcut to call GitHub API. + ghapi() { curl --silent --location --user _:$GITHUB_TOKEN "$@"; } + + # A temporary file which receives HTTP response headers. + TMPFILE=/tmp/tmp.$$ + + # An associative array, key: artifact name, value: number of artifacts of that name. + declare -A ARTCOUNT + + # Process all artifacts on this repository, loop on returned "pages". + URL=$REPO/actions/artifacts + while [[ -n "$URL" ]]; do + + # Get current page, get response headers in a temporary file. + JSON=$(ghapi --dump-header $TMPFILE "$URL") + + # Get URL of next page. Will be empty if we are at the last page. + URL=$(grep '^Link:' "$TMPFILE" | tr ',' '\n' | grep 'rel="next"' | head -1 | sed -e 's/.*.*//') + rm -f $TMPFILE + + # Number of artifacts on this page: + COUNT=$(( $(jq <<<$JSON -r '.artifacts | length') )) + + # Loop on all artifacts on this page. + for ((i=0; $i < $COUNT; i++)); do + + # Get name of artifact and count instances of this name. + name=$(jq <<<$JSON -r ".artifacts[$i].name?") + ARTCOUNT[$name]=$(( $(( ${ARTCOUNT[$name]} )) + 1)) + + id=$(jq <<<$JSON -r ".artifacts[$i].id?") + size=$(( $(jq <<<$JSON -r ".artifacts[$i].size_in_bytes?") )) + printf "Deleting '%s' #%d, %'d bytes\n" $name ${ARTCOUNT[$name]} $size + ghapi -X DELETE $REPO/actions/artifacts/$id + done + done \ No newline at end of file From 0e6e2032ca606e4d3b995692d40b8f2c0a6da563 Mon Sep 17 00:00:00 2001 From: Christopher Davenport Date: Tue, 3 Aug 2021 21:10:54 -0700 Subject: [PATCH 5/9] Mima --- build.sbt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build.sbt b/build.sbt index 24e0a67..5d098ad 100644 --- a/build.sbt +++ b/build.sbt @@ -12,8 +12,8 @@ lazy val `keysemaphore` = project.in(file(".")) .aggregate(core.jvm, core.js, docs) lazy val core = crossProject(JSPlatform, JVMPlatform) - .crossType(CrossType.Pure).in(file("core")) - .disablePlugins(MimaPlugin) + .crossType(CrossType.Pure) + .in(file("core")) .settings( name := "keysemaphore", libraryDependencies ++= Seq( From 2c2fd1eceecfcd25d158f3097014087c96967567 Mon Sep 17 00:00:00 2001 From: Christopher Davenport Date: Tue, 3 Aug 2021 21:14:35 -0700 Subject: [PATCH 6/9] site --- build.sbt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.sbt b/build.sbt index 5d098ad..ece6543 100644 --- a/build.sbt +++ b/build.sbt @@ -25,7 +25,7 @@ lazy val core = crossProject(JSPlatform, JVMPlatform) ) ) -lazy val docs = project.in(file("docs")) +lazy val site = project.in(file("site")) .dependsOn(core.jvm) .disablePlugins(MimaPlugin) .enablePlugins(NoPublishPlugin) From 2e6fde4dccc482170359d354e699e8460b42a619 Mon Sep 17 00:00:00 2001 From: Christopher Davenport Date: Tue, 3 Aug 2021 21:24:52 -0700 Subject: [PATCH 7/9] Broken Build --- build.sbt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.sbt b/build.sbt index ece6543..532f9bc 100644 --- a/build.sbt +++ b/build.sbt @@ -9,7 +9,7 @@ ThisBuild / crossScalaVersions := Seq("2.12.14", "2.13.6", "3.0.1") lazy val `keysemaphore` = project.in(file(".")) .disablePlugins(MimaPlugin) .enablePlugins(NoPublishPlugin) - .aggregate(core.jvm, core.js, docs) + .aggregate(core.jvm, core.js, site) lazy val core = crossProject(JSPlatform, JVMPlatform) .crossType(CrossType.Pure) From a319106e42b42ad52b661be7cec6df75b8b5fb10 Mon Sep 17 00:00:00 2001 From: Christopher Davenport Date: Tue, 3 Aug 2021 21:50:55 -0700 Subject: [PATCH 8/9] Fix Build --- build.sbt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/build.sbt b/build.sbt index 532f9bc..46c2d74 100644 --- a/build.sbt +++ b/build.sbt @@ -16,13 +16,17 @@ lazy val core = crossProject(JSPlatform, JVMPlatform) .in(file("core")) .settings( name := "keysemaphore", + mimaVersionCheckExcludedVersions := { + if (isDotty.value) Set("0.2.0") + else Set() + }, libraryDependencies ++= Seq( "org.typelevel" %%% "cats-core" % catsV, "org.typelevel" %%% "cats-effect" % catsEffectV, ("org.specs2" %%% "specs2-core" % specs2V % Test).cross(CrossVersion.for3Use2_13), ("org.specs2" %%% "specs2-scalacheck" % specs2V % Test).cross(CrossVersion.for3Use2_13) - ) + ), ) lazy val site = project.in(file("site")) From 9e2f99819adb37b4f108e101ab9ebe60203b4624 Mon Sep 17 00:00:00 2001 From: Anthony Ascencio Date: Thu, 5 Aug 2021 00:19:10 +0000 Subject: [PATCH 9/9] scala 3 --- build.sbt | 80 ++++++++++++------- .../keysemaphore/KeySemaphoreSpec.scala | 24 +++--- project/plugins.sbt | 17 ++-- 3 files changed, 72 insertions(+), 49 deletions(-) diff --git a/build.sbt b/build.sbt index d8a0576..e9bcf52 100644 --- a/build.sbt +++ b/build.sbt @@ -1,24 +1,27 @@ import sbtcrossproject.CrossPlugin.autoImport.{crossProject, CrossType} -lazy val `keysemaphore` = project.in(file(".")) +lazy val `keysemaphore` = project + .in(file(".")) .disablePlugins(MimaPlugin) .settings(publish / skip := true) .aggregate(core, docs) -lazy val core = project.in(file("core")) +lazy val core = project + .in(file("core")) .disablePlugins(MimaPlugin) .settings(commonSettings) .settings( name := "keysemaphore" ) -lazy val docs = project.in(file("docs")) +lazy val docs = project + .in(file("docs")) .settings(commonSettings) .dependsOn(core) .disablePlugins(MimaPlugin) .enablePlugins(MicrositesPlugin) .settings(publish / skip := true) - .settings{ + .settings { import microsites._ Seq( micrositeName := "keysemaphore", @@ -51,27 +54,39 @@ lazy val docs = project.in(file("docs")) micrositePushSiteWith := GitHub4s, micrositeGithubToken := sys.env.get("GITHUB_TOKEN"), micrositeExtraMdFiles := Map( - file("CHANGELOG.md") -> ExtraMdFileConfig("changelog.md", "page", Map("title" -> "changelog", "section" -> "changelog", "position" -> "100")), - file("CODE_OF_CONDUCT.md") -> ExtraMdFileConfig("code-of-conduct.md", "page", Map("title" -> "code of conduct", "section" -> "code of conduct", "position" -> "101")), - file("LICENSE") -> ExtraMdFileConfig("license.md", "page", Map("title" -> "license", "section" -> "license", "position" -> "102")) + file("CHANGELOG.md") -> ExtraMdFileConfig( + "changelog.md", + "page", + Map("title" -> "changelog", "section" -> "changelog", "position" -> "100") + ), + file("CODE_OF_CONDUCT.md") -> ExtraMdFileConfig( + "code-of-conduct.md", + "page", + Map("title" -> "code of conduct", "section" -> "code of conduct", "position" -> "101") + ), + file("LICENSE") -> ExtraMdFileConfig( + "license.md", + "page", + Map("title" -> "license", "section" -> "license", "position" -> "102") + ) ) ) } val catsV = "2.6.1" -val catsEffectV = "3.2.0" +val catsEffectV = "3.2.1" val munitCatsEffectV = "1.0.5" val kindProjectorV = "0.13.0" // General Settings lazy val commonSettings = Seq( - scalaVersion := "2.13.6", - crossScalaVersions := Seq(scalaVersion.value, "2.12.14"), + scalaVersion := "3.0.0", + crossScalaVersions := Seq(scalaVersion.value, "2.13.6", "2.12.14"), libraryDependencies ++= Seq( - "org.typelevel" %% "cats-core" % catsV, - "org.typelevel" %% "cats-effect" % catsEffectV, - "org.typelevel" %%% "munit-cats-effect-3" % munitCatsEffectV % Test - ) ++ + "org.typelevel" %% "cats-core" % catsV, + "org.typelevel" %% "cats-effect" % catsEffectV, + "org.typelevel" %%% "munit-cats-effect-3" % munitCatsEffectV % Test + ) ++ // format: off (if (scalaVersion.value.startsWith("2")) Seq(compilerPlugin("org.typelevel" %% "kind-projector" % kindProjectorV).cross(CrossVersion.full)) @@ -80,19 +95,26 @@ lazy val commonSettings = Seq( ) // General Settings -inThisBuild(List( - organization := "io.chrisdavenport", - developers := List( - Developer("ChristopherDavenport", "Christopher Davenport", "chris@christopherdavenport.tech", url("https://github.com/ChristopherDavenport")) - ), - - homepage := Some(url("https://github.com/ChristopherDavenport/keysemaphore")), - licenses += ("MIT", url("http://opensource.org/licenses/MIT")), - - pomIncludeRepository := { _ => false}, - Compile / doc / scalacOptions ++= Seq( +inThisBuild( + List( + organization := "io.chrisdavenport", + developers := List( + Developer( + "ChristopherDavenport", + "Christopher Davenport", + "chris@christopherdavenport.tech", + url("https://github.com/ChristopherDavenport") + ) + ), + homepage := Some(url("https://github.com/ChristopherDavenport/keysemaphore")), + licenses += ("MIT", url("http://opensource.org/licenses/MIT")), + pomIncludeRepository := { _ => false }, + Compile / doc / scalacOptions ++= Seq( "-groups", - "-sourcepath", (LocalRootProject / baseDirectory).value.getAbsolutePath, - "-doc-source-url", "https://github.com/ChristopherDavenport/keysemaphore/blob/v" + version.value + "€{FILE_PATH}.scala" - ), -)) + "-sourcepath", + (LocalRootProject / baseDirectory).value.getAbsolutePath, + "-doc-source-url", + "https://github.com/ChristopherDavenport/keysemaphore/blob/v" + version.value + "€{FILE_PATH}.scala" + ) + ) +) diff --git a/core/src/test/scala/io/chrisdavenport/keysemaphore/KeySemaphoreSpec.scala b/core/src/test/scala/io/chrisdavenport/keysemaphore/KeySemaphoreSpec.scala index 8a11153..598d6d3 100644 --- a/core/src/test/scala/io/chrisdavenport/keysemaphore/KeySemaphoreSpec.scala +++ b/core/src/test/scala/io/chrisdavenport/keysemaphore/KeySemaphoreSpec.scala @@ -5,48 +5,48 @@ import munit.CatsEffectSuite class KeySemaphoreSpec extends CatsEffectSuite { test("only take the maximum values per key") { - val test = for { - sem <- KeySemaphore.of[IO, Unit]{_: Unit => 1L} + val obtained = for { + sem <- KeySemaphore.of[IO, Unit] { _: Unit => 1L } first <- sem(()).tryAcquire second <- sem(()).tryAcquire } yield (first, second) val expected = (true, false) - assertIO(expected, test) + assertIO(obtained, expected) } test("not be affected by other keys") { - val test = for { - sem <- KeySemaphore.of[IO, Int]{_: Int => 1L} + val obtained = for { + sem <- KeySemaphore.of[IO, Int] { _: Int => 1L } first <- sem(1).tryAcquire second <- sem(2).tryAcquire third <- sem(1).tryAcquire } yield (first, second, third) val expected = (true, true, false) - assertIO(expected, test) + assertIO(obtained, expected) } test("restore on finished") { - val test = for { - sem <- KeySemaphore.of[IO, Int]{_: Int => 1L} + val obtained = for { + sem <- KeySemaphore.of[IO, Int] { _: Int => 1L } first <- sem(1).tryAcquire second <- sem(1).tryAcquire _ <- sem(1).release third <- sem(1).tryAcquire } yield (first, second, third) val expected = (true, false, true) - assertIO(expected, test) + assertIO(obtained, expected) } test("not allow more than the key") { - val test = for { - sem <- KeySemaphore.of[IO, Int]{_: Int => 1L} + val obtained = for { + sem <- KeySemaphore.of[IO, Int] { _: Int => 1L } first <- sem(1).tryAcquire _ <- sem(1).releaseN(10) second <- sem(1).tryAcquire third <- sem(1).tryAcquire } yield (first, second, third) val expected = (true, true, false) - assertIO(expected, test) + assertIO(obtained, expected) } // def printState(sem: KeySemaphore.AbstractKeySemaphore[IO, _]): IO[Unit] = diff --git a/project/plugins.sbt b/project/plugins.sbt index f1707ae..db4617f 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -1,8 +1,9 @@ -addSbtPlugin("io.github.davidgregory084" % "sbt-tpolecat" % "0.1.20") -addSbtPlugin("com.geirsson" % "sbt-ci-release" % "1.5.7") -addSbtPlugin("com.typesafe" % "sbt-mima-plugin" % "0.9.2") -addSbtPlugin("com.47deg" % "sbt-microsites" % "1.3.4") -addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % "1.1.0") -addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.6.0") -addSbtPlugin("io.chrisdavenport" % "sbt-mima-version-check" % "0.1.2") -addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.4.3") +addSbtPlugin("io.github.davidgregory084" % "sbt-tpolecat" % "0.1.20") +addSbtPlugin("com.geirsson" % "sbt-ci-release" % "1.5.7") +addSbtPlugin("com.typesafe" % "sbt-mima-plugin" % "0.9.2") +addSbtPlugin("com.47deg" % "sbt-microsites" % "1.3.4") +addSbtPlugin("org.scalameta" % "sbt-mdoc" % "2.2.22") +addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % "1.1.0") +addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.6.0") +addSbtPlugin("io.chrisdavenport" % "sbt-mima-version-check" % "0.1.2") +addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.4.3")