Skip to content

install github action to build and test on commit #13

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

Merged
merged 9 commits into from
Jun 15, 2023
124 changes: 124 additions & 0 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
# Continuous Integration (CI) to Build & Test & Coverage & Lint.
# ~~
name: CI
on:
pull_request:
branches: [ main, '**' ]
push:
branches: [ main ]

jobs:
validate:
name: Validate Code
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Setup JDK
uses: actions/setup-java@v3
with:
distribution: corretto
java-version: '11'
cache: 'sbt'

- name: Validate Code
run: sbt validateCode

build:
name: Build & Test
needs: [ validate ]
runs-on: ubuntu-latest

strategy:
fail-fast: true
matrix:
scala: [ '2.12.15', '2.13.10', '3.2.2' ]

steps:
- uses: actions/checkout@v3

- name: Setup JDK
uses: actions/setup-java@v3
with:
distribution: 'corretto'
java-version: '8'
cache: 'sbt'

- name: Build & Test
run: sbt ++${{ matrix.scala }} testWithCoverage

- name: Upload coverage report (Cobertura)
uses: actions/[email protected]
with:
name: cobertura.xml
path: ${{github.workspace}}/target/scala-2.13/coverage-report/cobertura.xml

- name: Upload coverage report (HTML)
uses: actions/[email protected]
with:
name: scoverage-report-html
path: ${{github.workspace}}/target/scala-2.13/scoverage-report/

optional-build:
name: Build (Optional)
continue-on-error: ${{ matrix.experimental }}
needs: [ validate ]
runs-on: ubuntu-latest

strategy:
fail-fast: true
matrix:
distribution: [ 'corretto' ]
jdk: [ '11' ]
scala: [ '2.12.15', '2.13.10', '3.2.2' ]
experimental: [ false ]
include:
- jdk: '17'
distribution: 'corretto'
scala: '2.13.10'
experimental: true

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Setup JDK
uses: actions/setup-java@v3
with:
distribution: ${{ matrix.distribution }}
java-version: ${{ matrix.jdk }}
cache: 'sbt'

- name: Perform Build / Test
run: sbt ++${{ matrix.scala }} compile test

coverage:
name: Coverage Report
if: ${{ github.event.pull_request }}
needs: [ build ]
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v3
with:
name: cobertura.xml

- name: Analyzing coverage report
uses: 5monkeys/cobertura-action@master
with:
path: cobertura.xml
only_changed_files: true
fail_below_threshold: true
show_missing: true
show_line: true
show_branch: true
show_class_names: true
link_missing_lines: true
minimum_coverage: 75

ready-to-merge:
name: Ready to Merge
if: ${{ github.event.pull_request }}
needs: [ optional-build, coverage ]
runs-on: ubuntu-latest
steps:
- run: echo 'Ready to merge.'
10 changes: 10 additions & 0 deletions .scalafix.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
rules = [
DisableSyntax,
ExplicitResultTypes,
LeakingImplicitClassVal,
NoAutoTupling,
NoValInForComprehension,
ProcedureSyntax,
RedundantSyntax,
RemoveUnused
]
2 changes: 2 additions & 0 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
version = 3.7.4
runner.dialect = scala213
60 changes: 55 additions & 5 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,27 @@ lazy val guice = (project in file("openai-guice"))
.dependsOn(client)
.aggregate(client_stream)


// POM settings for Sonatype
ThisBuild / homepage := Some(url("https://github.com/cequence-io/openai-scala-client"))
ThisBuild / homepage := Some(
url("https://github.com/cequence-io/openai-scala-client")
)

ThisBuild / sonatypeProfileName := "io.cequence"

ThisBuild / scmInfo := Some(ScmInfo(url("https://github.com/cequence-io/openai-scala-client"), "scm:[email protected]:cequence-io/openai-scala-client.git"))
ThisBuild / scmInfo := Some(
ScmInfo(
url("https://github.com/cequence-io/openai-scala-client"),
"scm:[email protected]:cequence-io/openai-scala-client.git"
)
)

ThisBuild / developers := List(
Developer("bnd", "Peter Banda", "[email protected]", url("https://peterbanda.net"))
Developer(
"bnd",
"Peter Banda",
"[email protected]",
url("https://peterbanda.net")
)
)

ThisBuild / licenses += "MIT" -> url("https://opensource.org/licenses/MIT")
Expand All @@ -44,4 +55,43 @@ ThisBuild / sonatypeCredentialHost := "s01.oss.sonatype.org"

ThisBuild / sonatypeRepository := "https://s01.oss.sonatype.org/service/local"

ThisBuild / publishTo := sonatypePublishToBundle.value
ThisBuild / publishTo := sonatypePublishToBundle.value

addCommandAlias(
"validateCode",
List(
"scalafix",
"scalafmtSbtCheck",
"scalafmtCheckAll",
"test:scalafix",
"test:scalafmtCheckAll"
).mkString(";")
)

addCommandAlias(
"formatCode",
List(
"scalafmt",
"scalafmtSbt",
"Test/scalafmt"
).mkString(";")
)

addCommandAlias(
"testWithCoverage",
List(
"coverage",
"test",
"coverageReport"
).mkString(";")
)


inThisBuild(
List(
scalacOptions += "-Ywarn-unused",
scalaVersion := "2.12.15",
semanticdbEnabled := true,
semanticdbVersion := scalafixSemanticdb.revision
)
)
11 changes: 10 additions & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
logLevel := Level.Warn

addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "3.9.15")
addSbtPlugin("com.github.sbt" % "sbt-pgp" % "2.1.2")
addSbtPlugin("com.github.sbt" % "sbt-pgp" % "2.1.2")
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.11.0")
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.0")


// Test Coverage plugin.
// ~
// sbt-scoverage is a plugin for SBT that integrates the scoverage code coverage library.
// See more: https://github.com/scoverage/sbt-scoverage
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "2.0.8")