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 Jan 7, 2025
1 parent ee9272b commit 14e9524
Show file tree
Hide file tree
Showing 10 changed files with 129 additions and 135 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
4 changes: 2 additions & 2 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ addSbtPlugin("pl.project13.scala" % "sbt-jmh" % "0.4.7")

libraryDependencies += "org.snakeyaml" % "snakeyaml-engine" % "2.8"
libraryDependencies += "dev.zio" %% "zio" % "2.1.14"
libraryDependencies += "dev.zio" %% "zio-json" % "0.7.3"
libraryDependencies += "dev.zio" %% "zio-json-yaml" % "0.7.3"
libraryDependencies += "dev.zio" %% "zio-json" % "0.7.4"
libraryDependencies += "dev.zio" %% "zio-json-yaml" % "0.7.4"
4 changes: 2 additions & 2 deletions zio-sbt-ci/build.sbt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
libraryDependencies += "dev.zio" %% "zio" % "2.1.14"
libraryDependencies += "dev.zio" %% "zio-json" % "0.7.3"
libraryDependencies += "dev.zio" %% "zio-json-yaml" % "0.7.3"
libraryDependencies += "dev.zio" %% "zio-json" % "0.7.4"
libraryDependencies += "dev.zio" %% "zio-json-yaml" % "0.7.4"
117 changes: 55 additions & 62 deletions zio-sbt-ci/src/main/scala/zio/sbt/ZioSbtCiPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,15 @@ object ZioSbtCiPlugin extends AutoPlugin {
Job(
name = "Lint",
steps = (if (swapSizeGB > 0) Seq(setSwapSpace) else Seq.empty) ++
Seq(checkout, SetupLibuv, SetupJava(javaVersion), SetupSBT, CacheDependencies) ++
checkGithubWorkflow.flatMap(
_.flatten
) ++ Seq(lint)
Seq(
checkout,
SetupLibuv,
SetupJava(javaVersion),
SetupSBT,
CacheDependencies,
Step.StepSequence(checkGithubWorkflow),
lint
)
)
)
}
Expand Down Expand Up @@ -329,7 +334,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 +377,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 +434,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 +459,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 @@ -482,7 +479,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 @@ -542,12 +539,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 @@ -556,7 +553,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 @@ -653,7 +652,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 @@ -662,7 +661,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 @@ -674,12 +673,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 @@ -724,25 +721,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 @@ -755,7 +748,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
4 changes: 2 additions & 2 deletions zio-sbt-ecosystem/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@ addSbtPlugin("pl.project13.scala" % "sbt-jcstress" % "0.2.0")
addSbtPlugin("com.typesafe" % "sbt-mima-plugin" % "1.1.4")

libraryDependencies += "dev.zio" %% "zio" % "2.1.14"
libraryDependencies += "dev.zio" %% "zio-json" % "0.7.3"
libraryDependencies += "dev.zio" %% "zio-json-yaml" % "0.7.3"
libraryDependencies += "dev.zio" %% "zio-json" % "0.7.4"
libraryDependencies += "dev.zio" %% "zio-json-yaml" % "0.7.4"
4 changes: 2 additions & 2 deletions zio-sbt-githubactions/build.sbt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
libraryDependencies += "dev.zio" %% "zio" % "2.1.14"
libraryDependencies += "dev.zio" %% "zio-json" % "0.7.3"
libraryDependencies += "dev.zio" %% "zio-json-yaml" % "0.7.3"
libraryDependencies += "dev.zio" %% "zio-json" % "0.7.4"
libraryDependencies += "dev.zio" %% "zio-json-yaml" % "0.7.4"
Loading

0 comments on commit 14e9524

Please sign in to comment.