Skip to content

Commit e5c9bfb

Browse files
authored
Pass & Filter pattern (sbt#1323)
Filter pattern in GlobalBenchmarkSetup Test that -Dbenchmark.pattern works in CI Pass pattern to GlobalBenchmarkSetup Run benchmarks in parallel Renaming job names
1 parent e3ccfde commit e5c9bfb

File tree

3 files changed

+37
-19
lines changed

3 files changed

+37
-19
lines changed

.github/workflows/ci.yml

+23-9
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ jobs:
2727
- os: ubuntu-latest
2828
java: 21
2929
jobtype: 4
30+
- os: ubuntu-latest
31+
java: 21
32+
jobtype: 5
3033
runs-on: ${{ matrix.os }}
3134
steps:
3235
- name: Checkout
@@ -50,20 +53,31 @@ jobs:
5053
if: ${{ matrix.jobtype == 3 }}
5154
shell: bash
5255
run: |
53-
sbt -v -Dfile.encoding=UTF-8 "runBenchmarks"
54-
- name: Checkout Develop Branch (3)
55-
if: ${{ github.event_name == 'pull_request' && matrix.jobtype == 3 }}
56+
sbt -v -Dfile.encoding=UTF-8 scalafmtCheckAll scalafmtSbtCheck
57+
- name: Benchmark (Scalac) (4)
58+
if: ${{ matrix.jobtype == 4 }}
59+
shell: bash
60+
run: |
61+
sbt -v -Dfile.encoding=UTF-8 "-Dbenchmark.pattern=.*Scalac.*" "runBenchmarks"
62+
- name: Benchmark (Shapeless) (5)
63+
if: ${{ matrix.jobtype == 5 }}
64+
shell: bash
65+
run: |
66+
sbt -v -Dfile.encoding=UTF-8 "-Dbenchmark.pattern=.*Shapeless.*" "runBenchmarks"
67+
- name: Checkout Develop Branch (4, 5)
68+
if: ${{ github.event_name == 'pull_request' && (matrix.jobtype == 4 || matrix.jobtype == 5) }}
5669
uses: actions/checkout@v4
5770
with:
5871
clean: false
5972
ref: develop
60-
- name: Build and test against Develop Branch (3)
61-
if: ${{ github.event_name == 'pull_request' && matrix.jobtype == 3 }}
73+
- name: Benchmark (Scalac) against Develop Branch (4)
74+
if: ${{ github.event_name == 'pull_request' && matrix.jobtype == 4 }}
6275
shell: bash
6376
run: |
64-
sbt -v -Dfile.encoding=UTF-8 "runBenchmarks"
65-
- name: Build and test (4)
66-
if: ${{ matrix.jobtype == 4 }}
77+
sbt -v -Dfile.encoding=UTF-8 "-Dbenchmark.pattern=.*Scalac.*" "runBenchmarks"
78+
- name: Benchmark (Shapeless) against Develop Branch (5)
79+
if: ${{ github.event_name == 'pull_request' && matrix.jobtype == 5 }}
6780
shell: bash
6881
run: |
69-
sbt -v -Dfile.encoding=UTF-8 scalafmtCheckAll scalafmtSbtCheck
82+
sbt -v -Dfile.encoding=UTF-8 "-Dbenchmark.pattern=.*Shapeless.*" "runBenchmarks"
83+

build.sbt

+3-2
Original file line numberDiff line numberDiff line change
@@ -697,11 +697,12 @@ crossTestBridges := (compilerBridgeTest.jvm(scala213) / Test / test).dependsOn(p
697697
addCommandAlias(
698698
"runBenchmarks", {
699699
val dir = IO.createTemporaryDirectory.getAbsolutePath
700+
val pattern = sys.props.getOrElse("benchmark.pattern", "")
700701
Seq(
701702
s"${compilerBridge213.id}/packageBin",
702703
s"${compilerBridge212.id}/packageBin",
703-
s"${zincBenchmarks.jvm(scala212).id}/Test/run $dir",
704-
s"${zincBenchmarks.jvm(scala212).id}/jmh:run -p _tempDir=$dir -prof gc -foe true",
704+
s"${zincBenchmarks.jvm(scala212).id}/Test/run $dir $pattern",
705+
s"${zincBenchmarks.jvm(scala212).id}/jmh:run -p _tempDir=$dir -prof gc -foe true $pattern",
705706
s"""eval IO.delete(file("$dir"))""",
706707
).mkString(";", ";", "")
707708
}

internal/zinc-benchmarks/src/test/scala/xsbt/GlobalBenchmarkSetup.scala

+11-8
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,15 @@ import xsbt.BenchmarkProjects.{ Scalac, Shapeless }
1818
object GlobalBenchmarkSetup {
1919

2020
/** Update this list every time you add a new benchmark. */
21-
val projects = List(Scalac, Shapeless)
21+
val projects = Map("Scalac" -> Scalac, "Shapeless" -> Shapeless)
2222

23-
def runSetup(setupDir: File): (Int, String) = {
24-
val projectsPreparation = projects.map { project =>
25-
val benchmark = new ZincBenchmark(project)
26-
project -> benchmark.writeSetup(new File(setupDir, project.repo))
27-
}
23+
def runSetup(setupDir: File, pattern: String): (Int, String) = {
24+
val projectsPreparation = projects
25+
.filterKeys { _.matches(pattern) }
26+
.map { case (_, project) =>
27+
val benchmark = new ZincBenchmark(project)
28+
project -> benchmark.writeSetup(new File(setupDir, project.repo))
29+
}
2830

2931
val failedToPrepare = projectsPreparation.filter(_._2.isLeft)
3032
if (failedToPrepare.isEmpty)
@@ -43,11 +45,12 @@ object GlobalBenchmarkSetup {
4345

4446
if (args.isEmpty)
4547
fail("Missing directory to host project setups.")
46-
else if (args.length > 1)
48+
else if (args.length > 2)
4749
fail("Too many arguments. Pass the directory to host project setups.")
4850
else {
4951
val setupDir = new File(args(0))
50-
val (exitCode, status) = runSetup(setupDir)
52+
val pattern = if (args.length == 1) ".*" else args(1)
53+
val (exitCode, status) = runSetup(setupDir, pattern)
5154
println(status)
5255
println("The benchmark setup has finished.")
5356
System.exit(exitCode)

0 commit comments

Comments
 (0)