Skip to content

Commit

Permalink
Setup sbt-github-actions.
Browse files Browse the repository at this point in the history
  • Loading branch information
mrdziuban committed Mar 21, 2024
1 parent d8cc5d3 commit 0473e9d
Show file tree
Hide file tree
Showing 11 changed files with 271 additions and 51 deletions.
39 changes: 0 additions & 39 deletions .github/workflows/ci.yml

This file was deleted.

60 changes: 60 additions & 0 deletions .github/workflows/clean.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# This file was automatically generated by sbt-github-actions using the
# githubWorkflowGenerate 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 workflow description
# to meet your needs, then regenerate this file.

name: Clean

on: push

jobs:
delete-artifacts:
name: Delete Artifacts
runs-on: ubuntu-latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: Delete artifacts
shell: bash {0}
run: |
# Customize those three lines with your repository and credentials:
REPO=${GITHUB_API_URL}/repos/${{ github.repository }}
# A shortcut to call GitHub API.
ghapi() { curl --silent --location --user _:$GITHUB_TOKEN "$@"; }
# A temporary file which receives HTTP response headers.
TMPFILE=$(mktemp)
# An associative array, key: artifact name, value: number of artifacts of that name.
declare -A ARTCOUNT
# Process all artifacts on this repository, loop on returned "pages".
URL=$REPO/actions/artifacts
while [[ -n "$URL" ]]; do
# Get current page, get response headers in a temporary file.
JSON=$(ghapi --dump-header $TMPFILE "$URL")
# Get URL of next page. Will be empty if we are at the last page.
URL=$(grep '^Link:' "$TMPFILE" | tr ',' '\n' | grep 'rel="next"' | head -1 | sed -e 's/.*<//' -e 's/>.*//')
rm -f $TMPFILE
# Number of artifacts on this page:
COUNT=$(( $(jq <<<$JSON -r '.artifacts | length') ))
# Loop on all artifacts on this page.
for ((i=0; $i < $COUNT; i++)); do
# Get name of artifact and count instances of this name.
name=$(jq <<<$JSON -r ".artifacts[$i].name?")
ARTCOUNT[$name]=$(( $(( ${ARTCOUNT[$name]} )) + 1))
id=$(jq <<<$JSON -r ".artifacts[$i].id?")
size=$(( $(jq <<<$JSON -r ".artifacts[$i].size_in_bytes?") ))
printf "Deleting '%s' #%d, %'d bytes\n" $name ${ARTCOUNT[$name]} $size
ghapi -X DELETE $REPO/actions/artifacts/$id
done
done
79 changes: 79 additions & 0 deletions .github/workflows/scala-2-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# This file was automatically generated by sbt-github-actions using the
# githubWorkflowGenerate 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 workflow description
# to meet your needs, then regenerate this file.

name: Scala 2 Continuous Integration

on:
pull_request:
branches: [master]
push:
branches: [master]

env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

jobs:
build:
name: Build and Test
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
scala: [2.13.13]
java: [temurin@8, temurin@11, temurin@17, temurin@21]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout current branch (full)
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup Java (temurin@8)
if: matrix.java == 'temurin@8'
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 8
cache: sbt

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

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

- name: Setup Java (temurin@21)
if: matrix.java == 'temurin@21'
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 21
cache: sbt

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

- name: Build project
run: cd scala-2 && sbt '++ ${{ matrix.scala }}' test

- name: Check binary compatibility
if: matrix.java == 'temurin@8'
run: cd scala-2 && sbt '++ ${{ matrix.scala }}' mimaReportBinaryIssues

- name: Build docs
if: matrix.java == 'temurin@8'
run: cd scala-2 && sbt '++ ${{ matrix.scala }}' docs/mdoc
79 changes: 79 additions & 0 deletions .github/workflows/scala-3-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# This file was automatically generated by sbt-github-actions using the
# githubWorkflowGenerate 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 workflow description
# to meet your needs, then regenerate this file.

name: Scala 3 Continuous Integration

on:
pull_request:
branches: [master]
push:
branches: [master]

env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

jobs:
build:
name: Build and Test
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
scala: [3.3.3]
java: [temurin@8, temurin@11, temurin@17, temurin@21]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout current branch (full)
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup Java (temurin@8)
if: matrix.java == 'temurin@8'
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 8
cache: sbt

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

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

- name: Setup Java (temurin@21)
if: matrix.java == 'temurin@21'
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 21
cache: sbt

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

- name: Build project
run: cd scala-3 && sbt '++ ${{ matrix.scala }}' test

- name: Check binary compatibility
if: matrix.java == 'temurin@8'
run: cd scala-3 && sbt '++ ${{ matrix.scala }}' mimaReportBinaryIssues

- name: Build docs
if: matrix.java == 'temurin@8'
run: cd scala-3 && sbt '++ ${{ matrix.scala }}' docs/mdoc
23 changes: 23 additions & 0 deletions CommonBuild.scala
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import com.typesafe.tools.mima.plugin.MimaKeys.mimaPreviousArtifacts
import sbt.*
import sbt.Keys.*
import sbtghactions.{JavaSpec, WorkflowStep}
import sbtghactions.GenerativeKeys.*
import sbtgitpublish.GitPublishKeys.*

package object andxor {
val currentVersion = "0.14.0"

val scala2 = "2.13.13"
val scala3 = "3.3.3"

val catsVersion = "2.10.0"
val catsCore = "org.typelevel" %% "cats-core" % catsVersion
val catsLaws = "org.typelevel" %% "cats-laws" % catsVersion % "test"
Expand All @@ -21,7 +26,11 @@ package object andxor {

val scalariform = ("org.scalariform" %% "scalariform" % "0.2.10").cross(CrossVersion.for3Use2_13)

val javaVersions = Seq(8, 11, 17, 21).map(v => JavaSpec.temurin(v.toString))
val isJava8 = s"matrix.java == '${javaVersions.find(_.version == "8").get.render}'"

trait CommonBuild {
val relDir: String
val baseSettings0: Seq[Setting[_]]

final lazy val baseSettings = Seq(
Expand Down Expand Up @@ -51,6 +60,20 @@ package object andxor {
mimaPreviousArtifacts := Set("andxor" %% name.value % "0.14.0"),
)

final lazy val githubActionsSettings = Seq(
ThisBuild / githubWorkflowScalaVersions := Some(crossScalaVersions.value).filter(_.nonEmpty).getOrElse(Seq(scalaVersion.value)),
ThisBuild / githubWorkflowJavaVersions := javaVersions,
ThisBuild / githubWorkflowArtifactUpload := false,
ThisBuild / githubWorkflowBuildMatrixFailFast := Some(false),
ThisBuild / githubWorkflowTargetBranches := Seq("master"),
ThisBuild / githubWorkflowPublishTargetBranches := Seq(),
ThisBuild / githubWorkflowSbtCommand := s"cd $relDir && sbt",
ThisBuild / githubWorkflowBuild ++= Seq(
WorkflowStep.Sbt(List("mimaReportBinaryIssues"), name = Some("Check binary compatibility"), cond = Some(isJava8)),
WorkflowStep.Sbt(List("docs/mdoc"), name = Some("Build docs"), cond = Some(isJava8)),
),
)

final lazy val testSettings = Seq(libraryDependencies += scalacheck % "test")

def generateBase = Project("generate", file("generate"))
Expand Down
17 changes: 17 additions & 0 deletions both.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,21 @@ function mimaReport() {
sbtSequential mimaReportBinaryIssues
}



function githubWorkflowGenerate() {
sbtParallel githubWorkflowGenerate

ghdir='.github/workflows'

mv "scala-2/$ghdir/clean.yml" "$ghdir/clean.yml"
rm "scala-3/$ghdir/clean.yml"

cat "scala-2/$ghdir/ci.yml" | sed -E 's/^(name:)\s*(Continuous Integration)$/\1 Scala 2 \2/' > "$ghdir/scala-2-ci.yml"
rm "scala-2/$ghdir/ci.yml"

cat "scala-3/$ghdir/ci.yml" | sed -E 's/^(name:)\s*(Continuous Integration)$/\1 Scala 3 \2/' > "$ghdir/scala-3-ci.yml"
rm "scala-3/$ghdir/ci.yml"
}

$operation
1 change: 1 addition & 0 deletions common-plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
addSbtPlugin("com.github.sbt" % "sbt-github-actions" % "0.23.0")
addSbtPlugin("com.typesafe" % "sbt-mima-plugin" % "1.1.3")
addSbtPlugin("org.typelevel" % "sbt-tpolecat" % "0.5.0")
addSbtPlugin("org.scalameta" % "sbt-mdoc" % "2.5.2")
Expand Down
9 changes: 4 additions & 5 deletions scala-2/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import andxor.Build._

Global / onChangedBuildSource := ReloadOnSourceChanges

githubActionsSettings

lazy val generate: Project = generateBase

lazy val core: Project = coreBase
Expand All @@ -18,11 +20,8 @@ lazy val tests: Project = testsBase
.dependsOn(core, scalacheck, argonaut, circe)

lazy val root: Project = project.in(file("."))
.settings(commonSettings)
.settings(
crossScalaVersions := Seq(),
gitRelease := {}
)
.settings(baseSettings)
.settings(gitRelease := {})
.aggregate(generate, core, argonaut, circe, scalacheck, tests)

lazy val docs = project.in(file("andxor-docs"))
Expand Down
3 changes: 2 additions & 1 deletion scala-2/project/Build.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import sbt.Keys._
import sbtgitpublish.GitPublishKeys._

object Build extends CommonBuild {
val scalaVersions = Seq("2.13.13")
val relDir = "scala-2"
val scalaVersions = Seq(scala2)

def scalaVersionSpecificFolders(srcName: String, srcBaseDir: java.io.File, scalaVersion: String): Seq[java.io.File] =
CrossVersion.partialVersion(scalaVersion) match {
Expand Down
9 changes: 4 additions & 5 deletions scala-3/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import andxor.Build._

Global / onChangedBuildSource := ReloadOnSourceChanges

githubActionsSettings

lazy val generate: Project = generateBase
.settings(
buildInfoKeys := Seq[BuildInfoKey]("rootDir" -> (ThisBuild / baseDirectory).value.toString),
Expand All @@ -17,11 +19,8 @@ lazy val tests: Project = testsBase
.dependsOn(core, scalacheck)

lazy val root: Project = project.in(file("."))
.settings(commonSettings)
.settings(
crossScalaVersions := Seq(),
gitRelease := {}
)
.settings(baseSettings)
.settings(gitRelease := {})
.aggregate(core, scalacheck, tests)

lazy val docs = project.in(file("andxor-docs"))
Expand Down
Loading

0 comments on commit 0473e9d

Please sign in to comment.