Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to sbt-typelevel #367

Merged
merged 7 commits into from
Jan 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 34 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ on:
tags: [v*]

env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }}
PGP_PASSPHRASE: ${{ secrets.PGP_PASSPHRASE }}
SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}
SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }}
PGP_SECRET: ${{ secrets.PGP_SECRET }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

jobs:
build:
Expand All @@ -28,6 +29,7 @@ jobs:
os: [ubuntu-latest]
scala: [2.12.15, 2.13.8, 3.1.0]
java: [temurin@8]
project: [rootJS, rootJVM]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout current branch (full)
Expand Down Expand Up @@ -55,12 +57,29 @@ jobs:
key: ${{ runner.os }}-sbt-cache-v2-${{ hashFiles('**/*.sbt') }}-${{ hashFiles('project/build.properties') }}

- name: Check that workflows are up to date
run: sbt ++${{ matrix.scala }} githubWorkflowCheck
run: sbt 'project ${{ matrix.project }}' '++${{ matrix.scala }}' 'project /' githubWorkflowCheck

- name: Check headers and formatting
run: sbt 'project ${{ matrix.project }}' '++${{ matrix.scala }}' headerCheckAll scalafmtCheckAll 'project /' scalafmtSbtCheck

- name: fastOptJS
if: matrix.project == 'rootJS'
run: sbt 'project ${{ matrix.project }}' '++${{ matrix.scala }}' Test/fastOptJS

- run: sbt ++${{ matrix.scala }} ci
- name: Test
run: sbt 'project ${{ matrix.project }}' '++${{ matrix.scala }}' test

- name: Check binary compatibility
run: sbt 'project ${{ matrix.project }}' '++${{ matrix.scala }}' mimaReportBinaryIssues

- name: Generate API documentation
run: sbt 'project ${{ matrix.project }}' '++${{ matrix.scala }}' doc

- name: Make target directories
run: mkdir -p target .js/target test-kit/js/target js/target test-kit/jvm/target jvm/target .jvm/target .native/target project/target

- name: Compress target directories
run: tar cf targets.tar target test-kit/js/target js/target test-kit/jvm/target jvm/target project/target
run: tar cf targets.tar target .js/target test-kit/js/target js/target test-kit/jvm/target jvm/target .jvm/target .native/target project/target

- name: Upload target directories
uses: actions/upload-artifact@v2
Expand Down Expand Up @@ -134,6 +153,15 @@ jobs:
rm targets.tar

- name: Import signing key
if: env.PGP_SECRET != '' && env.PGP_PASSPHRASE == ''
run: echo $PGP_SECRET | base64 -d | gpg --import

- run: sbt ++${{ matrix.scala }} release
- name: Import signing key and strip passphrase
if: env.PGP_SECRET != '' && env.PGP_PASSPHRASE != ''
run: |
echo "$PGP_SECRET" | base64 -d > /tmp/signing-key.gpg
echo "$PGP_PASSPHRASE" | gpg --pinentry-mode loopback --passphrase-fd 0 --import /tmp/signing-key.gpg
(echo "$PGP_PASSPHRASE"; echo; echo) | gpg --command-fd 0 --pinentry-mode loopback --change-passphrase $(gpg --list-secret-keys --with-colons 2> /dev/null | grep '^sec:' | cut --delimiter ':' --fields 5 | tail -n 1)

- name: Publish
run: sbt '++${{ matrix.scala }}' tlRelease
5 changes: 3 additions & 2 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ maxColumn: 120
runner.dialect = scala213source3

fileOverride {
"glob:**/shared/src/main/scala-3/**" {
runner.dialect = scala3
"glob:**/scala-3/**" {
runner.dialect = scala3
}
}

58 changes: 12 additions & 46 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,59 +1,34 @@
import sbtcrossproject.CrossPlugin.autoImport.crossProject
import sbtcrossproject.CrossPlugin.autoImport.CrossType
import com.typesafe.tools.mima.core._

ThisBuild / baseVersion := "3.1"
ThisBuild / tlBaseVersion := "3.1"

ThisBuild / organization := "com.comcast"
ThisBuild / organizationName := "Comcast Cable Communications Management, LLC"

ThisBuild / homepage := Some(url("https://github.com/comcast/ip4s"))
ThisBuild / startYear := Some(2018)

ThisBuild / publishGithubUser := "mpilquist"
ThisBuild / publishFullName := "Michael Pilquist"

ThisBuild / developers ++= List(
Developer("matthughes", "Matt Hughes", "@matthughes", url("https://github.com/matthughes")),
Developer("nequissimus", "Tim Steinbach", "@nequissimus", url("https://github.com/nequissimus"))
tlGitHubDev("mpilquist", "Michael Pilquist"),
tlGitHubDev("matthughes", "Matt Hughes"),
tlGitHubDev("nequissimus", "Tim Steinbach")
)

ThisBuild / githubWorkflowJavaVersions := Seq(JavaSpec.temurin("8"))

ThisBuild / crossScalaVersions := List("2.12.15", "2.13.8", "3.1.0")

ThisBuild / spiewakCiReleaseSnapshots := true

ThisBuild / spiewakMainBranches := List("main")

ThisBuild / homepage := Some(url("https://github.com/comcast/ip4s"))

ThisBuild / scmInfo := Some(
ScmInfo(
url("https://github.com/comcast/ip4s"),
"git@github.com:comcast/ip4s.git"
)
)

ThisBuild / testFrameworks += new TestFramework("munit.Framework")
ThisBuild / tlVersionIntroduced := Map("3" -> "3.0.3")

ThisBuild / doctestTestFramework := DoctestTestFramework.ScalaCheck

ThisBuild / scalafmtOnCompile := true

ThisBuild / initialCommands := "import com.comcast.ip4s._"

ThisBuild / fatalWarningsInCI := false

ThisBuild / mimaBinaryIssueFilters ++= Seq(
ProblemFilters.exclude[DirectMissingMethodProblem]("com.comcast.ip4s.Ipv6Address.toInetAddress"),
ProblemFilters.exclude[ReversedMissingMethodProblem]("com.comcast.ip4s.Dns.*") // sealed trait
)

lazy val root = project
.in(file("."))
.enablePlugins(NoPublishPlugin, SonatypeCiReleasePlugin)
.aggregate(coreJVM, coreJS, testKitJVM, testKitJS)
lazy val root = tlCrossRootProject.aggregate(core, testKit)

lazy val testKit = crossProject(JVMPlatform, JSPlatform)
.in(file("./test-kit"))
Expand Down Expand Up @@ -86,21 +61,10 @@ lazy val core = crossProject(JVMPlatform, JSPlatform)
.settings(
name := "ip4s-core",
libraryDependencies ++= {
if (isDotty.value) Nil else List("org.scala-lang" % "scala-reflect" % scalaVersion.value % "provided")
if (tlIsScala3.value) Nil
else List("org.scala-lang" % "scala-reflect" % scalaVersion.value % "provided")
},
scalacOptions := scalacOptions.value.filterNot(_ == "-source:3.0-migration"),
Compile / scalafmt / unmanagedSources := (Compile / scalafmt / unmanagedSources).value.filterNot(
_.toString.endsWith("Literals.scala")
),
Test / scalafmt / unmanagedSources := (Test / scalafmt / unmanagedSources).value.filterNot(
_.toString.endsWith("Literals.scala")
),
Compile / unmanagedSourceDirectories ++= {
val major = if (isDotty.value) "-3" else "-2"
List(CrossType.Pure, CrossType.Full).flatMap(
_.sharedSrcDir(baseDirectory.value, "main").toList.map(f => file(f.getPath + major))
)
}
scalacOptions := scalacOptions.value.filterNot(_ == "-source:3.0-migration")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just for my learning, why does this option not work here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It disables certain Scala 3 only features - in this case, the macro support.

)
.settings(
libraryDependencies ++= Seq(
Expand All @@ -110,7 +74,9 @@ lazy val core = crossProject(JVMPlatform, JSPlatform)
)
)

lazy val coreJVM = core.jvm
lazy val coreJVM = core.jvm.settings(
doctestIgnoreRegex := Some(".*Literals.scala")
)

lazy val coreJS = core.js
.disablePlugins(DoctestPlugin)
Expand Down
3 changes: 3 additions & 0 deletions js/src/main/scala/com/comcast/ip4s/DnsPlatform.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package com.comcast.ip4s
import cats.effect.kernel.Async
import cats.syntax.all._

import scala.annotation.nowarn
import scala.scalajs.js
import scala.scalajs.js.|
import scala.scalajs.js.annotation.JSImport
Expand Down Expand Up @@ -87,8 +88,10 @@ private[ip4s] trait DnsCompanionPlatform {
@JSImport("dns", "promises")
private[ip4s] object dnsPromises extends js.Any {

@nowarn
def lookup(hostname: String, options: LookupOptions): js.Promise[LookupResult | js.Array[LookupResult]] = js.native

@nowarn
def reverse(ip: String): js.Promise[js.Array[String]] = js.native
}

Expand Down
4 changes: 4 additions & 0 deletions js/src/main/scala/com/comcast/ip4s/IDNCompanionPlatform.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.comcast.ip4s

import scala.annotation.nowarn
import scalajs._
import scala.scalajs.js.annotation._
import scala.util.Try
Expand All @@ -31,6 +32,9 @@ private[ip4s] trait IDNCompanionPlatform {
@js.native
@JSImport("punycode", JSImport.Default)
private[ip4s] object Punycode extends js.Any {
@nowarn
def toASCII(value: String): String = js.native

@nowarn
def toUnicode(value: String): String = js.native
}
6 changes: 1 addition & 5 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
addSbtPlugin("org.typelevel" % "sbt-typelevel" % "0.4.1")
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.8.0")
addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % "1.1.0")
addSbtPlugin("ch.epfl.scala" % "sbt-scalajs-bundler" % "0.20.0")
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.4.6")
addSbtPlugin("com.codecommit" % "sbt-spiewak-sonatype" % "0.23.0")
addSbtPlugin("com.codecommit" % "sbt-github-actions" % "0.14.2")
addSbtPlugin("com.github.tkawachi" % "sbt-doctest" % "0.9.9")
addSbtPlugin("com.typesafe" % "sbt-mima-plugin" % "1.0.1")
addSbtPlugin("org.scalameta" % "sbt-mdoc" % "2.2.24")