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

Adopt sbt-typelevel #98

Merged
merged 3 commits into from
Nov 17, 2022
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
203 changes: 194 additions & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,17 @@ name: Continuous Integration

on:
pull_request:
branches: ['**']
branches: ['**', '!update/**', '!pr/**']
push:
branches: ['**']
branches: ['**', '!update/**', '!pr/**']
tags: [v*]

env:
PGP_PASSPHRASE: ${{ secrets.PGP_PASSPHRASE }}
SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}
SONATYPE_CREDENTIAL_HOST: ${{ secrets.SONATYPE_CREDENTIAL_HOST }}
SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }}
PGP_SECRET: ${{ secrets.PGP_SECRET }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

jobs:
Expand All @@ -23,20 +29,35 @@ jobs:
matrix:
os: [ubuntu-latest]
scala: [2.12.17, 2.13.10, 3.2.1]
java: [temurin@11]
java: [temurin@8]
project: [rootJS, rootJVM, rootNative]
exclude:
- scala: 2.12.17
project: rootNative
- scala: 2.13.10
project: rootNative
runs-on: ${{ matrix.os }}
steps:
- name: Checkout current branch (full)
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Setup Java (temurin@11)
if: matrix.java == 'temurin@11'
uses: actions/setup-java@v2
- name: Download Java (temurin@8)
id: download-java-temurin-8
if: matrix.java == 'temurin@8'
uses: typelevel/download-java@v1
with:
distribution: temurin
java-version: 11
java-version: 8

- name: Setup Java (temurin@8)
if: matrix.java == 'temurin@8'
uses: actions/setup-java@v2
with:
distribution: jdkfile
java-version: 8
jdkFile: ${{ steps.download-java-temurin-8.outputs.jdkFile }}

- name: Cache sbt
uses: actions/cache@v2
Expand All @@ -51,6 +72,170 @@ jobs:
key: ${{ runner.os }}-sbt-cache-v2-${{ hashFiles('**/*.sbt') }}-${{ hashFiles('project/build.properties') }}

- name: Check that workflows are up to date
run: sbt ++${{ matrix.scala }} githubWorkflowCheck
run: sbt githubWorkflowCheck

- name: Check headers and formatting
if: matrix.java == 'temurin@8'
run: sbt 'project ${{ matrix.project }}' '++ ${{ matrix.scala }}' headerCheckAll scalafmtCheckAll 'project /' scalafmtSbtCheck

- name: scalaJSLink
if: matrix.project == 'rootJS'
run: sbt 'project ${{ matrix.project }}' '++ ${{ matrix.scala }}' Test/scalaJSLinkerResult

- name: nativeLink
if: matrix.project == 'rootNative'
run: sbt 'project ${{ matrix.project }}' '++ ${{ matrix.scala }}' Test/nativeLink

- name: Test
run: sbt 'project ${{ matrix.project }}' '++ ${{ matrix.scala }}' test

- name: Check binary compatibility
if: matrix.java == 'temurin@8'
run: sbt 'project ${{ matrix.project }}' '++ ${{ matrix.scala }}' mimaReportBinaryIssues

- name: Generate API documentation
if: matrix.java == 'temurin@8'
run: sbt 'project ${{ matrix.project }}' '++ ${{ matrix.scala }}' doc

- name: Make target directories
if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main')
run: mkdir -p target .js/target core/native/target core/js/target core/jvm/target .jvm/target .native/target project/target

- name: Compress target directories
if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main')
run: tar cf targets.tar target .js/target core/native/target core/js/target core/jvm/target .jvm/target .native/target project/target

- name: Upload target directories
if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main')
uses: actions/upload-artifact@v2
with:
name: target-${{ matrix.os }}-${{ matrix.java }}-${{ matrix.scala }}-${{ matrix.project }}
path: targets.tar

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.2.1]
java: [temurin@8]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout current branch (full)
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Download Java (temurin@8)
id: download-java-temurin-8
if: matrix.java == 'temurin@8'
uses: typelevel/download-java@v1
with:
distribution: temurin
java-version: 8

- name: Setup Java (temurin@8)
if: matrix.java == 'temurin@8'
uses: actions/setup-java@v2
with:
distribution: jdkfile
java-version: 8
jdkFile: ${{ steps.download-java-temurin-8.outputs.jdkFile }}

- 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: Download target directories (2.12.17, rootJS)
uses: actions/download-artifact@v2
with:
name: target-${{ matrix.os }}-${{ matrix.java }}-2.12.17-rootJS

- name: Inflate target directories (2.12.17, rootJS)
run: |
tar xf targets.tar
rm targets.tar

- name: Download target directories (2.12.17, rootJVM)
uses: actions/download-artifact@v2
with:
name: target-${{ matrix.os }}-${{ matrix.java }}-2.12.17-rootJVM

- name: Inflate target directories (2.12.17, rootJVM)
run: |
tar xf targets.tar
rm targets.tar

- name: Download target directories (2.13.10, rootJS)
uses: actions/download-artifact@v2
with:
name: target-${{ matrix.os }}-${{ matrix.java }}-2.13.10-rootJS

- name: Inflate target directories (2.13.10, rootJS)
run: |
tar xf targets.tar
rm targets.tar

- name: Download target directories (2.13.10, rootJVM)
uses: actions/download-artifact@v2
with:
name: target-${{ matrix.os }}-${{ matrix.java }}-2.13.10-rootJVM

- name: Inflate target directories (2.13.10, rootJVM)
run: |
tar xf targets.tar
rm targets.tar

- name: Download target directories (3.2.1, rootJS)
uses: actions/download-artifact@v2
with:
name: target-${{ matrix.os }}-${{ matrix.java }}-3.2.1-rootJS

- name: Inflate target directories (3.2.1, rootJS)
run: |
tar xf targets.tar
rm targets.tar

- name: Download target directories (3.2.1, rootJVM)
uses: actions/download-artifact@v2
with:
name: target-${{ matrix.os }}-${{ matrix.java }}-3.2.1-rootJVM

- name: Inflate target directories (3.2.1, rootJVM)
run: |
tar xf targets.tar
rm targets.tar

- name: Download target directories (3.2.1, rootNative)
uses: actions/download-artifact@v2
with:
name: target-${{ matrix.os }}-${{ matrix.java }}-3.2.1-rootNative

- name: Inflate target directories (3.2.1, rootNative)
run: |
tar xf targets.tar
rm targets.tar

- name: Import signing key
if: env.PGP_SECRET != '' && env.PGP_PASSPHRASE == ''
run: echo $PGP_SECRET | base64 -di | gpg --import

- name: Import signing key and strip passphrase
if: env.PGP_SECRET != '' && env.PGP_PASSPHRASE != ''
run: |
echo "$PGP_SECRET" | base64 -di > /tmp/signing-key.gpg
echo "$PGP_PASSPHRASE" | gpg --pinentry-mode loopback --passphrase-fd 0 --import /tmp/signing-key.gpg
(echo "$PGP_PASSPHRASE"; echo; echo) | gpg --command-fd 0 --pinentry-mode loopback --change-passphrase $(gpg --list-secret-keys --with-colons 2> /dev/null | grep '^sec:' | cut --delimiter ':' --fields 5 | tail -n 1)

- run: sbt ++${{ matrix.scala }} ci
- name: Publish
run: sbt '++ ${{ matrix.scala }}' tlRelease
3 changes: 3 additions & 0 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
version = "3.6.1"
runner.dialect = Scala213Source3
project.includePaths = [] # disables formatting
34 changes: 17 additions & 17 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -16,51 +16,51 @@

name := "cats-effect-cps"

ThisBuild / baseVersion := "0.4"

ThisBuild / organization := "org.typelevel"
ThisBuild / organizationName := "Typelevel"
ThisBuild / tlBaseVersion := "0.4"

ThisBuild / startYear := Some(2021)
ThisBuild / endYear := Some(2022)

ThisBuild / homepage := Some(url("https://github.com/typelevel/cats-effect-cps"))
ThisBuild / scmInfo := Some(
ScmInfo(
url("https://github.com/typelevel/cats-effect-cps"),
"scm:git@github.com:typelevel/cats-effect-cps.git"))

ThisBuild / developers := List(
Developer("djspiewak", "Daniel Spiewak", "@djspiewak", url("https://github.com/djspiewak")),
Developer("baccata", "Olivier Melois", "@baccata", url("https://github.com/baccata")))
tlGitHubDev("djspiewak", "Daniel Spiewak"),
tlGitHubDev("baccata", "Olivier Melois"))

ThisBuild / crossScalaVersions := Seq("2.12.17", "2.13.10", "3.2.1")

ThisBuild / githubWorkflowBuildMatrixExclusions ++= {
crossScalaVersions.value.filter(_.startsWith("2.")).map { scala =>
MatrixExclude(Map("scala" -> scala, "project" -> "rootNative"))
}
}

val CatsEffectVersion = "3.4.1"

lazy val root = project.in(file(".")).aggregate(core.jvm, core.js, core.native).enablePlugins(NoPublishPlugin)
lazy val root = tlCrossRootProject.aggregate(core)

lazy val core = crossProject(JVMPlatform, JSPlatform, NativePlatform)
.in(file("core"))
.settings(
name := "cats-effect-cps",
headerEndYear := Some(2022),

scalacOptions ++= {
if (isDotty.value)
if (tlIsScala3.value)
Seq()
else
Seq("-Xasync")
},

resolvers ++= Resolver.sonatypeOssRepos("snapshots"),
tlFatalWarnings := {
tlFatalWarnings.value && !tlIsScala3.value
},
Comment on lines +52 to +54
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

idk if it's legit or not, would be ideal to fix this and re-enable fatals.

[warn] -- Warning: /workspace/cats-effect-cps/core/shared/src/test/scala/cats/effect/cps/AsyncAwaitSpec.scala:217:25 
[warn] 217 |        async[OptionTIO](optionT.await).value.await
[warn]     |                         ^^^^^^^^^^^^^
[warn]     |                         unused variable creation, effect may be lost
[warn]     |---------------------------------------------------------------------------
[warn]     |Inline stack trace
[warn]     |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
[warn]     |This location contains code that was inlined from AsyncAwaitSpec.scala:217
[warn]      ---------------------------------------------------------------------------
[warn] one warning found

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I can tell that one is out of our direct control, most likely happening during the macro expansion carried out by dotty-cps-async.

Maybe @rssh has an idea ? Ruslan, if you lurk, the repro steps are, once this branch is checked out and SBT is started :

> ++ 3.2.1 
> coreJVM/test 

That being said, I don't think this is an impediment to the merging of this PR

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can define

implicit val printCode = cps.macros.flags.PrintCode

to see, what's going on

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem that in internal async we materialize monad in var, which is not used (and issue warning about this) because the result is await which translated to argument.


libraryDependencies ++= Seq(
"org.typelevel" %%% "cats-effect-std" % CatsEffectVersion,

"org.typelevel" %%% "cats-effect" % CatsEffectVersion % Test,
"org.typelevel" %%% "cats-effect-testing-specs2" % "1.5.0" % Test),

libraryDependencies ++= {
if (isDotty.value)
if (tlIsScala3.value)
Seq("com.github.rssh" %%% "dotty-cps-async" % "0.9.11")
else
Seq("org.scala-lang" % "scala-reflect" % scalaVersion.value % "provided")
Expand Down
2 changes: 1 addition & 1 deletion core/shared/src/main/scala-2/cats/effect/cps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import cats.effect.cpsinternal.AsyncAwaitDsl
* }}}
*
* The code is transformed at compile time into a state machine
* that sequentially calls upon a [[Dispatcher]] every time it reaches
* that sequentially calls upon a [[cats.effect.std.Dispatcher]] every time it reaches
* an "await" block.
*/
object cps {
Expand Down
6 changes: 3 additions & 3 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
addSbtPlugin("com.codecommit" % "sbt-spiewak-sonatype" % "0.23.0")
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.11.0")
addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % "1.2.0")
addSbtPlugin("org.typelevel" % "sbt-typelevel" % "0.4.17")
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.11.0")
addSbtPlugin("org.scala-native" % "sbt-scala-native" % "0.4.7")
addSbtPlugin("org.portable-scala" % "sbt-scala-native-crossproject" % "1.2.0")
addSbtPlugin("de.heikoseeberger" % "sbt-header" % "5.9.0")