Skip to content

Commit

Permalink
add githubactionsnative model, restore old models
Browse files Browse the repository at this point in the history
  • Loading branch information
ThijsBroersen committed Oct 18, 2024
1 parent b2a7d1a commit ba39433
Show file tree
Hide file tree
Showing 7 changed files with 900 additions and 243 deletions.
42 changes: 21 additions & 21 deletions zio-sbt-ci/src/main/scala/zio/sbt/ZioSbtCiPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import sbt.{Def, io => _, _}

import zio.json._
import zio.json.yaml._
import zio.sbt.githubactions.Step.SingleStep
import zio.sbt.githubactions.{Job, Step, _}
import zio.sbt.githubactionsnative.Step.SingleStep
import zio.sbt.githubactionsnative.{Job, Step, _}

object ZioSbtCiPlugin extends AutoPlugin {
override def requires = plugins.CorePlugin
Expand Down Expand Up @@ -368,8 +368,8 @@ object ZioSbtCiPlugin extends AutoPlugin {
uses = Some(ActionRef(V("zio/generate-github-app-token"))),
`with` = Some(
Map(
"app_id" -> "${{ secrets.APP_ID }}",
"app_private_key" -> "${{ secrets.APP_PRIVATE_KEY }}"
"app_id" -> "${{ secrets.APP_ID }}".toJsonAST.right.get,
"app_private_key" -> "${{ secrets.APP_PRIVATE_KEY }}".toJsonAST.right.get
)
)
),
Expand All @@ -379,17 +379,17 @@ object ZioSbtCiPlugin extends AutoPlugin {
uses = Some(ActionRef(V("peter-evans/create-pull-request"))),
`with` = Some(
Map(
"title" -> "Update README.md",
"commit-message" -> "Update README.md",
"branch" -> "zio-sbt-website/update-readme",
"delete-branch" -> "true",
"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,
"token" -> "${{ steps.generate-token.outputs.token }}"
| - 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
)
)
),
Expand Down Expand Up @@ -534,12 +534,12 @@ object ZioSbtCiPlugin extends AutoPlugin {
val workflow =
Workflow(
name = workflowName,
env = jvmMap ++ nodeMap,
env = Some(jvmMap ++ nodeMap),
on = Some(
Triggers(
release = Some(Triggers.Release(Seq(Triggers.ReleaseType.Published))),
push = Some(Triggers.Push(branches = Some(enabledBranches.map(Branch.Named)).filter(_.nonEmpty))),
pullRequest = Some(Triggers.PullRequest(branchesIgnore = Some(Seq(Branch.Named("gh-pages")))))
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")))))
)
),
jobs = ListMap.empty[
Expand Down Expand Up @@ -645,7 +645,7 @@ object ZioSbtCiPlugin extends AutoPlugin {
Step.SingleStep(
name = "Set Swap Space",
uses = Some(ActionRef(V("pierotofy/set-swap-space"))),
`with` = Some(Map("swap-size-gb" -> swapSizeGB.toString))
`with` = Some(Map("swap-size-gb" -> swapSizeGB.toString.toJsonAST.right.get))
)
}

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

Expand All @@ -668,9 +668,9 @@ object ZioSbtCiPlugin extends AutoPlugin {
uses = Some(ActionRef(V("actions/setup-java"))),
`with` = Some(
Map(
"distribution" -> "corretto",
"java-version" -> version,
"check-latest" -> "true"
"distribution" -> "corretto".toJsonAST.right.get,
"java-version" -> version.toJsonAST.right.get,
"check-latest" -> "true".toJsonAST.right.get
)
)
)
Expand Down Expand Up @@ -727,8 +727,8 @@ object ZioSbtCiPlugin extends AutoPlugin {
uses = Some(ActionRef(V("actions/setup-node"))),
`with` = Some(
Map(
"node-version" -> "16.x",
"registry-url" -> "https://registry.npmjs.org"
"node-version" -> "16.x".toJsonAST.right.get,
"registry-url" -> "https://registry.npmjs.org".toJsonAST.right.get
)
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,50 +17,46 @@
package zio.sbt.githubactions

import zio.json._

import zio.sbt.githubactions.ScalaWorkflow.JavaVersion.JDK11

// The original code of the githubactions package was originally copied from the zio-aws-codegen project:
// https://github.com/zio/zio-aws/tree/master/zio-aws-codegen/src/main/scala/zio/aws/codegen/githubactions
@deprecated("Use zio.sbt.githubactionsnative.ScalaWorkflow instead", "0.4.x")
object ScalaWorkflow {
import Step._

def checkoutCurrentBranch(fetchDepth: Int = 0): Step =
SingleStep(
name = "Checkout current branch",
uses = Some(ActionRef("actions/checkout@v2")),
`with` = Some(
Map(
"fetch-depth" -> fetchDepth.toJson
)
parameters = Map(
"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(
Map(
"java-version" -> (javaVersion match {
case None => "${{ matrix.java }}"
case Some(version) => version.asString
})
)
parameters = Map(
"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(
Map(
"node-version" -> (javaVersion match {
case None => "16.x"
case Some(version) => version.asString
}),
"registry-url" -> "https://registry.npmjs.org"
)
parameters = Map(
"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 @@ -80,16 +76,14 @@ object ScalaWorkflow {
SingleStep(
name = "Cache SBT",
uses = Some(ActionRef("actions/cache@v2")),
`with` = Some(
Map(
"path" -> Seq(
"~/.ivy2/cache",
"~/.sbt",
"~/.coursier/cache/v1",
"~/.cache/coursier/v1"
).mkString("\n"),
"key" -> s"$osS-sbt-$scalaS-$${{ hashFiles('**/*.sbt') }}-$${{ hashFiles('**/build.properties') }}"
)
parameters = Map(
"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 @@ -112,7 +106,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 @@ -137,11 +131,9 @@ object ScalaWorkflow {
SingleStep(
s"Upload $id targets",
uses = Some(ActionRef("actions/upload-artifact@v2")),
`with` = Some(
Map(
"name" -> s"target-$id-$osS-$scalaS-$javaS",
"path" -> "targets.tar"
)
parameters = Map(
"name" -> s"target-$id-$osS-$scalaS-$javaS".toJsonAST.right.get,
"path" -> "targets.tar".toJsonAST.right.get
)
)
)
Expand All @@ -163,10 +155,8 @@ object ScalaWorkflow {
SingleStep(
s"Download stored $id targets",
uses = Some(ActionRef("actions/download-artifact@v2")),
`with` = Some(
Map(
"name" -> s"target-$id-$osS-$scalaS-$javaS"
)
parameters = Map(
"name" -> s"target-$id-$osS-$scalaS-$javaS".toJsonAST.right.get
)
),
SingleStep(
Expand All @@ -193,17 +183,15 @@ object ScalaWorkflow {
SingleStep(
"Load PGP secret",
run = Some(".github/import-key.sh"),
env = Some(Map("PGP_SECRET" -> "${{ secrets.PGP_SECRET }}"))
env = Map("PGP_SECRET" -> "${{ secrets.PGP_SECRET }}")
)

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

Expand Down Expand Up @@ -244,12 +232,12 @@ object ScalaWorkflow {
val JDK21: JavaVersion = CorrettoJDK("21")
}

implicit class JobOps(job: JobValue) {
implicit class JobOps(job: Job) {
def matrix(
scalaVersions: Seq[ScalaVersion],
operatingSystems: Seq[OS] = Seq(OS.UbuntuLatest),
javaVersions: Seq[JavaVersion] = Seq(JDK11)
): JobValue =
): Job =
job.copy(
strategy = Some(
Strategy(
Expand Down
Loading

0 comments on commit ba39433

Please sign in to comment.