Skip to content

Commit

Permalink
Apply minor patches to ease onboarding to Pekko
Browse files Browse the repository at this point in the history
  • Loading branch information
PawelLipski committed Aug 19, 2023
1 parent 14ac09d commit 8299032
Show file tree
Hide file tree
Showing 29 changed files with 123 additions and 76 deletions.
22 changes: 10 additions & 12 deletions .github/workflows/standard-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ name: Standard Workflow

on: workflow_call

concurrency:
group: ${{ github.head_ref }}
cancel-in-progress: true

jobs:
code-style-check:
runs-on: ubuntu-latest
Expand All @@ -15,9 +19,6 @@ jobs:
with:
java-version: [email protected]

- name: Resolve dependencies
run: sbt update

- name: Run code checks
run: |
PATH=$PATH:./scripts
Expand All @@ -33,6 +34,9 @@ jobs:
# Curiously, scalafmtCheckAll doesn't cover *.sbt files, hence scalafmtSbtCheck is needed as well
run: sbt scalafmtCheckAll scalafmtSbtCheck "scalafixAll --check"

- name: Substitute sbt plugin snapshot version
run: ./scripts/substitute-sbt-plugin-snapshot-version

- name: Check code style - examples/event-migration
run: sbt scalafmtCheckAll scalafmtSbtCheck "scalafixAll --check"
working-directory: examples/event-migration
Expand All @@ -57,9 +61,6 @@ jobs:
with:
java-version: [email protected]

- name: Resolve dependencies
run: sbt update

- name: Compile
run: sbt compile Test/compile

Expand All @@ -84,9 +85,6 @@ jobs:
with:
java-version: [email protected]

- name: Resolve dependencies
run: sbt update

- name: Compile
run: sbt compile Test/compile

Expand All @@ -110,9 +108,6 @@ jobs:
with:
java-version: [email protected]

- name: Resolve dependencies
run: sbt update

- name: Compile
run: sbt compile Test/compile

Expand Down Expand Up @@ -151,6 +146,9 @@ jobs:
with:
java-version: [email protected]

- name: Substitute sbt plugin snapshot version
run: ./scripts/substitute-sbt-plugin-snapshot-version

- name: Test event-migration-examples
run: sbt test
working-directory: examples/event-migration
Expand Down
5 changes: 5 additions & 0 deletions .remarkrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
plugins:
lint-no-dead-urls:
skipUrlPatterns:
# TODO (#325): remove these patterns
- https://github.com/VirtusLab/pekko-serialization-helper
4 changes: 2 additions & 2 deletions .scala-steward.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ commits.message = "Scala-Steward: Update ${artifactName} from ${currentVersion}

buildRoots = [
".",
"examples/akka-cluster-app/",
"examples/akka-persistence-app/",
"examples/event-migration/",
"examples/example-app/",
"sbt-akka-serialization-helper/src/sbt-test/sbt-dumpschema/dependencies",
"sbt-akka-serialization-helper/src/sbt-test/sbt-dumpschema/simple",
]

updates.pin = [
updates.pin = [
# * org.scala-lang.modules:scala-xml_2.12:2.1.0 (early-semver) is selected over 1.2.0
# +- com.github.sbt:sbt-native-packager:1.9.10 (sbtVersion=1.0, scalaVersion=2.12) (depends on 2.1.0)
# +- com.typesafe.play:twirl-api_2.12:1.5.1 (depends on 1.2.0)
Expand Down
16 changes: 4 additions & 12 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,10 @@ You might as well use any other profiler, but using https://github.com/jvm-profi

### Code quality

Before committing, don't forget to type
```shell
sbt scalafmtAll scalafixAll scalafmtSbt
```
to format the code, .sbt files and check imports. Run this command in the following directories:
- the base directory (`.`)
- `examples/akka-cluster-app`
- `examples/akka-persistence-app`
- `examples/event-migration`
You can use `pre-commit` hook, provided in `./pre-commit`, to do the formatting and checking automatically.

Additionally, all warnings locally are escalated to errors in CI, so make sure there are none.
Don't forget to run `./scripts/format-code` before opening a pull request.
You can symlink this file as git `pre-commit` hook, but beware that it runs quite long.

All local Scala compilation warnings are escalated to errors in CI, so make sure there are none.

### Compatible JDK versions

Expand Down
12 changes: 9 additions & 3 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ ThisBuild / licenses := List(
"MIT License" -> url("https://github.com/VirtusLab/akka-serialization-helper/blob/main/LICENSE"))
ThisBuild / developers := List(
Developer("MarconZet", "Marcin Złakowski", "[email protected]", url("https://github.com/MarconZet")),
Developer("HubertBalcerzak", "Hubert Balcerzak", "[email protected]", url("https://github.com/HubertBalcerzak")),
Developer(
"LukaszKontowski",
"Łukasz Kontowski",
"[email protected]",
url("https://github.com/LukaszKontowski")),
Developer("PawelLipski", "Paweł Lipski", "[email protected]", url("https://github.com/PawelLipski")))

sonatypeProfileName := "org.virtuslab"
Expand All @@ -45,7 +49,8 @@ Global / onChangedBuildSource := ReloadOnSourceChanges

ThisBuild / semanticdbEnabled := true
ThisBuild / semanticdbVersion := "4.7.8"
ThisBuild / scalafixDependencies += "com.github.liancheng" %% "organize-imports" % "0.6.0"

ThisBuild / resolvers += Resolver.ApacheMavenSnapshotsRepo

lazy val commonSettings = Seq(
sonatypeProfileName := "org.virtuslab",
Expand Down Expand Up @@ -148,6 +153,7 @@ lazy val serializabilityCheckerCompilerPlugin = (projectMatrix in file("serializ
.settings(name := "serializability-checker-compiler-plugin")
.settings(commonSettings)
.settings(crossScalaVersions := testAgainstScalaVersions)
.settings(resolvers ++= Resolver.sonatypeOssRepos("snapshots"))
.settings(
libraryDependencies ++= {
CrossVersion
Expand All @@ -165,7 +171,7 @@ lazy val serializabilityCheckerCompilerPlugin = (projectMatrix in file("serializ
akkaProjections % Test,
betterFiles % Test,
akkaGrpc % Test,
akkaGrpcWebSupport % Test))
akkaHttpCors % Test))
.dependsOn(annotation)
.jvmPlatform(scalaVersions = targetScalaVersions)

Expand Down
1 change: 0 additions & 1 deletion examples/akka-cluster-app/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,3 @@ lazy val logbackDependency = "ch.qos.logback" % "logback-classic" % logbackVersi

ThisBuild / semanticdbEnabled := true
ThisBuild / semanticdbVersion := "4.7.8"
ThisBuild / scalafixDependencies += "com.github.liancheng" %% "organize-imports" % "0.6.0"
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ object App {
// Override the configuration of the port when specified as program argument
val config = ConfigFactory
.parseString(s"""
akka.remote.artery.canonical.port=$port
akka.remote.artery.canonical.port = $port
akka.cluster.roles = [$role]
""")
.withFallback(ConfigFactory.load("example"))
Expand Down
64 changes: 33 additions & 31 deletions examples/akka-persistence-app/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,16 @@ Test / logBuffered := false
fork := true // must be true due to https://discuss.lightbend.com/t/akka-projection-getting-started-guide-example-could-not-run-eventgeneratorapp/9434/2
Global / cancelable := false // ctrl-c

val AkkaVersion = "2.6.20"
val AkkaHttpVersion = "10.2.10"
val AkkaManagementVersion = "1.1.4"
val AkkaPersistenceJdbcVersion = "5.1.0"
val AkkaProjectionVersion = "1.2.5"
val ScalikeJdbcVersion = "3.5.0"
val CirceVersion = "0.14.5"
ThisBuild / resolvers += Resolver.ApacheMavenSnapshotsRepo

val akkaVersion = "2.6.20"
val akkaHttpVersion = "10.2.10"
val akkaHttp2SupportVersion = "10.2.10"
val akkaManagementVersion = "1.1.4"
val akkaPersistenceJdbcVersion = "5.1.0"
val akkaProjectionVersion = "1.2.5"
val circeVersion = "0.14.5"
val scalikeJdbcVersion = "3.5.0"

enablePlugins(AkkaGrpcPlugin, JavaAppPackaging, DockerPlugin, AkkaSerializationHelperPlugin)
dockerBaseImage := "docker.io/library/adoptopenjdk:11-jre-hotspot"
Expand All @@ -35,41 +38,40 @@ dockerRepository := sys.props.get("docker.registry")

libraryDependencies ++= Seq(
// 1. Basic dependencies for a clustered application
"com.typesafe.akka" %% "akka-stream" % AkkaVersion,
"com.typesafe.akka" %% "akka-cluster-typed" % AkkaVersion,
"com.typesafe.akka" %% "akka-cluster-sharding-typed" % AkkaVersion,
"com.typesafe.akka" %% "akka-actor-testkit-typed" % AkkaVersion % Test,
"com.typesafe.akka" %% "akka-stream" % akkaVersion,
"com.typesafe.akka" %% "akka-cluster-typed" % akkaVersion,
"com.typesafe.akka" %% "akka-cluster-sharding-typed" % akkaVersion,
"com.typesafe.akka" %% "akka-actor-testkit-typed" % akkaVersion % Test,
// Akka Management powers Health Checks and Akka Cluster Bootstrapping
"com.lightbend.akka.management" %% "akka-management" % AkkaManagementVersion,
"com.typesafe.akka" %% "akka-http" % AkkaHttpVersion,
"com.typesafe.akka" %% "akka-http-spray-json" % AkkaHttpVersion,
"com.lightbend.akka.management" %% "akka-management-cluster-http" % AkkaManagementVersion,
"com.lightbend.akka.management" %% "akka-management-cluster-bootstrap" % AkkaManagementVersion,
"com.lightbend.akka.discovery" %% "akka-discovery-kubernetes-api" % AkkaManagementVersion,
"com.typesafe.akka" %% "akka-discovery" % AkkaVersion,
"com.lightbend.akka.management" %% "akka-management" % akkaManagementVersion,
"com.typesafe.akka" %% "akka-http" % akkaHttpVersion,
"com.typesafe.akka" %% "akka-http-spray-json" % akkaHttpVersion,
"com.lightbend.akka.management" %% "akka-management-cluster-http" % akkaManagementVersion,
"com.lightbend.akka.management" %% "akka-management-cluster-bootstrap" % akkaManagementVersion,
"com.lightbend.akka.discovery" %% "akka-discovery-kubernetes-api" % akkaManagementVersion,
"com.typesafe.akka" %% "akka-discovery" % akkaVersion,
// Common dependencies for logging and testing
"com.typesafe.akka" %% "akka-slf4j" % AkkaVersion,
"com.typesafe.akka" %% "akka-slf4j" % akkaVersion,
"ch.qos.logback" % "logback-classic" % "1.4.7",
"org.scalatest" %% "scalatest" % "3.2.12" % Test,
// 2. Using gRPC and/or protobuf
"com.typesafe.akka" %% "akka-http2-support" % AkkaHttpVersion,
"com.typesafe.akka" %% "akka-http2-support" % akkaHttp2SupportVersion,
// 3. Using Akka Persistence
"com.typesafe.akka" %% "akka-persistence-typed" % AkkaVersion,
"com.typesafe.akka" %% "akka-serialization-jackson" % AkkaVersion,
"com.lightbend.akka" %% "akka-persistence-jdbc" % AkkaPersistenceJdbcVersion,
"com.typesafe.akka" %% "akka-persistence-testkit" % AkkaVersion % Test,
"com.typesafe.akka" %% "akka-persistence-typed" % akkaVersion,
"com.typesafe.akka" %% "akka-serialization-jackson" % akkaVersion,
"com.lightbend.akka" %% "akka-persistence-jdbc" % akkaPersistenceJdbcVersion,
"com.typesafe.akka" %% "akka-persistence-testkit" % akkaVersion % Test,
"org.postgresql" % "postgresql" % "42.6.0",
// 4. Querying or projecting data from Akka Persistence
"com.typesafe.akka" %% "akka-persistence-query" % AkkaVersion,
"com.lightbend.akka" %% "akka-projection-eventsourced" % AkkaProjectionVersion,
"com.lightbend.akka" %% "akka-projection-jdbc" % AkkaProjectionVersion,
"org.scalikejdbc" %% "scalikejdbc" % ScalikeJdbcVersion,
"org.scalikejdbc" %% "scalikejdbc-config" % ScalikeJdbcVersion,
"com.typesafe.akka" %% "akka-persistence-query" % akkaVersion,
"com.lightbend.akka" %% "akka-projection-eventsourced" % akkaProjectionVersion,
"com.lightbend.akka" %% "akka-projection-jdbc" % akkaProjectionVersion,
"org.scalikejdbc" %% "scalikejdbc" % scalikeJdbcVersion,
"org.scalikejdbc" %% "scalikejdbc-config" % scalikeJdbcVersion,
// 5. Dependencies needed to use Akka Serialization Helper with circe codecs
"io.circe" %% "circe-core" % CirceVersion,
"io.circe" %% "circe-core" % circeVersion,
AkkaSerializationHelperPlugin.annotation,
AkkaSerializationHelperPlugin.circeAkkaSerializer)

ThisBuild / semanticdbEnabled := true
ThisBuild / semanticdbVersion := "4.7.8"
ThisBuild / scalafixDependencies += "com.github.liancheng" %% "organize-imports" % "0.6.0"
2 changes: 2 additions & 0 deletions examples/akka-persistence-app/project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
resolvers += Resolver.ApacheMavenSnapshotsRepo

addSbtPlugin("com.github.sbt" % "sbt-native-packager" % "1.9.9")
addSbtPlugin("com.lightbend.akka.grpc" % "sbt-akka-grpc" % "2.1.6")
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.0")
Expand Down
2 changes: 0 additions & 2 deletions examples/event-migration/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ libraryDependencies += "io.circe" %% "circe-generic-extras" % circeGenericExtras
libraryDependencies ++= Seq(
"io.bullet" %% "borer-core",
"io.bullet" %% "borer-derivation",
"io.bullet" %% "borer-compat-akka",
"io.bullet" %% "borer-compat-circe",
"io.bullet" %% "borer-compat-scodec").map(_ % borerVersion)

Expand All @@ -27,5 +26,4 @@ scalacOptions += "-Ymacro-annotations"

ThisBuild / semanticdbEnabled := true
ThisBuild / semanticdbVersion := "4.7.8"
ThisBuild / scalafixDependencies += "com.github.liancheng" %% "organize-imports" % "0.6.0"
scalacOptions += "-Ywarn-unused"
5 changes: 3 additions & 2 deletions project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ object Dependencies {
val scalaVersion213 = "2.13.11"
val scalaVersion212 = "2.12.18"

val akkaProjectionVersion = "1.2.5"
val akkaVersion = "2.6.20"
val borerVersion = "1.8.0"
val circeYamlVersion = "0.14.2"
Expand All @@ -21,11 +22,11 @@ object Dependencies {
val akkaActorTyped = "com.typesafe.akka" %% "akka-actor-typed" % akkaVersion
val akkaStream = "com.typesafe.akka" %% "akka-stream" % akkaVersion
val akkaPersistenceTyped = "com.typesafe.akka" %% "akka-persistence-typed" % akkaVersion
val akkaProjections = "com.lightbend.akka" %% "akka-projection-eventsourced" % "1.2.5"
val akkaProjections = "com.lightbend.akka" %% "akka-projection-eventsourced" % akkaProjectionVersion
val akkaTestKitTyped = "com.typesafe.akka" %% "akka-actor-testkit-typed" % akkaVersion
val akkaStreamTestKit = "com.typesafe.akka" %% "akka-stream-testkit" % akkaVersion

val akkaGrpcWebSupport = "ch.megard" %% "akka-http-cors" % "1.2.0"
val akkaHttpCors = "ch.megard" %% "akka-http-cors" % "1.2.0" // required by akka-grpc-runtime
val akkaGrpc = "com.lightbend.akka.grpc" %% "akka-grpc-runtime" % "2.1.6"

val borerCore = "io.bullet" %% "borer-core" % borerVersion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ lazy val scala212 = "2.12.14"
name := "simple-dump"
version := "0.1"
scalaVersion := scala213
libraryDependencies += "com.typesafe.akka" %% "akka-persistence-typed" % "2.6.16"
val akkaVersion = "2.6.20"
libraryDependencies += "com.typesafe.akka" %% "akka-persistence-typed" % akkaVersion
crossScalaVersions := Seq(scala213, scala212)

enablePlugins(AkkaSerializationHelperPlugin)
Expand Down
9 changes: 9 additions & 0 deletions scripts/akka-to-pekko
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bash

set -e -o pipefail -u

git ls-files | grep -Ev 'akka-to-pekko|scalafmt\.conf|scala-steward\.conf' | xargs sed -E -f akka-to-pekko.sed -i

echo 'libraryDependencySchemes += "org.apache.pekko" %% "pekko-http-core" % "always"' >> examples/akka-persistence-app/build.sbt

git ls-files | grep -v 'akka-to-pekko' | rename -e 's/akka/pekko/' -e 's/Akka/Pekko/' --make-dirs --stdin
17 changes: 17 additions & 0 deletions scripts/akka-to-pekko.sed
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
s/"akka\./"org.apache.pekko./
s/doc\.akka\.io/pekko.apache.org/g
s/com\.lightbend\.akka(\.\w+)?/org.apache.pekko/
s/com\.typesafe\.akka/org.apache.pekko/g
s/import akka/import org.apache.pekko/
s/akka/pekko/g
s/Akka/Pekko/g

s/"ch.megard" %% "pekko-http-cors" % ".*"/"ch.megard" %% "pekko-http-cors" % "0.0.0-SNAPSHOT"/
s/"org.apache.pekko" %% "pekko-grpc-runtime" % ".*"/"org.apache.pekko" %% "pekko-grpc-runtime" % "1.0.0-RC2-2-56662643-SNAPSHOT"/
s/"org.apache.pekko" % "sbt-pekko-grpc" % ".*"/"org.apache.pekko" % "sbt-pekko-grpc" % "0.0.0-94-0bfb43a6-SNAPSHOT"/
s/val pekkoHttp2SupportVersion = .*/val pekkoHttp2SupportVersion = "0.0.0+4272-045c925b-SNAPSHOT"/
s/val pekkoHttpVersion = .*/val pekkoHttpVersion = "1.0.0"/
s/val pekkoManagementVersion = .*/val pekkoManagementVersion = "1.0.0"/
s/val pekkoPersistenceJdbcVersion = .*/val pekkoPersistenceJdbcVersion = "0.0.0+998-6a9e5841-SNAPSHOT"/
s/val pekkoProjectionVersion = .*/val pekkoProjectionVersion = "0.0.0+68-6f80a745-SNAPSHOT"/
s/val pekkoVersion = .*/val pekkoVersion = "1.0.1"/
4 changes: 1 addition & 3 deletions pre-commit → scripts/format-code
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#!/bin/sh

# This can be symlinked from .git/hooks/pre-commit in the repo with:
# ln -s ../../pre-commit .git/hooks/pre-commit
# Make sure the file is executable.
set -e

sbt scalafmtAll scalafixAll scalafmtSbt

Expand Down
13 changes: 13 additions & 0 deletions scripts/substitute-sbt-plugin-snapshot-version
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bash

set -e -o pipefail -u

sbt publishLocal

version=$(ls -1t ~/.ivy2/local/org.virtuslab.ash/sbt-akka-serialization-helper/scala_2.12/sbt_1.0/ | head -1)
# Version can be more elegantly extracted using:
# sbt -Dsbt.supershell=false -error "print sbtPekkoSerializationHelper/version"
# but the problem is that snapshot versions include minute-resolution timestamp,
# which is likely to change from the preceding `sbt publishLocal`.

find . -type f | grep '\.sbt$' | xargs sed -E 's/("sbt-akka-serialization-helper") % ".*"/\1 % "'"$version"'"/' -i
2 changes: 1 addition & 1 deletion scripts/validate-markdown-links
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ case ${GITHUB_REF-} in
# We don't want a main branch/tag build to fail because some linked website has a random downtime.
refs/heads/main) extra_options='' ;;
refs/tags/*) extra_options='' ;;
*) extra_options='--use=lint-no-dead-urls' ;;
*) extra_options='--use=lint-no-dead-urls --rc-path=.remarkrc.yml' ;;
esac

remark --use=validate-links $extra_options --ignore-path=.gitignore --frail .
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ class SerializabilityCheckerCompilerPluginComponent(
We should ignore scala.Any and other possible ignoredTypes in such cases.
In particular, mentioned problem might occur when using ActorSystem[_] implicitly as parameter.
For example, such scenario occurs when using object of type ActorSystem[_] in method calls
that in fact require akka.actor.ClassicActorSystemProvider (which is a supertype for ActorSystem).
that in fact require ClassicActorSystemProvider (which is a supertype for ActorSystem).
*/
private def typeArgsAreHiddenIgnoreTypes(typ: global.Type): Boolean =
if (typ.typeSymbol.fullName.matches(".+\\._\\$\\d"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package org.random.project

import akka.actor.ActorRef
import akka.pattern._
import akka.util.Timeout
import org.virtuslab.ash.annotation.SerializabilityTrait

object AskSignClassicTest {
final case class Msg() extends MySerializable
implicit val timeout: akka.util.Timeout = ???
implicit val timeout: Timeout = ???

val ref: ActorRef = ???
val msg = Msg()
Expand Down
Loading

0 comments on commit 8299032

Please sign in to comment.