Skip to content

Commit 2348e8e

Browse files
authored
Merge pull request #13 from phelps-sg/continuous_integration
install github action to build and test on commit
2 parents ee571e0 + 4f7005f commit 2348e8e

File tree

5 files changed

+201
-6
lines changed

5 files changed

+201
-6
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
# Continuous Integration (CI) to Build & Test & Coverage & Lint.
2+
# ~~
3+
name: CI
4+
on:
5+
pull_request:
6+
branches: [ main, '**' ]
7+
push:
8+
branches: [ main ]
9+
10+
jobs:
11+
validate:
12+
name: Validate Code
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v3
16+
17+
- name: Setup JDK
18+
uses: actions/setup-java@v3
19+
with:
20+
distribution: corretto
21+
java-version: '11'
22+
cache: 'sbt'
23+
24+
- name: Validate Code
25+
run: sbt validateCode
26+
27+
build:
28+
name: Build & Test
29+
needs: [ validate ]
30+
runs-on: ubuntu-latest
31+
32+
strategy:
33+
fail-fast: true
34+
matrix:
35+
scala: [ '2.12.15', '2.13.10', '3.2.2' ]
36+
37+
steps:
38+
- uses: actions/checkout@v3
39+
40+
- name: Setup JDK
41+
uses: actions/setup-java@v3
42+
with:
43+
distribution: 'corretto'
44+
java-version: '8'
45+
cache: 'sbt'
46+
47+
- name: Build & Test
48+
run: sbt ++${{ matrix.scala }} testWithCoverage
49+
50+
- name: Upload coverage report (Cobertura)
51+
uses: actions/[email protected]
52+
with:
53+
name: cobertura.xml
54+
path: ${{github.workspace}}/target/scala-2.13/coverage-report/cobertura.xml
55+
56+
- name: Upload coverage report (HTML)
57+
uses: actions/[email protected]
58+
with:
59+
name: scoverage-report-html
60+
path: ${{github.workspace}}/target/scala-2.13/scoverage-report/
61+
62+
optional-build:
63+
name: Build (Optional)
64+
continue-on-error: ${{ matrix.experimental }}
65+
needs: [ validate ]
66+
runs-on: ubuntu-latest
67+
68+
strategy:
69+
fail-fast: true
70+
matrix:
71+
distribution: [ 'corretto' ]
72+
jdk: [ '11' ]
73+
scala: [ '2.12.15', '2.13.10', '3.2.2' ]
74+
experimental: [ false ]
75+
include:
76+
- jdk: '17'
77+
distribution: 'corretto'
78+
scala: '2.13.10'
79+
experimental: true
80+
81+
steps:
82+
- name: Checkout repository
83+
uses: actions/checkout@v3
84+
85+
- name: Setup JDK
86+
uses: actions/setup-java@v3
87+
with:
88+
distribution: ${{ matrix.distribution }}
89+
java-version: ${{ matrix.jdk }}
90+
cache: 'sbt'
91+
92+
- name: Perform Build / Test
93+
run: sbt ++${{ matrix.scala }} compile test
94+
95+
coverage:
96+
name: Coverage Report
97+
if: ${{ github.event.pull_request }}
98+
needs: [ build ]
99+
runs-on: ubuntu-latest
100+
steps:
101+
- uses: actions/download-artifact@v3
102+
with:
103+
name: cobertura.xml
104+
105+
- name: Analyzing coverage report
106+
uses: 5monkeys/cobertura-action@master
107+
with:
108+
path: cobertura.xml
109+
only_changed_files: true
110+
fail_below_threshold: true
111+
show_missing: true
112+
show_line: true
113+
show_branch: true
114+
show_class_names: true
115+
link_missing_lines: true
116+
minimum_coverage: 75
117+
118+
ready-to-merge:
119+
name: Ready to Merge
120+
if: ${{ github.event.pull_request }}
121+
needs: [ optional-build, coverage ]
122+
runs-on: ubuntu-latest
123+
steps:
124+
- run: echo 'Ready to merge.'

.scalafix.conf

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
rules = [
2+
DisableSyntax,
3+
ExplicitResultTypes,
4+
LeakingImplicitClassVal,
5+
NoAutoTupling,
6+
NoValInForComprehension,
7+
ProcedureSyntax,
8+
RedundantSyntax,
9+
RemoveUnused
10+
]

.scalafmt.conf

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
version = 3.7.4
2+
runner.dialect = scala213

build.sbt

+55-5
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,27 @@ lazy val guice = (project in file("openai-guice"))
2424
.dependsOn(client)
2525
.aggregate(client_stream)
2626

27-
2827
// POM settings for Sonatype
29-
ThisBuild / homepage := Some(url("https://github.com/cequence-io/openai-scala-client"))
28+
ThisBuild / homepage := Some(
29+
url("https://github.com/cequence-io/openai-scala-client")
30+
)
3031

3132
ThisBuild / sonatypeProfileName := "io.cequence"
3233

33-
ThisBuild / scmInfo := Some(ScmInfo(url("https://github.com/cequence-io/openai-scala-client"), "scm:[email protected]:cequence-io/openai-scala-client.git"))
34+
ThisBuild / scmInfo := Some(
35+
ScmInfo(
36+
url("https://github.com/cequence-io/openai-scala-client"),
37+
"scm:[email protected]:cequence-io/openai-scala-client.git"
38+
)
39+
)
3440

3541
ThisBuild / developers := List(
36-
Developer("bnd", "Peter Banda", "[email protected]", url("https://peterbanda.net"))
42+
Developer(
43+
"bnd",
44+
"Peter Banda",
45+
46+
url("https://peterbanda.net")
47+
)
3748
)
3849

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

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

47-
ThisBuild / publishTo := sonatypePublishToBundle.value
58+
ThisBuild / publishTo := sonatypePublishToBundle.value
59+
60+
addCommandAlias(
61+
"validateCode",
62+
List(
63+
"scalafix",
64+
"scalafmtSbtCheck",
65+
"scalafmtCheckAll",
66+
"test:scalafix",
67+
"test:scalafmtCheckAll"
68+
).mkString(";")
69+
)
70+
71+
addCommandAlias(
72+
"formatCode",
73+
List(
74+
"scalafmt",
75+
"scalafmtSbt",
76+
"Test/scalafmt"
77+
).mkString(";")
78+
)
79+
80+
addCommandAlias(
81+
"testWithCoverage",
82+
List(
83+
"coverage",
84+
"test",
85+
"coverageReport"
86+
).mkString(";")
87+
)
88+
89+
90+
inThisBuild(
91+
List(
92+
scalacOptions += "-Ywarn-unused",
93+
scalaVersion := "2.12.15",
94+
semanticdbEnabled := true,
95+
semanticdbVersion := scalafixSemanticdb.revision
96+
)
97+
)

project/plugins.sbt

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
11
logLevel := Level.Warn
22

33
addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "3.9.15")
4-
addSbtPlugin("com.github.sbt" % "sbt-pgp" % "2.1.2")
4+
addSbtPlugin("com.github.sbt" % "sbt-pgp" % "2.1.2")
5+
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.11.0")
6+
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.0")
7+
8+
9+
// Test Coverage plugin.
10+
// ~
11+
// sbt-scoverage is a plugin for SBT that integrates the scoverage code coverage library.
12+
// See more: https://github.com/scoverage/sbt-scoverage
13+
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "2.0.8")

0 commit comments

Comments
 (0)