Skip to content

Commit

Permalink
use zio-json explicitEmptyCollections
Browse files Browse the repository at this point in the history
  • Loading branch information
ThijsBroersen committed Dec 13, 2024
1 parent e7dec54 commit 28c49c4
Show file tree
Hide file tree
Showing 10 changed files with 132 additions and 133 deletions.
1 change: 0 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ name: CI
env:
JDK_JAVA_OPTIONS: -XX:+PrintCommandLineFlags
'on':
workflow_dispatch: {}
release:
types:
- published
Expand Down
8 changes: 5 additions & 3 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ addSbtPlugin("org.portable-scala" % "sbt-platform-deps" % "1.0.2")
addSbtPlugin("pl.project13.scala" % "sbt-jmh" % "0.4.7")

libraryDependencies += "org.snakeyaml" % "snakeyaml-engine" % "2.8"
libraryDependencies += "dev.zio" %% "zio" % "2.1.9"
libraryDependencies += "dev.zio" %% "zio-json" % "0.7.3"
libraryDependencies += "dev.zio" %% "zio-json-yaml" % "0.7.3"
libraryDependencies += "dev.zio" %% "zio" % "2.1.13"
libraryDependencies += "dev.zio" %% "zio-json" % "0.7.3+19-9339fbba-SNAPSHOT"
libraryDependencies += "dev.zio" %% "zio-json-yaml" % "0.7.3+19-9339fbba-SNAPSHOT"

resolvers ++= Resolver.sonatypeOssRepos("snapshots")
6 changes: 4 additions & 2 deletions zio-sbt-ci/build.sbt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
libraryDependencies += "dev.zio" %% "zio" % "2.1.13"
libraryDependencies += "dev.zio" %% "zio-json" % "0.7.3"
libraryDependencies += "dev.zio" %% "zio-json-yaml" % "0.7.3"
libraryDependencies += "dev.zio" %% "zio-json" % "0.7.3+19-9339fbba-SNAPSHOT"
libraryDependencies += "dev.zio" %% "zio-json-yaml" % "0.7.3+19-9339fbba-SNAPSHOT"

resolvers ++= Resolver.sonatypeOssRepos("snapshots")
104 changes: 46 additions & 58 deletions zio-sbt-ci/src/main/scala/zio/sbt/ZioSbtCiPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ object ZioSbtCiPlugin extends AutoPlugin {
Seq(
Job(
name = "ci",
needs = Some(pullRequestApprovalJobs),
needs = pullRequestApprovalJobs,
steps = Seq(
SingleStep(
name = "Report Successful CI",
Expand Down Expand Up @@ -372,52 +372,44 @@ object ZioSbtCiPlugin extends AutoPlugin {
name = "Generate Token",
id = Some("generate-token"),
uses = Some(ActionRef(V("zio/generate-github-app-token"))),
`with` = Some(
ListMap(
"app_id" -> "${{ secrets.APP_ID }}".toJsonAST.right.get,
"app_private_key" -> "${{ secrets.APP_PRIVATE_KEY }}".toJsonAST.right.get
)
`with` = ListMap(
"app_id" -> "${{ secrets.APP_ID }}".toJsonAST.right.get,
"app_private_key" -> "${{ secrets.APP_PRIVATE_KEY }}".toJsonAST.right.get
)
),
Step.SingleStep(
name = "Create Pull Request",
id = Some("cpr"),
uses = Some(ActionRef(V("peter-evans/create-pull-request"))),
`with` = Some(
ListMap(
"title" -> "Update README.md".toJsonAST.right.get,
"commit-message" -> "Update README.md".toJsonAST.right.get,
"branch" -> "zio-sbt-website/update-readme".toJsonAST.right.get,
"delete-branch" -> true.toJsonAST.right.get,
"body" ->
"""|Autogenerated changes after running the `sbt docs/generateReadme` command of the [zio-sbt-website](https://zio.dev/zio-sbt) plugin.
|
|I will automatically update the README.md file whenever there is new change for README.md, e.g.
| - After each release, I will update the version in the installation section.
| - After any changes to the "docs/index.md" file, I will update the README.md file accordingly.""".stripMargin.toJsonAST.right.get,
"token" -> "${{ steps.generate-token.outputs.token }}".toJsonAST.right.get
)
`with` = ListMap(
"title" -> "Update README.md".toJsonAST.right.get,
"commit-message" -> "Update README.md".toJsonAST.right.get,
"branch" -> "zio-sbt-website/update-readme".toJsonAST.right.get,
"delete-branch" -> true.toJsonAST.right.get,
"body" ->
"""|Autogenerated changes after running the `sbt docs/generateReadme` command of the [zio-sbt-website](https://zio.dev/zio-sbt) plugin.
|
|I will automatically update the README.md file whenever there is new change for README.md, e.g.
| - After each release, I will update the version in the installation section.
| - After any changes to the "docs/index.md" file, I will update the README.md file accordingly.""".stripMargin.toJsonAST.right.get,
"token" -> "${{ steps.generate-token.outputs.token }}".toJsonAST.right.get
)
),
Step.SingleStep(
name = "Approve PR",
`if` = Some(Condition.Expression("steps.cpr.outputs.pull-request-number")),
env = Some(
ListMap(
"GITHUB_TOKEN" -> "${{ secrets.GITHUB_TOKEN }}",
"PR_URL" -> "${{ steps.cpr.outputs.pull-request-url }}"
)
env = ListMap(
"GITHUB_TOKEN" -> "${{ secrets.GITHUB_TOKEN }}",
"PR_URL" -> "${{ steps.cpr.outputs.pull-request-url }}"
),
run = Some("gh pr review \"$PR_URL\" --approve")
),
Step.SingleStep(
name = "Enable Auto-Merge",
`if` = Some(Condition.Expression("steps.cpr.outputs.pull-request-number")),
env = Some(
ListMap(
"GITHUB_TOKEN" -> "${{ secrets.GITHUB_TOKEN }}",
"PR_URL" -> "${{ steps.cpr.outputs.pull-request-url }}"
)
env = ListMap(
"GITHUB_TOKEN" -> "${{ secrets.GITHUB_TOKEN }}",
"PR_URL" -> "${{ steps.cpr.outputs.pull-request-url }}"
),
run = Some("gh pr merge --auto --squash \"$PR_URL\" || gh pr merge --squash \"$PR_URL\"")
)
Expand All @@ -437,7 +429,7 @@ object ZioSbtCiPlugin extends AutoPlugin {
Seq(
Job(
name = "Release",
needs = Some(jobs),
needs = jobs,
`if` = Some(Condition.Expression("github.event_name != 'pull_request'")),
steps = (if (swapSizeGB > 0) Seq(setSwapSpace) else Seq.empty) ++
Seq(
Expand All @@ -462,7 +454,7 @@ object ZioSbtCiPlugin extends AutoPlugin {
Seq(
Job(
name = "Release Docs",
needs = Some(Seq("release")),
needs = Seq("release"),
`if` = Some(
Condition.Expression("github.event_name == 'release'") &&
Condition.Expression("github.event.action == 'published'") || Condition.Expression(
Expand All @@ -481,7 +473,7 @@ object ZioSbtCiPlugin extends AutoPlugin {
),
Job(
name = "Notify Docs Release",
needs = Some(Seq("release-docs")),
needs = Seq("release-docs"),
`if` = Some(
Condition.Expression("github.event_name == 'release'") &&
Condition.Expression("github.event.action == 'published'")
Expand Down Expand Up @@ -541,12 +533,12 @@ object ZioSbtCiPlugin extends AutoPlugin {
val workflow =
Workflow(
name = workflowName,
env = Some(jvmMap ++ nodeMap),
env = jvmMap ++ nodeMap,
on = Some(
Triggers(
release = Some(Trigger.Release(Seq(Trigger.ReleaseType.Published))),
push = Some(Trigger.Push(branches = Some(enabledBranches.map(Branch.Named)).filter(_.nonEmpty))),
pullRequest = Some(Trigger.PullRequest(branchesIgnore = Some(Seq(Branch.Named("gh-pages")))))
push = Some(Trigger.Push(branches = enabledBranches.map(Branch.Named))).filter(_.branches.nonEmpty),
pullRequest = Some(Trigger.PullRequest(branchesIgnore = Seq(Branch.Named("gh-pages"))))
)
),
jobs = ListMap(
Expand All @@ -555,7 +547,9 @@ object ZioSbtCiPlugin extends AutoPlugin {
)
)

val yaml: String = workflow.toJsonAST.flatMap(_.toYaml(yamlOptions).left.map(_.getMessage())) match {
val yaml: String = zio.json.ast.Json.decoder
.decodeJson(workflow.toJson)
.flatMap(_.toYaml(yamlOptions).left.map(_.getMessage())) match {
case Right(value) => value
case Left(error) => sys.error(s"Error generating workflow yaml: $error")
}
Expand Down Expand Up @@ -652,7 +646,7 @@ object ZioSbtCiPlugin extends AutoPlugin {
Step.SingleStep(
name = "Set Swap Space",
uses = Some(ActionRef(V("pierotofy/set-swap-space"))),
`with` = Some(ListMap("swap-size-gb" -> swapSizeGB.toString.toJsonAST.right.get))
`with` = ListMap("swap-size-gb" -> swapSizeGB.toString.toJsonAST.right.get)
)
}

Expand All @@ -661,7 +655,7 @@ object ZioSbtCiPlugin extends AutoPlugin {
Step.SingleStep(
name = "Git Checkout",
uses = Some(ActionRef(V("actions/checkout"))),
`with` = Some(ListMap("fetch-depth" -> "0".toJsonAST.right.get))
`with` = ListMap("fetch-depth" -> "0".toJsonAST.right.get)
)
}

Expand All @@ -673,12 +667,10 @@ object ZioSbtCiPlugin extends AutoPlugin {
def SetupJava(version: String = "17"): Step.SingleStep = Step.SingleStep(
name = "Setup Scala",
uses = Some(ActionRef(V("actions/setup-java"))),
`with` = Some(
ListMap(
"distribution" -> "corretto".toJsonAST.right.get,
"java-version" -> version.toJsonAST.right.get,
"check-latest" -> true.toJsonAST.right.get
)
`with` = ListMap(
"distribution" -> "corretto".toJsonAST.right.get,
"java-version" -> version.toJsonAST.right.get,
"check-latest" -> true.toJsonAST.right.get
)
)

Expand Down Expand Up @@ -723,25 +715,21 @@ object ZioSbtCiPlugin extends AutoPlugin {
Step.SingleStep(
name = "Release",
run = Some(prefixJobs + "sbt ci-release"),
env = Some(
ListMap(
"PGP_PASSPHRASE" -> "${{ secrets.PGP_PASSPHRASE }}",
"PGP_SECRET" -> "${{ secrets.PGP_SECRET }}",
"SONATYPE_PASSWORD" -> "${{ secrets.SONATYPE_PASSWORD }}",
"SONATYPE_USERNAME" -> "${{ secrets.SONATYPE_USERNAME }}"
)
env = ListMap(
"PGP_PASSPHRASE" -> "${{ secrets.PGP_PASSPHRASE }}",
"PGP_SECRET" -> "${{ secrets.PGP_SECRET }}",
"SONATYPE_PASSWORD" -> "${{ secrets.SONATYPE_PASSWORD }}",
"SONATYPE_USERNAME" -> "${{ secrets.SONATYPE_USERNAME }}"
)
)
}

val SetupNodeJs: Step.SingleStep = Step.SingleStep(
name = "Setup NodeJs",
uses = Some(ActionRef(V("actions/setup-node"))),
`with` = Some(
ListMap(
"node-version" -> "16.x".toJsonAST.right.get,
"registry-url" -> "https://registry.npmjs.org".toJsonAST.right.get
)
`with` = ListMap(
"node-version" -> "16.x".toJsonAST.right.get,
"registry-url" -> "https://registry.npmjs.org".toJsonAST.right.get
)
)

Expand All @@ -754,7 +742,7 @@ object ZioSbtCiPlugin extends AutoPlugin {
Step.SingleStep(
name = "Publish Docs to NPM Registry",
run = Some(prefixJobs + s"sbt docs/${docsVersioning.npmCommand}"),
env = Some(ListMap("NODE_AUTH_TOKEN" -> "${{ secrets.NPM_TOKEN }}"))
env = ListMap("NODE_AUTH_TOKEN" -> "${{ secrets.NPM_TOKEN }}")
)
}

Expand Down
8 changes: 5 additions & 3 deletions zio-sbt-ecosystem/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ addSbtPlugin("pl.project13.scala" % "sbt-jcstress" % "0.2.0")
// Binary Compatibility Plugin
libraryDependencies += "dev.zio" %% "zio" % "2.1.13"

libraryDependencies += "dev.zio" %% "zio" % "2.1.9"
libraryDependencies += "dev.zio" %% "zio-json" % "0.7.3"
libraryDependencies += "dev.zio" %% "zio-json-yaml" % "0.7.3"
libraryDependencies += "dev.zio" %% "zio" % "2.1.13"
libraryDependencies += "dev.zio" %% "zio-json" % "0.7.3+19-9339fbba-SNAPSHOT"
libraryDependencies += "dev.zio" %% "zio-json-yaml" % "0.7.3+19-9339fbba-SNAPSHOT"

resolvers ++= Resolver.sonatypeOssRepos("snapshots")
6 changes: 4 additions & 2 deletions zio-sbt-githubactions/build.sbt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
libraryDependencies += "dev.zio" %% "zio" % "2.1.13"
libraryDependencies += "dev.zio" %% "zio-json" % "0.7.3"
libraryDependencies += "dev.zio" %% "zio-json-yaml" % "0.7.3"
libraryDependencies += "dev.zio" %% "zio-json" % "0.7.3+19-9339fbba-SNAPSHOT"
libraryDependencies += "dev.zio" %% "zio-json-yaml" % "0.7.3+19-9339fbba-SNAPSHOT"

resolvers ++= Resolver.sonatypeOssRepos("snapshots")
Original file line number Diff line number Diff line change
Expand Up @@ -29,39 +29,33 @@ object ScalaWorkflow {
SingleStep(
name = "Checkout current branch",
uses = Some(ActionRef("actions/checkout@v2")),
`with` = Some(
ListMap(
"fetch-depth" -> fetchDepth.toJsonAST.right.get
)
`with` = ListMap(
"fetch-depth" -> fetchDepth.toJsonAST.right.get
)
)

def setupScala(javaVersion: Option[JavaVersion] = None): Step =
SingleStep(
name = "Setup Java and Scala",
uses = Some(ActionRef("olafurpg/setup-scala@v11")),
`with` = Some(
ListMap(
"java-version" -> (javaVersion match {
case None => "${{ matrix.java }}"
case Some(version) => version.asString
}).toJsonAST.right.get
)
`with` = ListMap(
"java-version" -> (javaVersion match {
case None => "${{ matrix.java }}"
case Some(version) => version.asString
}).toJsonAST.right.get
)
)

def setupNode(javaVersion: Option[JavaVersion] = None): Step =
SingleStep(
name = "Setup NodeJS",
uses = Some(ActionRef("actions/setup-node@v3")),
`with` = Some(
ListMap(
"node-version" -> (javaVersion match {
case None => "16.x"
case Some(version) => version.asString
}).toJsonAST.right.get,
"registry-url" -> "https://registry.npmjs.org".toJsonAST.right.get
)
`with` = ListMap(
"node-version" -> (javaVersion match {
case None => "16.x"
case Some(version) => version.asString
}).toJsonAST.right.get,
"registry-url" -> "https://registry.npmjs.org".toJsonAST.right.get
)
)

Expand All @@ -81,16 +75,14 @@ object ScalaWorkflow {
SingleStep(
name = "Cache SBT",
uses = Some(ActionRef("actions/cache@v2")),
`with` = Some(
ListMap(
"path" -> Seq(
"~/.ivy2/cache",
"~/.sbt",
"~/.coursier/cache/v1",
"~/.cache/coursier/v1"
).mkString("\n").toJsonAST.right.get,
"key" -> s"$osS-sbt-$scalaS-$${{ hashFiles('**/*.sbt') }}-$${{ hashFiles('**/build.properties') }}".toJsonAST.right.get
)
`with` = ListMap(
"path" -> Seq(
"~/.ivy2/cache",
"~/.sbt",
"~/.coursier/cache/v1",
"~/.cache/coursier/v1"
).mkString("\n").toJsonAST.right.get,
"key" -> s"$osS-sbt-$scalaS-$${{ hashFiles('**/*.sbt') }}-$${{ hashFiles('**/build.properties') }}".toJsonAST.right.get
)
)
}
Expand All @@ -113,7 +105,7 @@ object ScalaWorkflow {
run = Some(
s"sbt -J-XX:+UseG1GC -J-Xmx${heapGb}g -J-Xms${heapGb}g -J-Xss${stackMb}m ${parameters.mkString(" ")}"
),
env = Some(env).filter(_.nonEmpty)
env = env
)

def storeTargets(
Expand All @@ -138,11 +130,9 @@ object ScalaWorkflow {
SingleStep(
s"Upload $id targets",
uses = Some(ActionRef("actions/upload-artifact@v2")),
`with` = Some(
ListMap(
"name" -> s"target-$id-$osS-$scalaS-$javaS".toJsonAST.right.get,
"path" -> "targets.tar".toJsonAST.right.get
)
`with` = ListMap(
"name" -> s"target-$id-$osS-$scalaS-$javaS".toJsonAST.right.get,
"path" -> "targets.tar".toJsonAST.right.get
)
)
)
Expand All @@ -164,10 +154,8 @@ object ScalaWorkflow {
SingleStep(
s"Download stored $id targets",
uses = Some(ActionRef("actions/download-artifact@v2")),
`with` = Some(
ListMap(
"name" -> s"target-$id-$osS-$scalaS-$javaS".toJsonAST.right.get
)
`with` = ListMap(
"name" -> s"target-$id-$osS-$scalaS-$javaS".toJsonAST.right.get
)
),
SingleStep(
Expand All @@ -194,17 +182,15 @@ object ScalaWorkflow {
SingleStep(
"Load PGP secret",
run = Some(".github/import-key.sh"),
env = Some(ListMap("PGP_SECRET" -> "${{ secrets.PGP_SECRET }}"))
env = ListMap("PGP_SECRET" -> "${{ secrets.PGP_SECRET }}")
)

def turnstyle(): Step =
SingleStep(
"Turnstyle",
uses = Some(ActionRef("softprops/turnstyle@v1")),
env = Some(
ListMap(
"GITHUB_TOKEN" -> "${{ secrets.ADMIN_GITHUB_TOKEN }}"
)
env = ListMap(
"GITHUB_TOKEN" -> "${{ secrets.ADMIN_GITHUB_TOKEN }}"
)
)

Expand Down
Loading

0 comments on commit 28c49c4

Please sign in to comment.