Skip to content
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

Use actions/setup-java caching abilities #1088

Merged
merged 1 commit into from Jun 28, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -47,7 +47,7 @@ jobs:
- name: Checkout
uses: actions/checkout@v2
- name: Setup JDK
uses: actions/setup-java@v2
uses: actions/setup-java@v3
with:
distribution: temurin
java-version: 8
Expand Down Expand Up @@ -89,7 +89,7 @@ jobs:
- name: Checkout
uses: actions/checkout@v2
- name: Setup JDK
uses: actions/setup-java@v2
uses: actions/setup-java@v3
with:
distribution: temurin
java-version: 8
Expand Down Expand Up @@ -117,24 +117,24 @@ java

You can speed up your `sbt` builds on GitHub Actions by caching various artifacts in-between the jobs.

Here are sample caching steps that you can use:
The action `setup-java` has built-in support for caching artifacts downloaded by
sbt when loading the build or when building the project.

To use it, set the input parameter `cache` of the action `setup-java` to the value `"sbt"`:

```yml
- name: Coursier cache
uses: coursier/cache-action@v6
- name: Setup JDK
uses: actions/setup-java@v3
with:
distribution: temurin
java-version: 8
cache: sbt
- name: Build and test
run: sbt -v +test
- name: Cleanup before cache
shell: bash
run: |
rm -rf "\$HOME/.ivy2/local" || true
find \$HOME/Library/Caches/Coursier/v1 -name "ivydata-*.properties" -delete || true
find \$HOME/.ivy2/cache -name "ivydata-*.properties" -delete || true
find \$HOME/.cache/coursier/v1 -name "ivydata-*.properties" -delete || true
find \$HOME/.sbt -name "*.lock" -delete || true
```

With the above changes combined GitHub Actions will tar up the cached directories and uploads them to a cloud storage provider.
Note the added line `cache: sbt`.

Overall, the use of caching should shave off a few minutes of build time per job.

### Build matrix
Expand Down Expand Up @@ -170,7 +170,7 @@ jobs:
- name: Checkout
uses: actions/checkout@v2
- name: Setup JDK
uses: actions/setup-java@v2
uses: actions/setup-java@v3
with:
distribution: temurin
java-version: \${{ matrix.java }}
Expand Down Expand Up @@ -210,7 +210,7 @@ jobs:
- name: Checkout
uses: actions/checkout@v2
- name: Setup JDK
uses: actions/setup-java@v2
uses: actions/setup-java@v3
with:
distribution: temurin
java-version: \${{ matrix.java }}
Expand Down Expand Up @@ -267,12 +267,11 @@ jobs:
- name: Checkout
uses: actions/checkout@v2
- name: Setup JDK
uses: actions/setup-java@v2
uses: actions/setup-java@v3
with:
distribution: temurin
java-version: \${{ matrix.java }}
- name: Coursier cache
uses: coursier/cache-action@v6
cache: sbt
- name: Build and test (1)
if: \${{ matrix.jobtype == 1 }}
shell: bash
Expand All @@ -288,14 +287,6 @@ jobs:
shell: bash
run: |
sbt -v "dependency-management/*"
- name: Cleanup before cache
shell: bash
run: |
rm -rf "\$HOME/.ivy2/local" || true
find \$HOME/Library/Caches/Coursier/v1 -name "ivydata-*.properties" -delete || true
find \$HOME/.ivy2/cache -name "ivydata-*.properties" -delete || true
find \$HOME/.cache/coursier/v1 -name "ivydata-*.properties" -delete || true
find \$HOME/.sbt -name "*.lock" -delete || true
```

### sbt-github-actions
Expand Down