Skip to content

Commit

Permalink
Merge pull request #68 from sh0hei/hello-scala3
Browse files Browse the repository at this point in the history
Hello, Scala3 🎉
  • Loading branch information
sh0hei authored Jun 2, 2021
2 parents e26371b + 8e2bd47 commit 8f25d17
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 38 deletions.
14 changes: 12 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
scala: [2.12.14, 2.13.6]
scala: [2.12.14, 2.13.6, 3.0.0]
java: [adopt@1.8]
runs-on: ${{ matrix.os }}
steps:
Expand Down Expand Up @@ -77,7 +77,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
scala: [2.13.6]
scala: [3.0.0]
java: [adopt@1.8]
runs-on: ${{ matrix.os }}
steps:
Expand Down Expand Up @@ -123,6 +123,16 @@ jobs:
tar xf targets.tar
rm targets.tar
- name: Download target directories (3.0.0)
uses: actions/download-artifact@v2
with:
name: target-${{ matrix.os }}-3.0.0-${{ matrix.java }}

- name: Inflate target directories (3.0.0)
run: |
tar xf targets.tar
rm targets.tar
- env:
PGP_PASSPHRASE: ${{ secrets.PGP_PASSPHRASE }}
PGP_SECRET: ${{ secrets.PGP_SECRET }}
Expand Down
25 changes: 25 additions & 0 deletions HOW-TO-RELEASE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Release process

How to create a new [release](../../releases).

## Releasing

The release process is automated thanks to:
- https://github.com/djspiewak/sbt-github-actions#integration-with-sbt-ci-release
- https://github.com/olafurpg/sbt-ci-release

To release, push a git tag:

```
git tag -a v0.1.0 -m "v0.1.0"
git push origin v0.1.0
```
Note that the tag version MUST start with `v`.

Wait for the [CI pipeline](../../actions) to release the new version. Publishing the artifacts on maven central can take time.

## Updating the release notes

Open the [releases](../../releases). A draft should already be prepared.

Edit the draft release to set the released version. Complete the release notes if necessary. And save it.
27 changes: 20 additions & 7 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
val isScala3 = Def.setting(
CrossVersion.partialVersion(scalaVersion.value).exists(_._1 == 3)
)

name := "sangria-ion"
organization := "org.sangria-graphql"
mimaPreviousArtifacts := Set("org.sangria-graphql" %% "sangria-ion" % "2.0.0")
mimaPreviousArtifacts := {
if (isScala3.value)
Set.empty
else
Set("org.sangria-graphql" %% "sangria-ion" % "2.0.0")
}

description := "Sangria Amazon Ion marshalling"
homepage := Some(url("http://sangria-graphql.org"))
homepage := Some(url("https://sangria-graphql.github.io/"))
licenses := Seq(
"Apache License, ASL Version 2.0" -> url("http://www.apache.org/licenses/LICENSE-2.0"))
"Apache License, ASL Version 2.0" -> url("https://www.apache.org/licenses/LICENSE-2.0"))

ThisBuild / crossScalaVersions := Seq("2.12.14", "2.13.6")
ThisBuild / crossScalaVersions := Seq("2.12.14", "2.13.6", "3.0.0")
ThisBuild / scalaVersion := crossScalaVersions.value.last
ThisBuild / githubWorkflowPublishTargetBranches := List()
ThisBuild / githubWorkflowBuildPreamble ++= List(
Expand All @@ -16,8 +25,12 @@ ThisBuild / githubWorkflowBuildPreamble ++= List(
)

scalacOptions ++= Seq("-deprecation", "-feature")

scalacOptions += "-target:jvm-1.8"
scalacOptions ++= {
if (isScala3.value)
Seq("-Xtarget:8")
else
Seq("-target:jvm-1.8")
}
javacOptions ++= Seq("-source", "8", "-target", "8")

libraryDependencies ++= Seq(
Expand All @@ -33,7 +46,7 @@ git.remoteRepo := "git@github.com:sangria-graphql/sangria-ion.git"
ThisBuild / githubWorkflowTargetTags ++= Seq("v*")
ThisBuild / githubWorkflowPublishTargetBranches :=
Seq(RefPredicate.StartsWith(Ref.Tag("v")))
ThisBuild / githubWorkflowPublish := Seq(
ThisBuild / githubWorkflowPublish := Seq(
WorkflowStep.Sbt(
List("ci-release"),
env = Map(
Expand Down
7 changes: 1 addition & 6 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
resolvers += Resolver.url(
"typesafe sbt-plugins",
url("https://dl.bintray.com/typesafe/sbt-plugins")
)(Resolver.ivyStylePatterns)
resolvers += "jgit-repo".at("https://download.eclipse.org/jgit/maven")

addSbtPlugin("com.typesafe" % "sbt-mima-plugin" % "0.9.2")
addSbtPlugin("com.typesafe.sbt" % "sbt-git" % "1.0.1")
addSbtPlugin("com.typesafe.sbt" % "sbt-site" % "1.4.1")
Expand All @@ -12,3 +6,4 @@ addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.8.2")
addSbtPlugin("org.scoverage" % "sbt-coveralls" % "1.2.7")
addSbtPlugin("com.codecommit" % "sbt-github-actions" % "0.12.0")
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.4.2")
addSbtPlugin("com.geirsson" % "sbt-ci-release" % "1.5.7")
37 changes: 19 additions & 18 deletions src/main/scala/sangria/marshalling/ion.scala
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ object ion {

def nullNode = system.newNull()

def renderPretty(node: IonValue) = renderPrettyValue(system, node)
def renderCompact(node: IonValue) = renderCompactValue(system, node)
def renderPretty(node: IonValue): String = renderPrettyValue(system, node)
def renderCompact(node: IonValue): String = renderCompactValue(system, node)

override def capabilities =
Set(
Expand All @@ -101,30 +101,30 @@ object ion {
IonClobStringSupport)
}

implicit def ionResultMarshaller(implicit system: IonSystem) =
implicit def ionResultMarshaller(implicit system: IonSystem): IonResultMarshaller =
new IonResultMarshaller(system)

class IonMarshallerForType(system: IonSystem) extends ResultMarshallerForType[IonValue] {
val marshaller = new IonResultMarshaller(system)
}

implicit def ionMarshallerForType(implicit system: IonSystem) =
implicit def ionMarshallerForType(implicit system: IonSystem): IonMarshallerForType =
new IonMarshallerForType(system)

class IonInputUnmarshaller(system: IonSystem) extends InputUnmarshaller[IonValue] {
def getRootMapValue(node: IonValue, key: String) = Option(node.asInstanceOf[IonStruct].get(key))

def isMapNode(node: IonValue) = node.isInstanceOf[IonStruct]
def isMapNode(node: IonValue): Boolean = node.isInstanceOf[IonStruct]
def getMapValue(node: IonValue, key: String) = Option(node.asInstanceOf[IonStruct].get(key))

// preserve order
def getMapKeys(node: IonValue) =
node.asInstanceOf[IonStruct].iterator().asScala.map(_.getFieldName).toVector

def isListNode(node: IonValue) = node.isInstanceOf[IonList]
def isListNode(node: IonValue): Boolean = node.isInstanceOf[IonList]
def getListValue(node: IonValue) = node.asInstanceOf[IonList].asScala.toSeq

def isDefined(node: IonValue) = !node.isNullValue
def isDefined(node: IonValue): Boolean = !node.isNullValue
def getScalarValue(node: IonValue) =
node match {
case v: IonBool => v.booleanValue
Expand All @@ -138,8 +138,9 @@ object ion {

def getScalaScalarValue(node: IonValue) = getScalarValue(node)

def isEnumNode(node: IonValue) = node.isInstanceOf[IonText] || node.isInstanceOf[IonClob]
def isScalarNode(node: IonValue) =
def isEnumNode(node: IonValue): Boolean =
node.isInstanceOf[IonText] || node.isInstanceOf[IonClob]
def isScalarNode(node: IonValue): Boolean =
node match {
case _: IonBool | _: IonText | _: IonFloat | _: IonInt | _: IonDecimal | _: IonClob => true
case _ => false
Expand All @@ -149,28 +150,28 @@ object ion {
def getVariableName(node: IonValue) =
throw new IllegalArgumentException("variables are not supported")

def render(node: IonValue) = renderCompactValue(system, node)
def render(node: IonValue): String = renderCompactValue(system, node)
}

implicit def ionInputUnmarshaller(implicit system: IonSystem) =
implicit def ionInputUnmarshaller(implicit system: IonSystem): IonInputUnmarshaller =
new IonInputUnmarshaller(system)

class IonToInput(system: IonSystem) extends ToInput[IonValue, IonValue] {
def toInput(value: IonValue) = (value, ionInputUnmarshaller(system))
}

implicit def ionToInput(implicit system: IonSystem) =
implicit def ionToInput(implicit system: IonSystem): IonToInput =
new IonToInput(system)

class IonFromInput(system: IonSystem) extends FromInput[IonValue] {
val marshaller = ionResultMarshaller(system)
def fromResult(node: marshaller.Node) = node
def fromResult(node: marshaller.Node) = node.asInstanceOf[IonValue]
}

implicit def ionFromInput(implicit system: IonSystem) =
implicit def ionFromInput(implicit system: IonSystem): IonFromInput =
new IonFromInput(system)

private def renderPrettyValue(system: IonSystem, value: IonValue) = {
private def renderPrettyValue(system: IonSystem, value: IonValue): String = {
val buf = new StringBuffer
val writer = IonTextWriterBuilder.pretty().build(buf)

Expand All @@ -182,7 +183,7 @@ object ion {
} finally writer.close()
}

private def renderCompactValue(system: IonSystem, value: IonValue) = {
private def renderCompactValue(system: IonSystem, value: IonValue): String = {
val buf = new StringBuffer
val writer = IonTextWriterBuilder.standard().build(buf)

Expand All @@ -195,10 +196,10 @@ object ion {
}

class IonInputParser(system: IonSystem) extends InputParser[IonValue] {
def parse(str: String) = Try(system.getLoader.load(str).get(0))
def parse(str: String): Try[IonValue] = Try(system.getLoader.load(str).get(0))
}

implicit def ionInputParser(implicit system: IonSystem) =
implicit def ionInputParser(implicit system: IonSystem): IonInputParser =
new IonInputParser(system)

}
8 changes: 3 additions & 5 deletions src/test/scala/sangria/marshalling/IonSupportSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ package sangria.marshalling

import java.nio.charset.Charset
import java.util.{Calendar, TimeZone}

import sangria.marshalling.testkit._
import software.amazon.ion.Timestamp
import software.amazon.ion.{IonSystem, IonValue, Timestamp}
import software.amazon.ion.system.IonSystemBuilder
import org.scalatest.matchers.should.Matchers
import org.scalatest.wordspec.AnyWordSpec
Expand All @@ -17,7 +16,7 @@ class IonSupportSpec
with ParsingBehaviour {
import sangria.marshalling.ion._

implicit val ionSystem = IonSystemBuilder.standard().build()
implicit val ionSystem: IonSystem = IonSystemBuilder.standard().build()

"Ion integration" should {
behave.like(`value (un)marshaller`(ionResultMarshaller))
Expand All @@ -36,7 +35,7 @@ class IonSupportSpec
)))
}

val toRender =
val toRender: IonValue =
ionSystem.getLoader
.load("""
{a:[null,123,[
Expand Down Expand Up @@ -92,7 +91,6 @@ class IonSupportSpec
}

val rm = ionResultMarshaller
val iu = ionInputUnmarshaller

val calendar = {
val cal = Calendar.getInstance(TimeZone.getTimeZone("CET"))
Expand Down

0 comments on commit 8f25d17

Please sign in to comment.