Skip to content

Commit c2e87a7

Browse files
committed
Fix examples, build them as part of CI
1 parent 23a6bfc commit c2e87a7

File tree

10 files changed

+111
-33
lines changed

10 files changed

+111
-33
lines changed

.github/labeler.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
version: 1
22
labels:
33
- label: "automerge"
4-
authors: ["softwaremill-cisoftwaremill-ci"]
4+
authors: ["softwaremill-ci"]
55
files:
66
- "build.sbt"
77
- "project/build.properties"
88
- "project/Versions.scala"
99
- "project/plugins.sbt"
1010
- label: "dependency"
11-
authors: ["softwaremill-cisoftwaremill-ci"]
11+
authors: ["softwaremill-ci"]
1212
files:
1313
- "build.sbt"
1414
- "project/build.properties"

.github/workflows/ci.yml

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,42 @@ permissions:
1010
pull-requests: write # labeler, auto-merge requirement
1111
jobs:
1212
build:
13-
uses: softwaremill/github-actions-workflows/.github/workflows/build-scala.yml@main
14-
# run on 1) push, 2) external PRs, 3) softwaremill-cisoftwaremill-ci PRs
13+
# run on 1) push, 2) external PRs, 3) softwaremill-ci PRs
1514
# do not run on internal, non-steward PRs since those will be run by push to branch
1615
if: |
1716
github.event_name == 'push' ||
1817
github.event.pull_request.head.repo.full_name != github.repository ||
19-
github.event.pull_request.user.login == 'softwaremill-cisoftwaremill-ci'
20-
with:
21-
java-opts: '-Xmx4G'
18+
github.event.pull_request.user.login == 'softwaremill-ci'
19+
runs-on: ubuntu-24.04
20+
env:
21+
JAVA_OPTS: '-Xmx4G'
22+
steps:
23+
- name: Checkout
24+
uses: actions/checkout@v6
25+
- name: Set up JDK
26+
uses: actions/setup-java@v5
27+
with:
28+
distribution: 'temurin'
29+
java-version: 11
30+
cache: 'sbt'
31+
- uses: sbt/setup-sbt@3e125ece5c3e5248e18da9ed8d2cce3d335ec8dd # v1, specifically v1.1.14
32+
- name: Install scala-cli
33+
uses: VirtusLab/scala-cli-setup@68bd9c30954d20e6cb6ddaf01b3b38336f25df4b # main, specifically v1.10.1
34+
with:
35+
jvm: '' # needed because scala-cli-setup otherwise forces the installation of their default JVM (17)
36+
- name: Check formatting
37+
run: sbt -v scalafmtCheckAll
38+
- name: Compile
39+
run: sbt -v compile
40+
- name: Verify that examples compile using Scala CLI
41+
run: sbt -v "project examples" verifyExamplesCompileUsingScalaCli
42+
- name: Test
43+
run: sbt -v test
44+
- uses: actions/upload-artifact@v5 # upload test results
45+
if: success() || failure() # run this step even if previous step failed
46+
with:
47+
name: 'tests-results'
48+
path: '**/test-reports/TEST*.xml'
2249

2350
publish:
2451
uses: softwaremill/github-actions-workflows/.github/workflows/publish-release.yml@main
@@ -30,14 +57,14 @@ jobs:
3057
sttp-native: 1
3158

3259
label:
33-
# only for PRs by softwaremill-cisoftwaremill-ci
34-
if: github.event.pull_request.user.login == 'softwaremill-cisoftwaremill-ci'
60+
# only for PRs by
61+
if: github.event.pull_request.user.login == 'softwaremill-ci'
3562
uses: softwaremill/github-actions-workflows/.github/workflows/label.yml@main
3663
secrets: inherit
3764

3865
auto-merge:
39-
# only for PRs by softwaremill-cisoftwaremill-ci
40-
if: github.event.pull_request.user.login == 'softwaremill-cisoftwaremill-ci'
66+
# only for PRs by softwaremill-ci
67+
if: github.event.pull_request.user.login == 'softwaremill-ci'
4168
needs: [ build, label ]
4269
uses: softwaremill/github-actions-workflows/.github/workflows/auto-merge.yml@main
4370
secrets: inherit

build.sbt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ val scalaTestV = "3.2.19"
77
val circeV = "0.14.15"
88
val tapirV = "1.13.0"
99

10+
lazy val verifyExamplesCompileUsingScalaCli = taskKey[Unit]("Verify that each example compiles using Scala CLI")
11+
1012
lazy val commonSettings = commonSmlBuildSettings ++ ossPublishSettings ++ Seq(
1113
organization := "com.softwaremill.chimp",
1214
scalaVersion := "3.3.7",
@@ -54,6 +56,7 @@ lazy val examples = (project in file("examples"))
5456
"com.softwaremill.sttp.client4" %% "core" % "4.0.13",
5557
"com.softwaremill.sttp.tapir" %% "tapir-netty-server-sync" % tapirV,
5658
"ch.qos.logback" % "logback-classic" % "1.5.20"
57-
)
59+
),
60+
verifyExamplesCompileUsingScalaCli := VerifyExamplesCompileUsingScalaCli(sLog.value, sourceDirectory.value)
5861
)
5962
.dependsOn(core)

examples/src/main/scala/chimp/AdderMcpZio.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
package chimp
2-
3-
//> using dep com.softwaremill.chimp::core:0.1.2
1+
//> using dep com.softwaremill.chimp::core:0.1.6
42
//> using dep com.softwaremill.sttp.tapir::tapir-zio-http-server:1.11.33
5-
//> using dep ch.qos.logback::logback-classic:1.5.18
3+
//> using dep ch.qos.logback:logback-classic:1.5.20
4+
5+
package chimp
66

77
import io.circe.Codec
88
import sttp.tapir.*

examples/src/main/scala/chimp/adderMcp.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
package chimp
2-
3-
//> using dep com.softwaremill.chimp::core:0.1.2
1+
//> using dep com.softwaremill.chimp::core:0.1.6
42
//> using dep com.softwaremill.sttp.tapir::tapir-netty-server-sync:1.11.33
5-
//> using dep ch.qos.logback::logback-classic:1.5.18
3+
//> using dep ch.qos.logback:logback-classic:1.5.20
4+
5+
package chimp
66

7-
import sttp.tapir.*
87
import io.circe.Codec
8+
import sttp.tapir.*
99
import sttp.tapir.server.netty.sync.NettySyncServer
1010

1111
case class Input(a: Int, b: Int) derives Codec, Schema

examples/src/main/scala/chimp/adderWithAuthMcp.scala

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
1-
package chimp
2-
3-
//> using dep com.softwaremill.chimp::core:0.1.2
1+
//> using dep com.softwaremill.chimp::core:0.1.6
42
//> using dep com.softwaremill.sttp.tapir::tapir-netty-server-sync:1.11.33
5-
//> using dep ch.qos.logback::logback-classic:1.5.18
3+
//> using dep ch.qos.logback:logback-classic:1.5.20
64

5+
package chimp
6+
7+
import io.circe.Codec
78
import sttp.model.Header
9+
import sttp.tapir.*
810
import sttp.tapir.server.netty.sync.NettySyncServer
911

1012
@main def mcpAuthApp(): Unit =
13+
case class Input(a: Int, b: Int) derives Codec, Schema
14+
1115
val adderTool = tool("adder")
1216
.description("Adds two numbers")
1317
.withAnnotations(ToolAnnotations(idempotentHint = Some(true)))

examples/src/main/scala/chimp/twoToolsMcp.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
package chimp
2-
3-
//> using dep com.softwaremill.chimp::core:0.1.2
1+
//> using dep com.softwaremill.chimp::core:0.1.6
42
//> using dep com.softwaremill.sttp.tapir::tapir-netty-server-sync:1.11.33
5-
//> using dep ch.qos.logback::logback-classic:1.5.18
3+
//> using dep ch.qos.logback:logback-classic:1.5.20
4+
5+
package chimp
66

77
import io.circe.Codec
88
import sttp.tapir.*

examples/src/main/scala/chimp/weatherMcp.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
package chimp
2-
3-
//> using dep com.softwaremill.chimp::core:0.1.2
1+
//> using dep com.softwaremill.chimp::core:0.1.6
42
//> using dep com.softwaremill.sttp.client4::core:4.0.8
53
//> using dep com.softwaremill.sttp.tapir::tapir-netty-server-sync:1.11.33
6-
//> using dep ch.qos.logback::logback-classic:1.5.18
4+
//> using dep ch.qos.logback:logback-classic:1.5.20
5+
6+
package chimp
77

88
import chimp.*
99
import io.circe.Codec

project/FileUtils.scala

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import java.io.File
2+
import java.nio.file.{FileVisitResult, Files, Path, SimpleFileVisitor}
3+
import java.nio.file.attribute.BasicFileAttributes
4+
5+
object FileUtils {
6+
def listScalaFiles(basePath: File): Seq[Path] = {
7+
val dirPath = basePath.toPath
8+
var result = Vector.empty[Path]
9+
10+
val fileVisitor = new SimpleFileVisitor[Path] {
11+
override def visitFile(file: Path, attrs: BasicFileAttributes): FileVisitResult = {
12+
if (file.toString.endsWith(".scala")) {
13+
result = result :+ file
14+
}
15+
FileVisitResult.CONTINUE
16+
}
17+
}
18+
19+
Files.walkFileTree(dirPath, fileVisitor)
20+
result
21+
}
22+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import java.io.File
2+
import sbt.Logger
3+
import scala.sys.process.{Process, ProcessLogger}
4+
5+
object VerifyExamplesCompileUsingScalaCli {
6+
def apply(log: Logger, examplesSrcPath: File): Unit = {
7+
val examples = FileUtils.listScalaFiles(examplesSrcPath)
8+
log.info(s"Found ${examples.size} examples")
9+
10+
for (example <- examples) {
11+
log.info(s"Compiling: $example")
12+
val errorOutput = new StringBuilder
13+
val logger = ProcessLogger((o: String) => (), (e: String) => errorOutput.append(e + "\n"))
14+
try {
15+
val result = Process(List("scala-cli", "compile", example.toFile.getAbsolutePath), examplesSrcPath).!(logger)
16+
if (result != 0) {
17+
throw new Exception(s"""Compiling $example failed.\n$errorOutput""".stripMargin)
18+
}
19+
} finally Process(List("scala-cli", "clean", example.toFile.getAbsolutePath), examplesSrcPath).!
20+
}
21+
}
22+
}

0 commit comments

Comments
 (0)