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

chore: adding mock server and ci/cd #10

Merged
merged 11 commits into from
Nov 21, 2024
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
152 changes: 152 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
# 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: Continuous Integration

on:
pull_request:
branches: [main]
push:
branches: [main]
tags: [v*]

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

jobs:
build:
name: Build and Test
strategy:
matrix:
os: [ubuntu-latest]
scala: [2.12.19, 2.13.14, 3.3.3]
java: [temurin@8, temurin@11]
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 sbt
uses: sbt/setup-sbt@v1

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

- name: Build
run: 'sbt ''++ ${{ matrix.scala }}'' clean compile integration_test/test:compile'

- name: Start Mock Server
run: ./start-mock-server.sh

- name: Run Integration Tests
run: sbt '++ ${{ matrix.scala }}' it

publish:
name: Publish Artifacts
needs: [build]
if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/v'))
strategy:
matrix:
os: [ubuntu-latest]
scala: [2.12.18]
java: [temurin@8]
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 sbt
uses: sbt/setup-sbt@v1

- name: Publish project
env:
PGP_PASSPHRASE: ${{ secrets.PGP_PASSPHRASE }}
PGP_SECRET: ${{ secrets.PGP_SECRET }}
SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}
SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }}
run: sbt ci-release

mima_check:
name: Mima Check
if: ${{ github.event_name == 'pull_request' }}
strategy:
matrix:
os: [ubuntu-latest]
scala: [2.13.10]
java: [temurin@21]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- uses: coursier/setup-action@v1

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

- run: sbt mimaChecks

check:
name: Check Formatting
if: ${{ github.event_name == 'pull_request' }}
strategy:
matrix:
os: [ubuntu-latest]
scala: [2.13.10]
java: [temurin@11]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- uses: coursier/setup-action@v1

- name: Check Formatting
run: sbt scalafmtCheckAll
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,4 @@ build/
### Mac OS ###
.DS_Store
tmp
/output/*
4 changes: 4 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FROM eclipse-temurin:17.0.13_11-jre-noble
WORKDIR .
COPY ./output/mock-server.jar ./mock-server.jar
CMD java -jar mock-server.jar
141 changes: 125 additions & 16 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,13 +1,39 @@
import sbt.url
import sbtghactions.GenerativePlugin.autoImport.{
githubWorkflowPublish,
githubWorkflowPublishTargetBranches,
JavaSpec
}
import scala.collection.Seq
import xerial.sbt.Sonatype.sonatypeCentralHost

addCommandAlias("fmt", "scalafmtAll; scalafmtSbt")
addCommandAlias("fmt", "scalafmtAll; scalafmtSbt; mock_server/scalafmtAll")
addCommandAlias("it", "integration_test/test")
addCommandAlias("compileAll", "+compile; integration_test/test:compile; mock_server/compile")
addCommandAlias(
"mimaChecks",
"core/mimaReportBinaryIssues; requests/mimaReportBinaryIssues; sttp_core/mimaReportBinaryIssues; upickle/mimaReportBinaryIssues; zio_json/mimaReportBinaryIssues"
)

val globals = new {
val projectName = "sonatype-central-client"
val organizationName = "com.lumidion"
}

val versions = new {
val scala212 = "2.12.19"
val scala213 = "2.13.14"
val scala3 = "3.3.3"
val sttp = "4.0.0-M16"
val scalatest = "3.2.19"
val zioHttp = "3.0.1"
val zioJson = "0.7.2"
val requests = "0.9.0"
val upickle = "3.3.1"
}

lazy val crossScalaVersionsGlobal = Seq(versions.scala212, versions.scala213, versions.scala3)

inThisBuild(
List(
name := globals.projectName,
Expand All @@ -23,23 +49,81 @@ inThisBuild(
)
),
scalacOptions ++= Seq("-feature"),
versionScheme := Some("semver-spec")
versionScheme := Some("semver-spec"),
sonatypeCredentialHost := sonatypeCentralHost,
githubWorkflowJavaVersions := Seq(
JavaSpec.temurin("8"),
JavaSpec.temurin("11")
),
githubWorkflowScalaVersions := crossScalaVersionsGlobal,
githubWorkflowAddedJobs ++= Seq(
WorkflowJob(
id = "mima_check",
name = "Mima Check",
steps = List(
WorkflowStep.Use(UseRef.Public("actions", "checkout", "v4"), Map("fetch-depth" -> "0")),
WorkflowStep.Use(UseRef.Public("coursier", "setup-action", "v1"))
) ++ WorkflowStep.SetupJava(List(JavaSpec.temurin("21"))) :+ WorkflowStep.Sbt(
List("mimaChecks")
),
cond = Option("${{ github.event_name == 'pull_request' }}"),
javas = List(JavaSpec.temurin("21"))
),
WorkflowJob(
"check",
"Check Formatting",
List(
WorkflowStep.Use(UseRef.Public("actions", "checkout", "v4"), Map("fetch-depth" -> "0")),
WorkflowStep.Use(UseRef.Public("coursier", "setup-action", "v1")),
WorkflowStep.Sbt(
name = Some("Check Formatting"),
commands = List(s"scalafmtCheckAll")
)
),
javas = List(
JavaSpec.temurin("11")
),
cond = Option("${{ github.event_name == 'pull_request' }}")
)
),
githubWorkflowIncludeClean := false,
githubWorkflowArtifactUpload := false,
githubWorkflowTargetTags ++= Seq("v*"),
githubWorkflowPublishTargetBranches :=
Seq(RefPredicate.StartsWith(Ref.Tag("v"))),
githubWorkflowBuild := Seq(
WorkflowStep
.Sbt(
name = Some("Build"),
commands = List("clean", "compile", "integration_test/test:compile")
),
WorkflowStep.Run(name = Some("Start Mock Server"), commands = List("./start-mock-server.sh")),
WorkflowStep.Sbt(name = Some("Run Integration Tests"), commands = List("it"))
),
githubWorkflowTargetBranches := Seq("main"),
githubWorkflowPublish := Seq(
WorkflowStep.Sbt(
commands = List("ci-release"),
name = Some("Publish project"),
env = Map(
"PGP_PASSPHRASE" -> "${{ secrets.PGP_PASSPHRASE }}",
"PGP_SECRET" -> "${{ secrets.PGP_SECRET }}",
"SONATYPE_PASSWORD" -> "${{ secrets.SONATYPE_PASSWORD }}",
"SONATYPE_USERNAME" -> "${{ secrets.SONATYPE_USERNAME }}"
)
)
)
)
)

val versions = new {
val scala212 = "2.12.19"
val scala213 = "2.13.13"
val scala3 = "3.3.3"
val sttp = "4.0.0-M16"
val scalatest = "3.2.19"
val zioJson = "0.7.1"
val requests = "0.8.2"
val upickle = "3.3.1"
}
val mimaSettings = Seq(
mimaPreviousArtifacts ++= previousStableVersion.value
.map(organization.value %% name.value % _)
.toSet
)

val commonSettings = Seq(
crossScalaVersions := Seq(versions.scala212, versions.scala213, versions.scala3),
crossScalaVersions := crossScalaVersionsGlobal,
scalacOptions ++= {
if (scalaVersion.value == versions.scala3) {
Seq(
Expand All @@ -48,14 +132,14 @@ val commonSettings = Seq(
"-deprecation"
)
} else Seq.empty
},
publishTo := sonatypeCentralPublishToBundle.value
}
)

lazy val core = (project in file("modules/core"))
.settings(
name := s"${globals.projectName}-core"
)
.settings(mimaSettings)
.settings(commonSettings)

lazy val requests = (project in file("modules/requests"))
Expand All @@ -65,6 +149,7 @@ lazy val requests = (project in file("modules/requests"))
"com.lihaoyi" %% "requests" % versions.requests
)
)
.settings(mimaSettings)
.settings(commonSettings)
.dependsOn(core, upickle)

Expand All @@ -75,6 +160,7 @@ lazy val sttp_core = (project in file("modules/sttp-core"))
"com.softwaremill.sttp.client4" %% "core" % versions.sttp
)
)
.settings(mimaSettings)
.settings(commonSettings)
.dependsOn(core)

Expand All @@ -85,6 +171,7 @@ lazy val upickle = (project in file("modules/upickle"))
"com.lihaoyi" %% "upickle" % versions.upickle
)
)
.settings(mimaSettings)
.settings(commonSettings)
.dependsOn(core)

Expand All @@ -95,6 +182,7 @@ lazy val zio_json = (project in file("modules/zio-json"))
"dev.zio" %% "zio-json" % versions.zioJson
)
)
.settings(mimaSettings)
.settings(commonSettings)
.dependsOn(sttp_core)

Expand All @@ -107,11 +195,32 @@ lazy val integration_test = (project in file("modules/integration-test"))
"com.softwaremill.sttp.client4" %% "zio-json" % versions.sttp % Test
)
)
.settings(commonSettings)
.dependsOn(requests, sttp_core, zio_json)

lazy val mock_server = (project in file("modules/mock-server"))
.settings(
assembly / assemblyJarName := "mock-server.jar",
assembly / target := file("./output"),
ThisBuild / assemblyMergeStrategy := {
case PathList("META-INF", "io.netty.versions.properties") => MergeStrategy.first
case x =>
val oldStrategy = (ThisBuild / assemblyMergeStrategy).value
oldStrategy(x)
},
crossScalaVersions := Seq(versions.scala3),
publish / skip := true,
name := "mock-server",
libraryDependencies ++= Seq(
"dev.zio" %% "zio-http" % versions.zioHttp
)
)
.settings(commonSettings)
.dependsOn(core, zio_json)

lazy val root = (project in file("."))
.settings(
publish / skip := true,
name := globals.projectName
)
.aggregate(core, requests, upickle, sttp_core, zio_json)
.aggregate(core, requests, upickle, sttp_core, zio_json, integration_test)
7 changes: 7 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
services:
mock-server:
container_name: sonatype-central-mock-server
ports:
- 8080:8080
build:
context: '.'
Loading
Loading