Skip to content

Commit 2e22282

Browse files
authored
Merge pull request #86 from sbt/wip/cache
Add disk cache
2 parents a4300e3 + fe80340 commit 2e22282

6 files changed

Lines changed: 61 additions & 12 deletions

File tree

.github/workflows/ci.yml

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,12 @@ jobs:
1212
- os: ubuntu-22.04
1313
java: 17
1414
distribution: temurin
15-
- os: ubuntu-24.04
16-
java: 8
17-
distribution: zulu
1815
- os: macos-14
19-
java: 8
16+
java: 17
2017
distribution: zulu
2118
- os: windows-2022
22-
java: 8
23-
distribution: zulu
19+
java: 17
20+
distribution: temurin
2421
runs-on: ${{ matrix.os }}
2522
env:
2623
JAVA_OPTS: -Xms2048M -Xmx2048M -Xss6M -XX:ReservedCodeCacheSize=256M -Dfile.encoding=UTF-8
@@ -33,6 +30,13 @@ jobs:
3330
java-version: ${{ matrix.java }}
3431
cache: sbt
3532
- uses: ./
36-
- name: Build and test
33+
- name: Build and test root
3734
shell: bash
3835
run: sbt -v +test
36+
- name: Build and test sbt 2
37+
shell: bash
38+
run: |
39+
pushd example
40+
sbt -v test
41+
sbt -v test
42+
popd

README.md

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@ steps:
2929

3030
### Setting the runner version
3131

32-
The `sbt` runner (Bash script that launches sbt) is typically compatible with all modern sbt releases,
33-
you might want to pin the runner to a specific version.
32+
The `sbt` runner is typically compatible with all modern sbt releases.
33+
However, the launcher distributed by sbt 2.x will require JDK 17.
34+
35+
You can pin the `sbt` runner back to sbt 1.x to run JDK 8:
3436

3537
```yaml
3638
env:
@@ -40,12 +42,25 @@ steps:
4042
- name: Setup JDK
4143
uses: actions/setup-java@v5
4244
with:
43-
distribution: temurin
44-
java-version: 17
45+
distribution: zulu
46+
java-version: 8
4547
cache: sbt
4648
- uses: sbt/setup-sbt@v1
4749
with:
48-
sbt-runner-version: 1.9.9
50+
sbt-runner-version: 1.12.11
51+
- name: Build and test
52+
shell: bash
53+
run: sbt -v +test
54+
```
55+
56+
### Opting out of disk cache
57+
58+
By default setup-sbt enables the disk cache on sbt 2.x. This can be opted out as follows:
59+
60+
```yaml
61+
- uses: sbt/setup-sbt@v1
62+
with:
63+
disk-cache: false
4964
- name: Build and test
5065
shell: bash
5166
run: sbt -v +test

action.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ inputs:
55
description: "The runner version (The actual version is controlled via project/build.properties)"
66
required: true
77
default: 1.12.11
8+
disk-cache:
9+
description: "Enable sbt 2.x disk cache"
10+
required: false
11+
default: true
812
runs:
913
using: "composite"
1014
steps:
@@ -18,11 +22,18 @@ runs:
1822
if [[ "$RUNNER_OS" == "Windows" ]]; then
1923
echo "sbt_toolpath=$RUNNER_TOOL_CACHE\\sbt\\$SBT_RUNNER_VERSION" >> "$GITHUB_OUTPUT"
2024
echo "sbt_downloadpath=$RUNNER_TEMP\\_sbt" >> "$GITHUB_OUTPUT"
25+
echo "sbt_diskcache=$HOME\\AppData\\Local\\sbt" >> "$GITHUB_OUTPUT"
26+
elif [[ "$RUNNER_OS" == "macOS" ]]; then
27+
echo "sbt_toolpath=$RUNNER_TOOL_CACHE/sbt/$SBT_RUNNER_VERSION" >> "$GITHUB_OUTPUT"
28+
echo "sbt_downloadpath=$RUNNER_TEMP/_sbt" >> "$GITHUB_OUTPUT"
29+
echo "sbt_diskcache=$HOME/Library/Caches/sbt" >> "$GITHUB_OUTPUT"
2130
else
2231
echo "sbt_toolpath=$RUNNER_TOOL_CACHE/sbt/$SBT_RUNNER_VERSION" >> "$GITHUB_OUTPUT"
2332
echo "sbt_downloadpath=$RUNNER_TEMP/_sbt" >> "$GITHUB_OUTPUT"
33+
echo "sbt_diskcache=$HOME/.cache/sbt" >> "$GITHUB_OUTPUT"
2434
fi
2535
echo "sbt_cachekey=$RUNNER_OS-sbt-$SBT_RUNNER_VERSION-$SBT_CACHE_KEY_VERSION" >> "$GITHUB_OUTPUT"
36+
echo "sbt_diskcachekey=$RUNNER_OS-sbt-diskcache-$SBT_CACHE_KEY_VERSION" >> "$GITHUB_OUTPUT"
2637
- name: Check Tool Cache
2738
id: cache-tool-dir
2839
shell: bash
@@ -42,6 +53,13 @@ runs:
4253
with:
4354
path: ${{ steps.cache-paths.outputs.sbt_toolpath }}
4455
key: ${{ steps.cache-paths.outputs.sbt_cachekey }}
56+
- name: sbt 2.x disk cache
57+
id: disk-cache
58+
if: inputs.disk-cache == 'true'
59+
uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
60+
with:
61+
path: ${{ steps.cache-paths.outputs.sbt_diskcache }}
62+
key: ${{ steps.cache-paths.outputs.sbt_diskcachekey }}
4563
- name: "Download and Install sbt"
4664
shell: bash
4765
env:

example/build.sbt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
scalaVersion := "3.8.3"
2+
val munit = "org.scalameta" %% "munit" % "1.0.4"
3+
libraryDependencies += munit % Test

example/project/build.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
sbt.version=2.0.0-RC13
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package example
2+
3+
import munit.*
4+
5+
class ATest extends FunSuite:
6+
test("sum"):
7+
assert(1 + 1 == 2)
8+
end ATest

0 commit comments

Comments
 (0)