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

Migrate to sbt-typelevel and self-host #120

Merged
merged 12 commits into from
Jan 18, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
61 changes: 46 additions & 15 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ on:
branches: ['**']
push:
branches: ['**']
tags: [v*, v*]
tags: [v*]

env:
PGP_PASSPHRASE: ${{ secrets.PGP_PASSPHRASE }}
SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}
JABBA_INDEX: 'https://github.com/typelevel/jdk-index/raw/main/index.json'
SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }}
PGP_SECRET: ${{ secrets.PGP_SECRET }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -25,10 +25,11 @@ jobs:
build:
name: Build and Test
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
scala: [2.12.15]
java: [temurin@8]
java: [temurin@8, temurin@11, temurin@17]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout current branch (full)
Expand All @@ -43,6 +44,20 @@ jobs:
distribution: temurin
java-version: 8

- name: Setup Java (temurin@11)
if: matrix.java == 'temurin@11'
uses: actions/setup-java@v2
with:
distribution: temurin
java-version: 11

- name: Setup Java (temurin@17)
if: matrix.java == 'temurin@17'
uses: actions/setup-java@v2
with:
distribution: temurin
java-version: 17

- name: Cache sbt
uses: actions/cache@v2
with:
Expand All @@ -58,21 +73,15 @@ jobs:
- name: Check that workflows are up to date
run: sbt ++${{ matrix.scala }} githubWorkflowCheck

- name: Check formatting
run: sbt ++${{ matrix.scala }} scalafmtCheckAll scalafmtSbtCheck

- name: Check headers
run: sbt ++${{ matrix.scala }} headerCheckAll

- name: Compile
run: 'sbt ++${{ matrix.scala }} test:compile'

- name: Run tests
run: sbt ++${{ matrix.scala }} test
- run: sbt ++${{ matrix.scala }} ci
Copy link
Member

Choose a reason for hiding this comment

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

Now that I see it from a workflow perspective, I'm not sure I consider this progress. It is now harder to see on what step a build fails.

Copy link
Member Author

@armanbilge armanbilge Jan 9, 2022

Choose a reason for hiding this comment

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

Opened typelevel/sbt-typelevel#60 to think about this one.


- name: Build docs
if: matrix.ci == '' || matrix.ci == 'ciJVM'
run: sbt ++${{ matrix.scala }} doc

- name: Make target directories
run: mkdir -p target core/target project/target

- name: Compress target directories
run: tar cf targets.tar target core/target project/target

Expand All @@ -85,7 +94,7 @@ jobs:
publish:
name: Publish Artifacts
needs: [build]
if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/v'))
if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main')
strategy:
matrix:
os: [ubuntu-latest]
Expand All @@ -105,6 +114,20 @@ jobs:
distribution: temurin
java-version: 8

- name: Setup Java (temurin@11)
if: matrix.java == 'temurin@11'
uses: actions/setup-java@v2
with:
distribution: temurin
java-version: 11

- name: Setup Java (temurin@17)
if: matrix.java == 'temurin@17'
uses: actions/setup-java@v2
with:
distribution: temurin
java-version: 17

- name: Cache sbt
uses: actions/cache@v2
with:
Expand All @@ -128,6 +151,14 @@ jobs:
rm targets.tar

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

- 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)

- run: sbt ++${{ matrix.scala }} release
53 changes: 12 additions & 41 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
enablePlugins(SonatypeCiReleasePlugin)
enablePlugins(TypelevelCiReleasePlugin)

// Projects
lazy val `sbt-http4s-org` = project
Expand All @@ -10,45 +10,16 @@ lazy val core = project
.in(file("core"))
.enablePlugins(SbtPlugin)
.settings(
name := "sbt-http4s-org",
addSbtPlugin("com.codecommit" % "sbt-spiewak-sonatype" % "0.23.0"),
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.4.6")
name := "sbt-http4s-org"
)

// General Settings
inThisBuild(
List(
organization := "org.http4s",
organizationName := "http4s.org",
publishGithubUser := "rossabaker",
publishFullName := "Ross A. Baker",
baseVersion := "0.7",
crossScalaVersions := Seq("2.12.15"),
developers := List(
Developer(
"rossabaker",
"Ross A. Baker",
"ross@rossabaker.com",
url("https://github.com/rossabaker"))
),
homepage := Some(url("https://github.com/http4s/sbt-http4s-org")),
scmInfo := Some(
ScmInfo(
url("https://github.com/http4s/sbt-http4s-org.git"),
"git@github.com:http4s/sbt-http4s-org.git")),
startYear := Some(2020),
licenses := Seq("Apache-2.0" -> url("https://www.apache.org/licenses/LICENSE-2.0.html")),
githubWorkflowTargetTags ++= Seq("v*"),
githubWorkflowBuild := Seq(
WorkflowStep
.Sbt(List("scalafmtCheckAll", "scalafmtSbtCheck"), name = Some("Check formatting")),
WorkflowStep
.Sbt(List("headerCheckAll"), name = Some("Check headers")),
WorkflowStep.Sbt(List("test:compile"), name = Some("Compile")),
WorkflowStep.Sbt(List("test"), name = Some("Run tests")),
WorkflowStep.Sbt(List("doc"), name = Some("Build docs"))
),
githubWorkflowJavaVersions := Seq(JavaSpec.temurin("8")),
githubWorkflowEnv += ("JABBA_INDEX" -> "https://github.com/typelevel/jdk-index/raw/main/index.json"),
spiewakMainBranches := Seq("main")
))
ThisBuild / tlBaseVersion := "0.10"
ThisBuild / crossScalaVersions := Seq("2.12.15")
ThisBuild / developers := List(
Developer(
"rossabaker",
"Ross A. Baker",
"ross@rossabaker.com",
url("https://github.com/rossabaker"))
)
ThisBuild / startYear := Some(2020)
2 changes: 2 additions & 0 deletions core/build.sbt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
resolvers += Resolver.sonatypeRepo("snapshots")
addSbtPlugin("org.typelevel" % "sbt-typelevel" % "0.4-91c982a-SNAPSHOT")
40 changes: 8 additions & 32 deletions core/src/main/scala/org/http4s/sbt/Http4sOrgPlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@ import sbt.Keys._
import com.typesafe.sbt.SbtGit.git
import sbtghactions._
import sbtghactions.GenerativeKeys._
import sbtspiewak._, SonatypeCiReleasePlugin.autoImport._
import org.typelevel.sbt._, TypelevelSonatypeCiReleasePlugin.autoImport._

object Http4sOrgPlugin extends AutoPlugin {
object autoImport

override def trigger = allRequirements

override def requires = SpiewakPlugin && SonatypeCiReleasePlugin
override def requires = TypelevelPlugin

override def buildSettings = organizationSettings ++ githubActionsSettings ++ http4sStyleSnapshots
override def buildSettings = organizationSettings ++ githubActionsSettings

val organizationSettings: Seq[Setting[_]] =
Seq(
Expand All @@ -41,39 +41,15 @@ object Http4sOrgPlugin extends AutoPlugin {

val githubActionsSettings: Seq[Setting[_]] =
Seq(
spiewakMainBranches := Seq("main"),
tlCiReleaseBranches := Seq("main"),
githubWorkflowJavaVersions := List("8", "11", "17").map(JavaSpec.temurin(_)),
githubWorkflowEnv += ("JABBA_INDEX" -> "https://github.com/typelevel/jdk-index/raw/main/index.json"),
githubWorkflowBuild := Seq(
WorkflowStep
.Sbt(List("scalafmtCheckAll", "scalafmtSbtCheck"), name = Some("Check formatting")),
WorkflowStep.Sbt(List("headerCheckAll"), name = Some("Check headers")),
WorkflowStep.Sbt(List("test:compile"), name = Some("Compile")),
WorkflowStep.Sbt(List("mimaReportBinaryIssues"), name = Some("Check binary compatibility")),
githubWorkflowBuild +=
WorkflowStep.Sbt(
List("unusedCompileDependenciesTest"),
name = Some("Check unused compile dependencies")),
Copy link
Member Author

Choose a reason for hiding this comment

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

This is something not currently covered in sbt-typelevel. I'm a bit confused, are projects actually using this? If so I should add it back.

Copy link
Member

Choose a reason for hiding this comment

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

http4s should be. I think it's good POM hygiene, but it's one of my less popular opinions.

Copy link
Member Author

Choose a reason for hiding this comment

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

I've never used it but seems like a good idea. I don't see it in the http4s CI rn:
https://github.com/http4s/http4s/blob/0671d49d246639e3edad89d7f8e1ba979d9a7658/.github/workflows/ci.yml#L100-L125

Copy link
Member

Choose a reason for hiding this comment

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

We had the explicit dependencies check in addition to the unused dependencies check. The former was very controversial, but I'd like to reinstate the latter.

WorkflowStep.Sbt(List("test"), name = Some("Run tests")),
WorkflowStep.Sbt(List("doc"), name = Some("Build docs"))
),
List("doc"),
name = Some("Build docs"),
cond = Some("matrix.ci == '' || matrix.ci == 'ciJVM'")),
Copy link
Member Author

Choose a reason for hiding this comment

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

So, this cond here is a bit annoying.

Copy link
Member

Choose a reason for hiding this comment

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

I don't quite understand it.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm trying to account for CI matrices with a JVM/JS axis here. There might be a better way to do this.

We only want to run doc once per platform, but we don't know if there are platforms and if so how they are setup. E.g. we might want to do project rootJVM; doc and project rootJS; doc in their appropriate jobs. But that seems hard, since not all project have rootJVM and rootJS.

So, what I did was try to run doc conditionally:

  1. matrix.ci == 'ciJVM' we are running in a JVM job in a crossed matrix, so we should run doc
  2. matrix.ci == '' The ci key is not defined, so the matrix is not crossed, and we should run doc

Of course, we could run this step on all the jobs, but it would be redundant and time-consuming.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixing typelevel/sbt-typelevel#61 would fix this insanity.

githubWorkflowBuildMatrixFailFast := Some(false),
githubWorkflowArtifactUpload := false,
Copy link
Member Author

Choose a reason for hiding this comment

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

Any reason we don't like this?

Copy link
Member

Choose a reason for hiding this comment

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

I remember it being an irritant, but don't remember why. I'm happy to try without it.

githubWorkflowTargetBranches := Seq("**")
)

val http4sStyleSnapshots: Seq[Setting[_]] =
Seq(
isSnapshot :=
git.gitCurrentTags.value.isEmpty || git.gitUncommittedChanges.value,
version := {
val v = version.value
val suffix = "-SNAPSHOT"
if (isSnapshot.value && !v.endsWith(suffix)) v + suffix else v
},
githubWorkflowPublish := Seq(
WorkflowStep.Sbt(List("+publish")),
WorkflowStep
.Sbt(List("sonatypeBundleRelease"), cond = Some("startsWith(github.ref, 'refs/tags/v')"))
)
)
}
1 change: 1 addition & 0 deletions project/Http4sOrgPlugin.scala
1 change: 1 addition & 0 deletions project/core.sbt
2 changes: 0 additions & 2 deletions project/plugins.sbt

This file was deleted.