From 2ef6dd0d22f140d4add784bbb98f3db5e6330141 Mon Sep 17 00:00:00 2001 From: Arman Bilge Date: Wed, 8 Nov 2023 02:08:36 +0000 Subject: [PATCH] Expose `tlSiteJavaVersion`, auto-config to JDK 11+ --- .github/workflows/ci.yml | 2 +- .mergify.yml | 2 +- docs/customization.md | 1 + .../typelevel/sbt/TypelevelSitePlugin.scala | 34 ++++++++++++++++--- 4 files changed, 33 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 72624341..ce18b164 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -523,7 +523,7 @@ jobs: strategy: matrix: os: [ubuntu-latest] - java: [temurin@8] + java: [temurin@11] runs-on: ${{ matrix.os }} steps: - name: Ignore line ending differences in git diff --git a/.mergify.yml b/.mergify.yml index 258627d1..db3438bc 100644 --- a/.mergify.yml +++ b/.mergify.yml @@ -22,7 +22,7 @@ pull_request_rules: - status-success=Build and Test (macos-latest, 2.12, temurin@8, sbt-typelevelJVM) - status-success=Build and Test (windows-latest, 2.12, temurin@8, sbt-typelevelJVM) - status-success=Validate Steward Config (ubuntu-latest, temurin@11) - - status-success=Generate Site (ubuntu-latest, temurin@8) + - status-success=Generate Site (ubuntu-latest, temurin@11) - '#approved-reviews-by>=1' actions: merge: {} diff --git a/docs/customization.md b/docs/customization.md index 81df02f7..8f157d43 100644 --- a/docs/customization.md +++ b/docs/customization.md @@ -113,6 +113,7 @@ Using this plugin the following 2 settings have new default values: - `tlSiteApiModule` (setting): The module that publishes API docs (default: `None`). - `tlSiteApiPackage` (setting): The top-level package for your API docs (e.g. org.typlevel.sbt). - `tlSiteKeepFiles` (setting): Whether to keep existing files when deploying site (default: `true`). +- `tlSiteJavaVersion` (setting): The Java version to use for the site job, must be >= 11 (default: first compatible choice from `githubWorkflowJavaVersions`, otherwise Temurin 11). - `tlSiteGenerate` (setting): A sequence of workflow steps which generates the site (default: `[Sbt(List("tlSite"))]`). - `tlSitePublish` (setting): A sequence of workflow steps which publishes the site (default: `peaceiris/actions-gh-pages`). - `tlSitePublishBranch` (setting): The branch to publish the site from on every push. Set this to `None` if you only want to update the site on tag releases. (default: `main`) diff --git a/site/src/main/scala/org/typelevel/sbt/TypelevelSitePlugin.scala b/site/src/main/scala/org/typelevel/sbt/TypelevelSitePlugin.scala index 4cc51453..fe5a2dcd 100644 --- a/site/src/main/scala/org/typelevel/sbt/TypelevelSitePlugin.scala +++ b/site/src/main/scala/org/typelevel/sbt/TypelevelSitePlugin.scala @@ -31,6 +31,7 @@ import sbt.Keys._ import sbt._ import scala.annotation.nowarn +import scala.util.Try object TypelevelSitePlugin extends AutoPlugin { @@ -58,6 +59,8 @@ object TypelevelSitePlugin extends AutoPlugin { lazy val tlSiteKeepFiles = settingKey[Boolean]("Whether to keep existing files when deploying site (default: true)") + lazy val tlSiteJavaVersion = settingKey[JavaSpec]( + "The Java version to use for the site job, must be >= 11 (default: first compatible choice from `githubWorkflowJavaVersions`, otherwise Temurin 11)") lazy val tlSiteGenerate = settingKey[Seq[WorkflowStep]]( "A sequence of workflow steps which generates the site (default: [Sbt(List(\"tlSite\"))])") lazy val tlSitePublish = settingKey[Seq[WorkflowStep]]( @@ -92,6 +95,20 @@ object TypelevelSitePlugin extends AutoPlugin { tlSiteApiPackage := None, tlSiteRelatedProjects := Nil, tlSiteKeepFiles := true, + tlSiteJavaVersion := { + githubWorkflowJavaVersions + .value + .collectFirst { + case spec @ JavaSpec(_, version) + if version + .split('.') + .lift(0) + .flatMap(v => Try(v.toInt).toOption) + .exists(_ >= 11) => + spec + } + .getOrElse(JavaSpec.temurin("11")) + }, homepage := { gitHubUserRepo.value.map { case ("typelevel", repo) => url(s"https://typelevel.org/$repo") @@ -209,16 +226,25 @@ object TypelevelSitePlugin extends AutoPlugin { List.empty } }, - ThisBuild / githubWorkflowAddedJobs += + ThisBuild / githubWorkflowAddedJobs += { + + val extraJava = + if (!githubWorkflowJavaVersions.value.contains(tlSiteJavaVersion.value)) + WorkflowStep.SetupJava(List(tlSiteJavaVersion.value)) + else Nil + WorkflowJob( "site", "Generate Site", scalas = List.empty, sbtStepPreamble = List.empty, - javas = List(githubWorkflowJavaVersions.value.head), - steps = - githubWorkflowJobSetup.value.toList ++ tlSiteGenerate.value ++ tlSitePublish.value + javas = List(tlSiteJavaVersion.value), + steps = githubWorkflowJobSetup.value.toList ++ + extraJava ++ + tlSiteGenerate.value ++ + tlSitePublish.value ) + } ) private def previewTask = Def