From 44c27f20d383a7e07ea60d13bc5cfedb6b40d09d Mon Sep 17 00:00:00 2001 From: Brendan Doyle Date: Fri, 1 Sep 2023 09:51:33 -0700 Subject: [PATCH] * Supports rollback from pekko migration * Prepare for github actions release process --- .github/workflows/release.yml | 23 +++++++++++++++ README.md | 4 +++ build.sbt | 25 +++++++++++++---- .../persistence/mongodb/MongoDataModel.scala | 19 +++++++++++-- project/plugins.sbt | 4 +-- sonatype.sbt | 28 ------------------- 6 files changed, 63 insertions(+), 40 deletions(-) create mode 100644 .github/workflows/release.yml delete mode 100644 sonatype.sbt diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 00000000..bef4a568 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,23 @@ +name: Release +on: + push: + branches: [master, main] + tags: ["*"] +jobs: + publish: + runs-on: ubuntu-20.04 + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + - uses: actions/setup-java@v3 + with: + distribution: temurin + java-version: 17 + cache: sbt + - run: sbt ci-release + env: + PGP_PASSPHRASE: ${{ secrets.PGP_PASSPHRASE }} + PGP_SECRET: ${{ secrets.PGP_SECRET }} + SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }} + SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }} diff --git a/README.md b/README.md index 43da800c..4fdbb600 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,10 @@ * Test suite verifies against MongoDB 3.6, 4.0, 4.2 +### Preparing to migrate to Apache Pekko? Not to worry, an incremental upgrade is supported. + +* Provides forwards compatibility for Akka / Pekko features that persist internal class names, allowing for you to safely roll back your application after migration. + ### Using Akka 2.6? Use 3.x Series. [![Build Status](https://travis-ci.com/scullxbones/akka-persistence-mongo.svg?branch=master)](https://travis-ci.org/scullxbones/akka-persistence-mongo) ![Maven Central 2.12](https://maven-badges.herokuapp.com/maven-central/com.github.scullxbones/akka-persistence-mongo-common_2.12/badge.svg) diff --git a/build.sbt b/build.sbt index 9fa5b351..470bc1a6 100644 --- a/build.sbt +++ b/build.sbt @@ -1,4 +1,4 @@ -val releaseV = "3.0.8" +publish / skip := true val scala212V = "2.12.15" val scala213V = "2.13.7" @@ -39,8 +39,22 @@ val commonDeps = Seq( lazy val Ci = config("ci").extend(Test) ThisBuild / organization := "com.github.scullxbones" -ThisBuild / version := releaseV ThisBuild / scalaVersion := scalaV +ThisBuild / versionScheme := Some("semver-spec") + +import xerial.sbt.Sonatype._ + +ThisBuild / sonatypeProjectHosting := Some(GitHubHosting("scullxbones", "akka-persistence-mongo", "scullduggery@gmail.com")) +ThisBuild / licenses := Seq("APL2" -> url("http://www.apache.org/licenses/LICENSE-2.0.txt")) +ThisBuild / developers := List( + Developer( + "scullxbones", + "Brian Scully", + "@scullxbones", + url("https://github.com/scullxbones/") + ) + ) +ThisBuild / homepage := Some(url("https://github.com/scullxbones/akka-persistence-mongo")) val commonSettings = Seq( scalaVersion := scalaV, @@ -52,8 +66,6 @@ val commonSettings = Seq( "com.typesafe.akka" %% "akka-stream" % akkaV, "org.mongodb" % "mongodb-driver-legacy" % MongoJavaDriverVersion ), - version := releaseV, - organization := "com.github.scullxbones", scalacOptions ++= Seq( "-unchecked", "-deprecation", @@ -131,7 +143,8 @@ lazy val `akka-persistence-mongo-tools` = (project in file("tools")) .settings( libraryDependencies ++= Seq( "org.mongodb.scala" %% "mongo-scala-driver" % "2.7.0" % "compile" - ) + ), + publish / skip := true, ) .configs(Ci) @@ -139,6 +152,6 @@ lazy val `akka-persistence-mongo` = (project in file(".")) .aggregate(`akka-persistence-mongo-common`, `akka-persistence-mongo-rxmongo`, `akka-persistence-mongo-scala`, `akka-persistence-mongo-tools`) .settings( crossScalaVersions := Nil, - skip in publish := true, + publish / skip := true, publishTo := Some(Resolver.file("file", new File("target/unusedrepo"))) ) diff --git a/common/src/main/scala/akka/contrib/persistence/mongodb/MongoDataModel.scala b/common/src/main/scala/akka/contrib/persistence/mongodb/MongoDataModel.scala index 9d410a32..5022c989 100644 --- a/common/src/main/scala/akka/contrib/persistence/mongodb/MongoDataModel.scala +++ b/common/src/main/scala/akka/contrib/persistence/mongodb/MongoDataModel.scala @@ -8,7 +8,7 @@ import akka.actor.ActorRef import akka.persistence.journal.Tagged import akka.persistence.query.{EventEnvelope, Offset} import akka.persistence.{AtomicWrite, PersistentRepr} -import akka.serialization.{Serialization, SerializerWithStringManifest} +import akka.serialization.{Serialization, Serializer, SerializerWithStringManifest} import scala.collection.immutable.{Seq => ISeq} import scala.language.existentials @@ -51,15 +51,28 @@ case class Serialized[C <: AnyRef](bytes: Array[Byte], lazy val content: C = { val clazz = loadClass.getClassFor[X forSome { type X <: AnyRef }](className) + Try(tryDeserialize(clazz, clazz.flatMap(c => Try(ser.serializerFor(c))))) + .recover({ + case _ if className.startsWith("org.apache.pekko.") => + val backwardsCompatClazz = loadClass.getClassFor[X forSome { type X <: AnyRef }](className.replaceFirst("org.apache.pekko", "akka")) + tryDeserialize(backwardsCompatClazz, backwardsCompatClazz.flatMap(c => Try(ser.serializerFor(c)))) + case x => throw x + }) match { + case Failure(x) => throw x + case Success(deser) => deser + } + } - val tried = (serializedManifest,serializerId,clazz.flatMap(c => Try(ser.serializerFor(c)))) match { + private def tryDeserialize(clazz: Try[Class[_ <: X forSome {type X <: AnyRef}]], + serializer: Try[Serializer]): C = { + val tried = (serializedManifest, serializerId, serializer) match { // Manifest was serialized, class exists ~ prefer read-time configuration case (Some(manifest), _, Success(clazzSer)) => ser.deserialize(bytes, clazzSer.identifier, manifest) // No manifest id serialized, prefer read-time configuration case (None, _, Success(clazzSer)) => - ser.deserialize[X forSome { type X <: AnyRef }](bytes, clazzSer.identifier, clazz.toOption) + ser.deserialize[X forSome {type X <: AnyRef}](bytes, clazzSer.identifier, clazz.toOption) // Manifest, id were serialized, class doesn't exist - use write-time configuration case (Some(manifest), Some(id), Failure(_)) => diff --git a/project/plugins.sbt b/project/plugins.sbt index 443d37bb..ec40530f 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -1,5 +1,3 @@ libraryDependencies += "org.scala-lang" % "scala-compiler" % scalaVersion.value -addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "3.9.10") - -addSbtPlugin("com.jsuereth" % "sbt-pgp" % "2.1.1") +addSbtPlugin("com.github.sbt" % "sbt-ci-release" % "1.5.12") diff --git a/sonatype.sbt b/sonatype.sbt deleted file mode 100644 index 3ca183cd..00000000 --- a/sonatype.sbt +++ /dev/null @@ -1,28 +0,0 @@ -publishMavenStyle := true - -licenses := Seq("APL2" -> url("http://www.apache.org/licenses/LICENSE-2.0.txt")) - -import xerial.sbt.Sonatype._ -sonatypeProjectHosting := Some(GitHubHosting("scullxbones", "akka-persistence-mongo", "scullduggery@gmail.com")) - -pomExtra in Global := { - https://github.com/scullxbones/akka-persistence-mongo - - - Apache 2 - http://www.apache.org/licenses/LICENSE-2.0.txt - - - - scm:git:github.com/scullxbones/akka-persistence-mongo.git - scm:git:git@github.com:scullxbones/akka-persistence-mongo.git - github.com/scullxbones/akka-persistence-mongo.git - - - - scullxbones - Brian Scully - https://github.com/scullxbones/ - - -}