Skip to content

Commit

Permalink
Update dependencies, use sbt-github-actions, test on java 21.
Browse files Browse the repository at this point in the history
  • Loading branch information
mrdziuban committed Feb 22, 2024
1 parent 794bc3d commit 426118c
Show file tree
Hide file tree
Showing 8 changed files with 172 additions and 46 deletions.
92 changes: 64 additions & 28 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,43 +1,79 @@
name: composefree
# 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:
push:
branches:
- master
pull_request:
branches:
- master
branches: [master]
push:
branches: [master]

env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

jobs:
test:
runs-on: ubuntu-latest
build:
name: Build and Test
strategy:
fail-fast: false
matrix:
scala: [2.13.10, 3.3.0]
java: [8, 11, 17]
os: [ubuntu-latest]
scala: [2.13.12, 3.3.1]
java: [temurin@8, temurin@11, temurin@17, temurin@21]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- name: Checkout current branch (full)
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup Java ${{ matrix.java }}
uses: actions/setup-java@v2
- name: Setup Java (temurin@8)
if: matrix.java == 'temurin@8'
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: ${{ matrix.java }}
java-version: 8
cache: sbt

- name: Cache sbt
uses: actions/cache@v2
- name: Setup Java (temurin@11)
if: matrix.java == 'temurin@11'
uses: actions/setup-java@v4
with:
path: |
~/.sbt
~/.ivy2/cache
~/.coursier/cache/v1
~/.cache/coursier/v1
key: ${{ runner.os }}-sbt-cache-v2-${{ hashFiles('**/*.sbt') }}-${{ hashFiles('project/build.properties') }}
distribution: temurin
java-version: 11
cache: sbt

- name: Setup Java (temurin@17)
if: matrix.java == 'temurin@17'
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 17
cache: sbt

- name: Setup Java (temurin@21)
if: matrix.java == 'temurin@21'
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 21
cache: sbt

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

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

- name: sbt example/run
run: sbt ++${{ matrix.scala }} example/run
- name: Run example
if: matrix.java == 'temurin@21'
run: sbt '++ ${{ matrix.scala }}' example/run

- name: sbt docs/mdoc
run: sbt ++${{ matrix.scala }} docs/mdoc
- name: Build docs
if: matrix.java == 'temurin@21'
run: sbt '++ ${{ matrix.scala }}' docs/mdoc
60 changes: 60 additions & 0 deletions .github/workflows/clean.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# 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
shell: bash {0}
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=$(mktemp)
# 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/.*<//' -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
31 changes: 24 additions & 7 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,9 +1,26 @@
Global / onChangedBuildSource := ReloadOnSourceChanges

lazy val scala213 = "2.13.10"
lazy val scala3 = "3.3.0"
lazy val scala213 = "2.13.12"
lazy val scala3 = "3.3.1"
lazy val scalaVersions = Seq(scala213, scala3)

lazy val kindProjector = compilerPlugin("org.typelevel" %% "kind-projector" % "0.13.2" cross CrossVersion.full)
ThisBuild / crossScalaVersions := scalaVersions

// GitHub Actions config
val javaVersions = Seq(8, 11, 17, 21).map(v => JavaSpec.temurin(v.toString))

ThisBuild / githubWorkflowJavaVersions := javaVersions
ThisBuild / githubWorkflowArtifactUpload := false
ThisBuild / githubWorkflowBuildMatrixFailFast := Some(false)
ThisBuild / githubWorkflowTargetBranches := Seq("master")
ThisBuild / githubWorkflowPublishTargetBranches := Seq()

def isJava(v: Int) = s"matrix.java == '${javaVersions.find(_.version == v.toString).get.render}'"

ThisBuild / githubWorkflowBuild ++= Seq(
WorkflowStep.Sbt(List("example/run"), name = Some("Run example"), cond = Some(isJava(21))),
WorkflowStep.Sbt(List("docs/mdoc"), name = Some("Build docs"), cond = Some(isJava(21))),
)

def forScalaV[A](scalaVersion: String)(_213: => A, _3: => A): A =
CrossVersion.partialVersion(scalaVersion) match {
Expand All @@ -15,15 +32,15 @@ lazy val commonSettings = Seq(
version := "6.1.0",
organization := "bondlink",
scalaVersion := scala3,
crossScalaVersions := Seq(scala213, scala3),
crossScalaVersions := scalaVersions,
scalacOptions ++= Seq(
"-Wconf:msg=package object inheritance is deprecated:s",
) ++ forScalaV(scalaVersion.value)(
Seq("-Xsource:3.3", "-Ymacro-annotations"),
Seq(),
),
libraryDependencies ++= forScalaV(scalaVersion.value)(
Seq(kindProjector),
Seq(compilerPlugin("org.typelevel" %% "kind-projector" % "0.13.2" cross CrossVersion.full)),
Seq(),
),
publish / skip := true
Expand All @@ -32,7 +49,7 @@ lazy val commonSettings = Seq(
commonSettings
gitRelease := {}

lazy val catsVersion = "2.9.0"
lazy val catsVersion = "2.10.0"
lazy val catsCore = "org.typelevel" %% "cats-core" % catsVersion
lazy val catsFree = "org.typelevel" %% "cats-free" % catsVersion
lazy val catsLaws = "org.typelevel" %% "cats-laws" % catsVersion % Test
Expand Down Expand Up @@ -71,7 +88,7 @@ lazy val future = project.in(file("future"))
lazy val example = project.in(file("example"))
.settings(commonSettings ++ Seq(
name := "composefree-example",
libraryDependencies += "org.typelevel" %% "cats-effect" % "3.4.8",
libraryDependencies += "org.typelevel" %% "cats-effect" % "3.5.3",
gitRelease := {}
))
.dependsOn(core, future)
Expand Down
6 changes: 6 additions & 0 deletions example/src/main/scala-2/Example.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package composefree.example

import composefree.future._
import scala.concurrent.ExecutionContext.Implicits.global

object Example extends ExampleBase()
6 changes: 6 additions & 0 deletions example/src/main/scala-3/Example.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package composefree.example

import composefree.future.given
import scala.concurrent.ExecutionContext.Implicits.global

object Example extends ExampleBase()
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
package composefree.example

import cats.Parallel
import cats.effect.{ExitCode, IO, IOApp}
import cats.syntax.apply._
import cats.syntax.traverse._
import composefree.future.{given, _}
import composefree.example.console._
import composefree.example.dsl._
import composefree.example.numbers._
import composefree.future.ParFuture
import composefree.puredsl._
import scala.concurrent.blocking
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.{blocking, ExecutionContext, Future}
import scala.concurrent.duration._

object Example extends IOApp {
abstract class ExampleBase()(implicit ec: ExecutionContext, p: Parallel.Aux[Future, ParFuture]) extends IOApp {
import examplecompose._

def stall[A](a: A): Composed[A] =
final def stall[A](a: A): Composed[A] =
for {
_ <- print(s"stalling -- $a")
_ <- pure { blocking(Thread.sleep(3500L)) }.as[PureOp]
_ <- print(s"done stalling -- $a")
} yield a

val progA: Composed[Int] = (stall(1).opAp, stall(2).opAp).mapN(_ + _).op
final val progA: Composed[Int] = (stall(1).opAp, stall(2).opAp).mapN(_ + _).op

val prog: Composed[Int] =
final val prog: Composed[Int] =
for {
init <- pure(2).as[PureOp]
_ <- set(init)
Expand All @@ -41,7 +41,7 @@ object Example extends IOApp {
_ <- print(s"result: $res")
} yield res

def run(args: List[String]): IO[ExitCode] =
final def run(args: List[String]): IO[ExitCode] =
for {
_ <- IO(println(s"************** Future ****************"))
_ <- IO.fromFuture(IO(prog.runWith(examplecompose.futureInterp))).timeout(10.seconds)
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.8.3
sbt.version=1.9.8
5 changes: 3 additions & 2 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
addSbtPlugin("org.scalameta" % "sbt-mdoc" % "2.3.6")
addSbtPlugin("io.github.davidgregory084" % "sbt-tpolecat" % "0.4.1")
addSbtPlugin("com.github.sbt" % "sbt-github-actions" % "0.23.0")
addSbtPlugin("org.scalameta" % "sbt-mdoc" % "2.5.2")
addSbtPlugin("org.typelevel" % "sbt-tpolecat" % "0.5.0")

resolvers += "bondlink-maven-repo" at "https://raw.githubusercontent.com/mblink/maven-repo/main"
addSbtPlugin("bondlink" % "sbt-git-publish" % "0.0.5")

0 comments on commit 426118c

Please sign in to comment.