Skip to content

Commit

Permalink
Use sbt-typelevel-mergify to generate .mergify.yml
Browse files Browse the repository at this point in the history
This replaces sbt-github-actions with sbt-typelevel-github-actions and
adds sbt-typelevel-mergify to generate the `.mergify.yml` from our
build. The advantage of that approach is that Scala and JDK versions in
the Mergify config are always in sync with the build which is verified
by the CI via the `githubWorkflowCheck` task.
  • Loading branch information
fthomas committed Jan 8, 2023
1 parent 63c3ece commit 8226035
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 50 deletions.
98 changes: 70 additions & 28 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,30 +24,48 @@ jobs:
matrix:
os: [ubuntu-latest]
scala: [2.13.10]
java: [adopt-hotspot@17, adopt-hotspot@11]
java: [temurin@17, temurin@11]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout current branch (full)
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
fetch-depth: 0

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

- name: Setup Java (adopt-hotspot@11)
if: matrix.java == 'adopt-hotspot@11'
uses: actions/setup-java@v2
- name: Setup Java (temurin@17)
if: matrix.java == 'temurin@17'
uses: actions/setup-java@v3
with:
distribution: adopt-hotspot
distribution: jdkfile
java-version: 17
jdkFile: ${{ steps.download-java-temurin-17.outputs.jdkFile }}

- name: Download Java (temurin@11)
id: download-java-temurin-11
if: matrix.java == 'temurin@11'
uses: typelevel/download-java@v2
with:
distribution: temurin
java-version: 11

- name: Setup Java (temurin@11)
if: matrix.java == 'temurin@11'
uses: actions/setup-java@v3
with:
distribution: jdkfile
java-version: 11
jdkFile: ${{ steps.download-java-temurin-11.outputs.jdkFile }}

- name: Cache sbt
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: |
~/.sbt
Expand All @@ -59,21 +77,27 @@ 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 githubWorkflowCheck

- name: Build project
run: sbt ++${{ matrix.scala }} validate
run: sbt '++ ${{ matrix.scala }}' validate

- name: Codecov
uses: codecov/codecov-action@v3

- name: Make target directories
if: github.event_name != 'pull_request' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v'))
run: mkdir -p target modules/docs/.jvm/target modules/dummy/.jvm/target modules/core/.jvm/target modules/benchmark/.jvm/target project/target

- name: Compress target directories
if: github.event_name != 'pull_request' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v'))
run: tar cf targets.tar target modules/docs/.jvm/target modules/dummy/.jvm/target modules/core/.jvm/target modules/benchmark/.jvm/target project/target

- name: Upload target directories
uses: actions/upload-artifact@v2
if: github.event_name != 'pull_request' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v'))
uses: actions/upload-artifact@v3
with:
name: target-${{ matrix.os }}-${{ matrix.scala }}-${{ matrix.java }}
name: target-${{ matrix.os }}-${{ matrix.java }}-${{ matrix.scala }}
path: targets.tar

publish:
Expand All @@ -84,30 +108,48 @@ jobs:
matrix:
os: [ubuntu-latest]
scala: [2.12.17]
java: [adopt-hotspot@17]
java: [temurin@17]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout current branch (full)
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
fetch-depth: 0

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

- name: Setup Java (adopt-hotspot@11)
if: matrix.java == 'adopt-hotspot@11'
uses: actions/setup-java@v2
- name: Setup Java (temurin@17)
if: matrix.java == 'temurin@17'
uses: actions/setup-java@v3
with:
distribution: jdkfile
java-version: 17
jdkFile: ${{ steps.download-java-temurin-17.outputs.jdkFile }}

- name: Download Java (temurin@11)
id: download-java-temurin-11
if: matrix.java == 'temurin@11'
uses: typelevel/download-java@v2
with:
distribution: temurin
java-version: 11

- name: Setup Java (temurin@11)
if: matrix.java == 'temurin@11'
uses: actions/setup-java@v3
with:
distribution: adopt-hotspot
distribution: jdkfile
java-version: 11
jdkFile: ${{ steps.download-java-temurin-11.outputs.jdkFile }}

- name: Cache sbt
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: |
~/.sbt
Expand All @@ -119,9 +161,9 @@ jobs:
key: ${{ runner.os }}-sbt-cache-v2-${{ hashFiles('**/*.sbt') }}-${{ hashFiles('project/build.properties') }}

- name: Download target directories (2.13.10)
uses: actions/download-artifact@v2
uses: actions/download-artifact@v3
with:
name: target-${{ matrix.os }}-2.13.10-${{ matrix.java }}
name: target-${{ matrix.os }}-${{ matrix.java }}-2.13.10

- name: Inflate target directories (2.13.10)
run: |
Expand Down
39 changes: 23 additions & 16 deletions .mergify.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
# This file was automatically generated by sbt-typelevel-mergify using the
# mergifyGenerate task. You should add and commit this file to
# your git repository. It goes without saying that you shouldn't edit
# this file by hand! Instead, if you wish to make changes, you should
# change your sbt build configuration to revise the mergify configuration
# to meet your needs, then regenerate this file.

pull_request_rules:
- name: assign and label scala-steward's PRs
conditions:
- author=scala-steward
actions:
assign:
users: [fthomas]
label:
add: [dependency-update]
- name: merge scala-steward's PRs
conditions:
- author=scala-steward
- status-success=Build and Test (ubuntu-latest, 2.13.10, adopt-hotspot@17)
- status-success=Build and Test (ubuntu-latest, 2.13.10, adopt-hotspot@11)
actions:
merge:
method: squash
- name: label scala-steward's PRs
conditions:
- author=scala-steward
actions:
label:
add:
- dependency-update
remove: []
- name: merge scala-steward's PRs
conditions:
- author=scala-steward
- status-success=Build and Test (ubuntu-latest, 2.13.10, temurin@17)
- status-success=Build and Test (ubuntu-latest, 2.13.10, temurin@11)
actions:
merge:
method: squash
26 changes: 21 additions & 5 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import scala.util.Properties
import scala.reflect.io.Path
import com.typesafe.sbt.packager.docker._
import sbtcrossproject.{CrossProject, CrossType, Platform}
import sbtghactions.JavaSpec.Distribution.Adopt
import org.typelevel.sbt.gha.JavaSpec.Distribution.Temurin

/// variables

Expand All @@ -23,7 +23,7 @@ val moduleCrossPlatformMatrix: Map[String, List[Platform]] = Map(

val Scala213 = "2.13.10"

/// sbt-github-actions configuration
/// sbt-typelevel configuration

ThisBuild / crossScalaVersions := Seq(Scala213)
ThisBuild / githubWorkflowTargetTags ++= Seq("v*")
Expand All @@ -50,7 +50,7 @@ ThisBuild / githubWorkflowPublish := Seq(
name = Some("Publish Docker image")
)
)
ThisBuild / githubWorkflowJavaVersions := Seq(JavaSpec(Adopt, "17"), JavaSpec(Adopt, "11"))
ThisBuild / githubWorkflowJavaVersions := Seq(JavaSpec(Temurin, "17"), JavaSpec(Temurin, "11"))
ThisBuild / githubWorkflowBuild :=
Seq(
WorkflowStep.Sbt(List("validate"), name = Some("Build project")),
Expand All @@ -60,8 +60,26 @@ ThisBuild / githubWorkflowBuild :=
)
)

ThisBuild / mergifyPrRules := {
val authorCondition = MergifyCondition.Custom("author=scala-steward")
Seq(
MergifyPrRule(
"label scala-steward's PRs",
List(authorCondition),
List(MergifyAction.Label(List("dependency-update")))
),
MergifyPrRule(
"merge scala-steward's PRs",
List(authorCondition) ++ mergifySuccessConditions.value,
List(MergifyAction.Merge(Some("squash")))
)
)
}

/// global build settings

ThisBuild / dynverSeparator := "-"

ThisBuild / evictionErrorLevel := Level.Info

/// projects
Expand Down Expand Up @@ -264,8 +282,6 @@ def myCrossProject(name: String): CrossProject =
)
.settings(commonSettings)

ThisBuild / dynverSeparator := "-"

lazy val commonSettings = Def.settings(
compileSettings,
metadataSettings,
Expand Down
2 changes: 1 addition & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
addSbtPlugin("com.codecommit" % "sbt-github-actions" % "0.14.2")
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "2.1.0")
addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.11.0")
addSbtPlugin("com.github.sbt" % "sbt-ci-release" % "1.5.11")
Expand All @@ -12,3 +11,4 @@ addSbtPlugin("pl.project13.scala" % "sbt-jmh" % "0.4.3")
addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % "1.2.0")
addSbtPlugin("org.scalameta" % "sbt-mdoc" % "2.3.6")
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "2.0.6")
addSbtPlugin("org.typelevel" % "sbt-typelevel-mergify" % "0.4.18")

0 comments on commit 8226035

Please sign in to comment.