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

Dependency updates #12

Merged
merged 4 commits into from
Dec 10, 2024
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
79 changes: 55 additions & 24 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,39 +1,70 @@
name: routing
# 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:
java: [11, 17, 21]
os: [ubuntu-latest]
scala: [2.12.20]
java: [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@11)
if: matrix.java == 'temurin@11'
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: ${{ matrix.java }}
java-version: 11
cache: sbt

- name: Cache sbt
uses: actions/cache@v2
- name: Setup Java (temurin@17)
if: matrix.java == 'temurin@17'
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') }}

- name: sbt test
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: Setup sbt
uses: sbt/setup-sbt@v1

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

- name: Build project
run: sbt test

- name: sbt mdoc
- name: Build docs
if: matrix.java == 'temurin@21'
run: sbt 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
5 changes: 2 additions & 3 deletions bench/src/main/scala/routing/bench/Http4sBenchmark.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package routing
package bench

import cats.effect.IO
import cats.effect.unsafe.implicits.global // 0.23, 1.0.0-M41
import cats.effect.unsafe.implicits.global
import org.http4s._
import org.http4s.dsl.io._
import org.openjdk.jmh.annotations._
Expand Down Expand Up @@ -36,9 +36,8 @@ object http4sHelper extends BenchmarkHelper[Request[IO], Request[IO] => IO[Respo
runIO(routes.run(request).value.flatMap(_.get.as[String]))
}

class Http4sBenchmark_0_22 { // 0.22
class Http4sBenchmark_0_23 { // 0.23
class Http4sBenchmark_1_0_0_M41 { // 1.0.0-M41
class Http4sBenchmark_1_0_0_M44 { // 1.0.0-M44
import http4sHelper._

@Benchmark def http4s: String = run(http4sService)
Expand Down
4 changes: 2 additions & 2 deletions bench/src/main/scala/routing/bench/PlayBenchmark.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// ++ 1.0.0-M41
// ++ 1.0.0-M44
package routing
package bench

Expand All @@ -17,4 +17,4 @@ class PlayBenchmark {
@Benchmark def routing: String = run(routingService)
@Benchmark def routingManual: String = run(routingManualService)
}
// -- 1.0.0-M41
// -- 1.0.0-M44
30 changes: 18 additions & 12 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,22 @@ Global / onChangedBuildSource := ReloadOnSourceChanges

noPublishSettings

// GitHub Actions config
val javaVersions = Seq(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.Run(List("sbt test"), name = Some("Build project")),
WorkflowStep.Run(List("sbt mdoc"), name = Some("Build docs"), cond = Some(isJava(21))),
)

lazy val core = simpleProj(projectMatrix.in(file("core")), "core", List(
Platform.Jvm,
Platform.Js,
Expand Down Expand Up @@ -75,16 +91,6 @@ lazy val docs = http4sProj(projectMatrix.in(file("routing-docs")), "routing-docs
"GITHUB_BLOB_URL" -> s"$githubRepoUrl/blob/master",
"HTTP4S_SUFFIX" -> axis.suffix,
"HTTP4S_VERSION_COMMENT" -> axis.comment,
"HTTP4S_PATH_CODE" -> (axis match {
case Http4sAxis.v0_22 |
Http4sAxis.v0_23 |
Http4sAxis.v1_0_0_M41 =>
"Uri.Path.unsafeFromString(path)"
}),
"HTTP4S_UNSAFERUNSYNC_IMPORT" -> (axis match {
case Http4sAxis.v0_23 | Http4sAxis.v1_0_0_M41 => "import cats.effect.unsafe.implicits.global\n"
case _ => ""
}),
"PLAY_LATEST_DEPENDENCY" -> playDepString(PlayAxis.v3_0),
"PLAY_SUPPORTED_VERSIONS" -> PlayAxis.all.map(a => s"- ${a.version} -- `${playDepString(a)}`").mkString("\n"),
),
Expand Down Expand Up @@ -139,8 +145,8 @@ lazy val example = http4sProj(projectMatrix.in(file("example")), "example", _ =>
libraryDependencies ++= Seq(
http4sDep("circe", axis.version).value,
http4sDep("blaze-server", axis match {
case Http4sAxis.v0_23 => s"${axis.suffix}.12"
case Http4sAxis.v1_0_0_M41 => s"${axis.suffix.dropRight(2)}38"
case Http4sAxis.v0_23 => s"${axis.suffix}.17"
case Http4sAxis.v1_0_0_M44 => s"${axis.suffix.dropRight(2)}41"
case _ => axis.version
}).value,
),
Expand Down
5 changes: 3 additions & 2 deletions docs/implementations/http4s.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ val service2: HttpRoutes[IO] = HttpRoutes.of {
You can confirm that routes are matched correctly by passing some test requests to the service:

```scala mdoc
@HTTP4S_UNSAFERUNSYNC_IMPORT@import org.http4s.Request
import cats.effect.unsafe.implicits.global
import org.http4s.Request

def testRoute(service: HttpRoutes[IO], call: Call): String =
service
Expand All @@ -88,7 +89,7 @@ You can also check that requests matching none of your routes are not handled by
import org.http4s.{Method, Uri}

def unhandled(method: Method, path: String) =
service1.run(Request[IO](method = method, uri = Uri(path = @HTTP4S_PATH_CODE@))).value.unsafeRunSync()
service1.run(Request[IO](method = method, uri = Uri(path = Uri.Path.unsafeFromString(path)))).value.unsafeRunSync()

unhandled(GET, "/fake")

Expand Down
2 changes: 0 additions & 2 deletions docs/implementations/play.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ The currently supported versions of Play are:

@PLAY_SUPPORTED_VERSIONS@

**Note:** Java 8 is only supported on Play 2.8.x

Play handlers will be of the shape `Params => play.api.mvc.Handler`

First let's rebuild our example routes.
Expand Down
11 changes: 8 additions & 3 deletions example/src/main/scala/routing/example/App.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@ package routing.example

import cats.effect.{ExitCode, IO, IOApp}
import org.http4s.blaze.server.BlazeServerBuilder
import scala.concurrent.ExecutionContext // 0.22

object App extends IOApp {
// ++ 1.0.0-M44
import org.typelevel.log4cats.LoggerFactory
import org.typelevel.log4cats.noop.NoOpFactory

private implicit val loggerFactory: LoggerFactory[IO] = NoOpFactory[IO]
// -- 1.0.0-M44

override def run(args: List[String]): IO[ExitCode] =
BlazeServerBuilder[IO](ExecutionContext.global) // 0.22
BlazeServerBuilder[IO] // 0.23, 1.0.0-M41
BlazeServerBuilder[IO]
.bindHttp(8080, "localhost")
.withHttpApp(Controller.actions.orNotFound)
.serve
Expand Down
9 changes: 2 additions & 7 deletions http4s/src/main/scala/routing/http4s/Syntax.scala
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package routing
package http4s

import cats.Applicative
import cats.Defer // 0.22
import cats.Monad // 0.23, 1.0.0-M41
import cats.{Applicative, Monad}
import cats.data.OptionT
import org.{http4s => h}
import scala.annotation.tailrec
Expand Down Expand Up @@ -45,10 +43,7 @@ object syntax {
}

implicit class Http4sRouteObjectOps(private val route: Route.type) extends AnyVal {
def httpRoutes[F[_]: Applicative: Defer]( // 0.22
def httpRoutes[F[_]: Monad]( // 0.23, 1.0.0-M41
handlers: Handled[h.Request[F] => F[h.Response[F]]]*
): h.HttpRoutes[F] =
def httpRoutes[F[_]: Monad](handlers: Handled[h.Request[F] => F[h.Response[F]]]*): h.HttpRoutes[F] =
h.HttpRoutes[F](tryRoutes(_, handlers.toList))
}
}
Loading
Loading