diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6a0dcbcd..229b8368 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,53 +1,53 @@ jobs: build: env: - SCALA_VERSION: "${{ matrix.scala }}" - name: "Scala ${{ matrix.scala }}, Java ${{ matrix.java }}" + SCALA_VERSION: ${{ matrix.scala }} + name: Scala ${{ matrix.scala }}, Java ${{ matrix.java }} runs-on: ubuntu-latest steps: - - uses: "actions/checkout@v2" - - uses: "actions/setup-java@v1" - with: - java-version: "${{ matrix.java }}" - - name: Get current week - run: | - echo "::set-env name=current_week::$(( 10#$(date +%U) ))" - echo "::set-env name=last_week::$(( 10#$(date +%U) - 1 ))" - - name: Cache SBT coursier cache - uses: "actions/cache@v1" - with: - key: "coursier-${{ env.current_week }}" - path: "~/.cache/coursier" - restore-keys: "coursier-${{ env.last_week }}" - - name: Cache SBT - uses: "actions/cache@v1" - with: - key: "sbt-${{ env.current_week }}" - path: "~/.sbt" - restore-keys: "sbt-${{ env.last_week }}" - - name: Unused and undeclared dependencies - run: "sbt ++$SCALA_VERSION unusedCompileDependenciesTest undeclaredCompileDependenciesTest" - - name: Tests - run: "sbt ++$SCALA_VERSION test" - - name: Scaladocs - run: "sbt ++$SCALA_VERSION doc" - - name: MiMa - run: "sbt ++$SCALA_VERSION mimaReportBinaryIssues" - - name: Scalafmt - run: "sbt ++$SCALA_VERSION scalafmtCheckAll" - - if: "startsWith(matrix.scala, '2.12')" - name: Test docs - run: "sbt ++$SCALA_VERSION docs/makeSite" + - uses: actions/checkout@v2 + - uses: actions/setup-java@v1 + with: + java-version: ${{ matrix.java }} + - name: Get current week + run: | + echo \"::set-env name=current_week::$(( 10#$(date +%U) ))\" + echo \"::set-env name=last_week::$(( 10#$(date +%U) - 1 ))\" + - name: Cache SBT coursier cache + uses: actions/cache@v1 + with: + key: coursier-${{ env.current_week }} + path: ~/.cache/coursier + restore-keys: coursier-${{ env.last_week }} + - name: Cache SBT + uses: actions/cache@v1 + with: + key: sbt-${{ env.current_week }} + path: ~/.sbt + restore-keys: sbt-${{ env.last_week }} + - name: Unused and undeclared dependencies + run: sbt ++$SCALA_VERSION unusedCompileDependenciesTest undeclaredCompileDependenciesTest + - name: Tests + run: sbt ++$SCALA_VERSION test + - name: Scaladocs + run: sbt ++$SCALA_VERSION doc + - name: MiMa + run: sbt ++$SCALA_VERSION mimaReportBinaryIssues + - name: Scalafmt + run: sbt ++$SCALA_VERSION scalafmtCheckAll + - if: startsWith(matrix.scala, '2.12') + name: Test docs + run: sbt ++$SCALA_VERSION docs/makeSite strategy: fail-fast: false matrix: java: - - '11' - - '14' + - '11' + - '14' scala: - - '2.12.11' - - '2.13.1' + - 2.12.11 + - 2.13.1 name: CI -on: - - push - - pull_request +'on': +- push +- pull_request diff --git a/.github/workflows/dhall.yml b/.github/workflows/dhall.yml index 8c83e597..d5e024e2 100644 --- a/.github/workflows/dhall.yml +++ b/.github/workflows/dhall.yml @@ -2,24 +2,15 @@ jobs: check: runs-on: ubuntu-latest steps: - - uses: "actions/checkout@v2" - - name: Setup Dhall - run: | - cd $(mktemp -d) - curl -L https://github.com/dhall-lang/dhall-haskell/releases/download/1.31.1/dhall-1.31.1-x86_64-linux.tar.bz2 | tar xj - curl -L https://github.com/dhall-lang/dhall-haskell/releases/download/1.31.1/dhall-json-1.6.3-x86_64-linux.tar.bz2 | tar xj - mkdir -p $HOME/bin - mv bin/* $HOME/bin/ - echo "::add-path::$HOME/bin" - - name: Check Dhall formatting - run: | - [[ $(find -name '*.dhall' -exec sh -c 'dhall --ascii format --check < {}' \; |& wc -c) -eq 0 ]] - - name: Check generated YAML files - run: | - cd dhall - ./generateYaml.sh - [[ $(git status --porcelain | wc -l) -eq 0 ]] + - uses: actions/checkout@v2 + - uses: actions/setup-java@v1 + with: + java-version: '11' + - name: Check generated YAML files + run: | + sbt convertDhall + [[ $(git status --porcelain | wc -l) -eq 0 ]] name: Check Dhall configs -on: - - push - - pull_request +'on': +- push +- pull_request diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index eea53b62..470141b9 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -2,49 +2,50 @@ jobs: publish: runs-on: ubuntu-latest steps: - - uses: "actions/checkout@v2" - - name: Unshallow - run: git fetch --unshallow - - uses: "actions/setup-java@v1" - with: - java-version: '11' - - uses: "olafurpg/setup-gpg@v2" - - name: Get current week - run: | - echo "::set-env name=current_week::$(( 10#$(date +%U) ))" - echo "::set-env name=last_week::$(( 10#$(date +%U) - 1 ))" - - name: Cache SBT coursier cache - uses: "actions/cache@v1" - with: - key: "coursier-${{ env.current_week }}" - path: "~/.cache/coursier" - restore-keys: "coursier-${{ env.last_week }}" - - name: Cache SBT - uses: "actions/cache@v1" - with: - key: "sbt-${{ env.current_week }}" - path: "~/.sbt" - restore-keys: "sbt-${{ env.last_week }}" - - env: - PGP_PASSPHRASE: "${{ secrets.PGP_PASSPHRASE }}" - PGP_SECRET: "${{ secrets.PGP_SECRET }}" - SBT_GHPAGES_COMMIT_MESSAGE: "Updated site: sha=${{ github.sha }} build=${{ github.run_id }}" - SONATYPE_PASSWORD: "${{ secrets.SONATYPE_PASSWORD }}" - SONATYPE_USERNAME: "${{ secrets.SONATYPE_USERNAME }}" - SSH_PRIVATE_KEY: "${{ secrets.SSH_PRIVATE_KEY }}" - name: Release - run: | - echo "$PGP_SECRET" | base64 --decode | gpg --import --no-tty --batch --yes - eval "$(ssh-agent -s)" - echo "$SSH_PRIVATE_KEY" | ssh-add - - git config --global user.name "GitHub Actions CI" - git config --global user.email "ghactions@invalid" - - sbt ci-release docs/makeSite docs/ghpagesPushSite + - uses: actions/checkout@v2 + - name: Unshallow + run: git fetch --unshallow + - uses: actions/setup-java@v1 + with: + java-version: '11' + - uses: olafurpg/setup-gpg@v2 + - name: Get current week + run: | + echo \"::set-env name=current_week::$(( 10#$(date +%U) ))\" + echo \"::set-env name=last_week::$(( 10#$(date +%U) - 1 ))\" + - name: Cache SBT coursier cache + uses: actions/cache@v1 + with: + key: coursier-${{ env.current_week }} + path: ~/.cache/coursier + restore-keys: coursier-${{ env.last_week }} + - name: Cache SBT + uses: actions/cache@v1 + with: + key: sbt-${{ env.current_week }} + path: ~/.sbt + restore-keys: sbt-${{ env.last_week }} + - env: + PGP_PASSPHRASE: ${{ secrets.PGP_PASSPHRASE }} + PGP_SECRET: ${{ secrets.PGP_SECRET }} + SBT_GHPAGES_COMMIT_MESSAGE: 'Updated site: sha=${{ github.sha }} build=${{ + github.run_id }}' + SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }} + SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }} + SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }} + name: Release + run: | + echo \"$PGP_SECRET\" | base64 --decode | gpg --import --no-tty --batch --yes + eval \"$(ssh-agent -s)\" + echo \"$SSH_PRIVATE_KEY\" | ssh-add - + git config --global user.name \"GitHub Actions CI\" + git config --global user.email \"ghactions@invalid\" + + sbt ci-release docs/makeSite docs/ghpagesPushSite name: Publish releases and snapshots -on: +'on': push: branches: - - master + - master tags: - - "*" + - '*' diff --git a/.mergify.yml b/.mergify.yml index fdb69542..ce634439 100644 --- a/.mergify.yml +++ b/.mergify.yml @@ -1,12 +1,12 @@ pull_request_rules: - - actions: - merge: - method: merge - conditions: - - author=scala-steward - - "body~=labels:.*semver-patch.*" - - "status-success=Scala 2.12.11, Java 11" - - "status-success=Scala 2.12.11, Java 14" - - "status-success=Scala 2.13.1, Java 11" - - "status-success=Scala 2.13.1, Java 14" - name: "automatically merge scala-steward's PRs" +- actions: + merge: + method: merge + conditions: + - author=scala-steward + - body~=labels:.*semver-patch.* + - status-success=Scala 2.12.11, Java 11 + - status-success=Scala 2.12.11, Java 14 + - status-success=Scala 2.13.1, Java 11 + - status-success=Scala 2.13.1, Java 14 + name: automatically merge scala-steward's PRs diff --git a/build.sbt b/build.sbt index 81d0d4d0..067077d2 100644 --- a/build.sbt +++ b/build.sbt @@ -3,7 +3,8 @@ lazy val `http4s-jdk-http-client` = project .disablePlugins(MimaPlugin) .settings(commonSettings, skipOnPublishSettings) .settings( - crossScalaVersions := Nil + crossScalaVersions := Nil, + Dhall.convertDhallTask ) .aggregate(core) @@ -36,9 +37,6 @@ val javaWebsocketV = "1.4.1" val kindProjectorV = "0.10.3" val betterMonadicForV = "0.3.1" -lazy val scalaVersions = - upickle.default.read[List[String]](new File("scalaVersions.json")) - // format: off val coreDeps = Seq( "org.typelevel" %% "cats-core" % catsV, @@ -65,8 +63,9 @@ val coreDeps = Seq( // General Settings lazy val commonSettings = Seq( organization := "org.http4s", - scalaVersion := scalaVersions.head, - crossScalaVersions := scalaVersions, + Dhall.scalaVersionsImpl, + scalaVersion := Dhall.scalaVersions.value.default, + crossScalaVersions := Dhall.scalaVersions.value.all, scalacOptions += "-Yrangepos", scalacOptions in (Compile, doc) ++= Seq( "-groups", diff --git a/dhall/ci.dhall b/dhall/ci.dhall index 544e4ece..b5e127f7 100644 --- a/dhall/ci.dhall +++ b/dhall/ci.dhall @@ -24,7 +24,7 @@ let steps = c.Run::{ , name = "Test docs" , run = "docs/makeSite" - , if = Some "startsWith(matrix.scala, '2.12')" + , `if` = Some "startsWith(matrix.scala, '2.12')" } ] @@ -35,7 +35,8 @@ in { name = "CI" /\ { name = c.ciJobName "\${{ matrix.scala }}" "\${{ matrix.java }}" , strategy = { fail-fast = False - , matrix = { java = c.javaVersions.all, scala = c.scalaVersions } + , matrix = + { java = c.javaVersions.all, scala = c.scalaVersions.all } } , env.SCALA_VERSION = "\${{ matrix.scala }}" } diff --git a/dhall/common.dhall b/dhall/common.dhall index 64988f1e..a423ef30 100644 --- a/dhall/common.dhall +++ b/dhall/common.dhall @@ -2,25 +2,25 @@ let SimpleObject = List { mapKey : Text, mapValue : Text } let Uses = { Type = - { name : Optional Text, uses : Text, with : Optional SimpleObject } - , default = { name = None Text, with = None SimpleObject } + { name : Optional Text, uses : Text, `with` : Optional SimpleObject } + , default = { name = None Text, `with` = None SimpleObject } } let Run = { Type = { name : Text , run : Text - , if : Optional Text + , `if` : Optional Text , env : Optional SimpleObject } - , default = { if = None Text, env = None SimpleObject } + , default = { `if` = None Text, env = None SimpleObject } } let BuildStep = < Uses : Uses.Type | Run : Run.Type > let baseJob = \(steps : List BuildStep) -> { runs-on = "ubuntu-latest", steps } -let javaVersions = let dv = "11" in { default = dv, all = [ dv, "14" ] } +let javaVersions = ./javaVersions.dhall let scalaVersions = ./scalaVersions.dhall @@ -39,7 +39,7 @@ let steps = -> BuildStep.Uses Uses::{ , uses = "actions/setup-java@v1" - , with = Some (toMap { java-version = version }) + , `with` = Some (toMap { java-version = version }) } , cache = let cacheConfig = @@ -48,7 +48,7 @@ let steps = Uses::{ , name = Some config.name , uses = "actions/cache@v1" - , with = Some + , `with` = Some ( toMap { path = config.path , key = diff --git a/dhall/dhall.dhall b/dhall/dhall.dhall index 3a684ca3..55661228 100644 --- a/dhall/dhall.dhall +++ b/dhall/dhall.dhall @@ -1,44 +1,14 @@ let c = ./common.dhall -let versions = { dhall = "1.31.1", dhallToYaml = "1.6.3" } - -let dhallDownload = - \(file : Text) - -> let baseUrl = - "https://github.com/dhall-lang/dhall-haskell/releases/download" - - in "curl -L ${baseUrl}/${versions.dhall}/${file}-x86_64-linux.tar.bz2 | tar xj" - let steps = [ c.steps.checkout - , c.BuildStep.Run - c.Run::{ - , name = "Setup Dhall" - , run = - '' - cd $(mktemp -d) - ${dhallDownload "dhall-${versions.dhall}"} - ${dhallDownload "dhall-json-${versions.dhallToYaml}"} - mkdir -p $HOME/bin - mv bin/* $HOME/bin/ - echo "::add-path::$HOME/bin" - '' - } - , c.BuildStep.Run - c.Run::{ - , name = "Check Dhall formatting" - , run = - '' - [[ $(find -name '*.dhall' -exec sh -c 'dhall --ascii format --check < {}' \; |& wc -c) -eq 0 ]] - '' - } + , c.steps.java c.javaVersions.default , c.BuildStep.Run c.Run::{ , name = "Check generated YAML files" , run = '' - cd dhall - ./generateYaml.sh + sbt convertDhall [[ $(git status --porcelain | wc -l) -eq 0 ]] '' } diff --git a/dhall/dhallFormat.sh b/dhall/dhallFormat.sh deleted file mode 100755 index e9251bc6..00000000 --- a/dhall/dhallFormat.sh +++ /dev/null @@ -1,2 +0,0 @@ -cd $(dirname "$0") -find -name '*.dhall' -exec dhall --ascii format --inplace {} \; diff --git a/dhall/generateYaml.sh b/dhall/generateYaml.sh deleted file mode 100755 index 270cb778..00000000 --- a/dhall/generateYaml.sh +++ /dev/null @@ -1,9 +0,0 @@ -cd $(dirname "$0") - -for f in ci release dhall; do - dhall-to-yaml --omit-empty --file $f.dhall --output ../.github/workflows/$f.yml -done - -dhall-to-yaml --omit-empty --file mergify.dhall --output ../.mergify.yml - -dhall-to-json --file scalaVersions.dhall --output ../scalaVersions.json diff --git a/dhall/javaVersions.dhall b/dhall/javaVersions.dhall new file mode 100644 index 00000000..eebc3d96 --- /dev/null +++ b/dhall/javaVersions.dhall @@ -0,0 +1 @@ +let default = "11" in { default, all = [ default, "14" ] } diff --git a/dhall/mergify.dhall b/dhall/mergify.dhall index a6dd2067..04d17f20 100644 --- a/dhall/mergify.dhall +++ b/dhall/mergify.dhall @@ -15,14 +15,14 @@ let ciJobNameRules = ) c.javaVersions.all ) - c.scalaVersions + c.scalaVersions.all in { pull_request_rules = [ { name = "automatically merge scala-steward's PRs" , conditions = [ "author=scala-steward", "body~=labels:.*semver-patch.*" ] # ciJobNameRules - , actions.merge.method = "merge" + , actions.`merge`.method = "merge" } ] } diff --git a/dhall/scalaVersions.dhall b/dhall/scalaVersions.dhall index 6a55d58c..04fa9b6b 100644 --- a/dhall/scalaVersions.dhall +++ b/dhall/scalaVersions.dhall @@ -1 +1 @@ -[ "2.12.11", "2.13.1" ] +let default = "2.12.11" in { default, all = [ default, "2.13.1" ] } diff --git a/project/Dhall.scala b/project/Dhall.scala new file mode 100644 index 00000000..9bcc8d08 --- /dev/null +++ b/project/Dhall.scala @@ -0,0 +1,58 @@ +import cats.effect._ +import java.nio.file.{Files, Paths} +import org.dhallj.core.Expr +import org.dhallj.core.converters.JsonConverter +import org.dhallj.imports.syntax._ +import org.dhallj.parser.DhallParser +import org.dhallj.yaml.YamlConverter +import org.http4s.client.Client +import org.http4s.client.jdkhttpclient.JdkHttpClient +import sbt.{IO => _, _} +import scala.concurrent.ExecutionContext +import upickle.default.{ReadWriter, macroRW} + +object Dhall { + + lazy val convertDhall = taskKey[Unit]("Generate YAML/JSON from Dhall.") + + private lazy val http = { + implicit val cs: ContextShift[IO] = IO.contextShift(ExecutionContext.global) + JdkHttpClient.simple[IO].unsafeRunSync() + } + + private def loadDhall(expr: String): Expr = { + implicit val c: Client[IO] = http + DhallParser + .parse(expr) + .normalize() + .resolveImports[IO] + .unsafeRunSync() + .normalize() + } + + val convertDhallTask = convertDhall := { + val baseDir = (Keys.baseDirectory in LocalRootProject).value.absolutePath + def convertYaml(from: String, to: String): Unit = { + val dhall = loadDhall(s"$baseDir/dhall/$from.dhall") + val yaml = YamlConverter.toYamlString(dhall) + Files.writeString(Paths.get(s"$baseDir/$to"), yaml) + } + List("ci", "release", "dhall").foreach { file => + convertYaml(file, s".github/workflows/$file.yml") + } + convertYaml("mergify", s".mergify.yml") + } + + case class ScalaVersions(default: String, all: List[String]) + object ScalaVersions { implicit val rw: ReadWriter[ScalaVersions] = macroRW } + + val scalaVersions = settingKey[ScalaVersions]("Read the Scala versions via Dhall") + + val scalaVersionsImpl = scalaVersions := { + val baseDir = (Keys.baseDirectory in LocalRootProject).value.absolutePath + val dhall = loadDhall(s"$baseDir/dhall/scalaVersions.dhall") + val json = JsonConverter.toCompactString(dhall) + upickle.default.read[ScalaVersions](json) + } + +} diff --git a/project/build.sbt b/project/build.sbt index 9580ea08..57e2ae83 100644 --- a/project/build.sbt +++ b/project/build.sbt @@ -1,3 +1,14 @@ +val dhalljV = "0.2.0" +val http4sJdkHttpClientV = "0.3.0" +val upickleV = "1.1.0" + +// format: off libraryDependencies ++= Seq( - "com.lihaoyi" %% "upickle" % "1.1.0" + "org.dhallj" % "dhall-core" % dhalljV, + "org.dhallj" % "dhall-parser" % dhalljV, + "org.dhallj" % "dhall-yaml" % dhalljV, + "org.dhallj" %% "dhall-imports" % dhalljV, + "org.http4s" %% "http4s-jdk-http-client" % http4sJdkHttpClientV, + "com.lihaoyi" %% "upickle" % upickleV ) +// format: on diff --git a/scalaVersions.json b/scalaVersions.json deleted file mode 100644 index 462f94cf..00000000 --- a/scalaVersions.json +++ /dev/null @@ -1,4 +0,0 @@ -[ - "2.12.11", - "2.13.1" -]