From 754319f3bbe6f040111dfed0a083dfdc03a45d0f Mon Sep 17 00:00:00 2001 From: Florian Meriaux Date: Thu, 24 Mar 2022 10:11:05 +0100 Subject: [PATCH] Add SBT in cache managers. --- README.md | 26 ++++++++++++++++++++------ src/cache.ts | 8 +++++++- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index c02eb6c9..872220da 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,7 @@ Inputs `java-version` and `distribution` are mandatory. See [Supported distribut **Eclipse Temurin** ```yaml steps: -- uses: actions/checkout@v2 +- uses: actions/checkout@v3 - uses: actions/setup-java@v2 with: distribution: 'temurin' # See 'Supported distributions' for available options @@ -36,7 +36,7 @@ steps: **Zulu OpenJDK** ```yaml steps: -- uses: actions/checkout@v2 +- uses: actions/checkout@v3 - uses: actions/setup-java@v2 with: distribution: 'zulu' # See 'Supported distributions' for available options @@ -69,13 +69,14 @@ Currently, the following distributions are supported: The action has a built-in functionality for caching and restoring dependencies. It uses [actions/cache](https://github.com/actions/cache) under hood for caching dependencies but requires less configuration settings. Supported package managers are gradle and maven. The format of the used cache key is `setup-java-${{ platform }}-${{ packageManager }}-${{ fileHash }}`, where the hash is based on the following files: - gradle: `**/*.gradle*`, `**/gradle-wrapper.properties` - maven: `**/pom.xml` +- sbt: `**/build.sbt` The cache input is optional, and caching is turned off by default. #### Caching gradle dependencies ```yaml steps: -- uses: actions/checkout@v2 +- uses: actions/checkout@v3 - uses: actions/setup-java@v2 with: distribution: 'temurin' @@ -87,7 +88,7 @@ steps: #### Caching maven dependencies ```yaml steps: -- uses: actions/checkout@v2 +- uses: actions/checkout@v3 - uses: actions/setup-java@v2 with: distribution: 'temurin' @@ -97,6 +98,19 @@ steps: run: mvn -B package --file pom.xml ``` +#### Caching sbt dependencies +```yaml +steps: +- uses: actions/checkout@v3 +- uses: actions/setup-java@v2 + with: + distribution: 'temurin' + java-version: '11' + cache: 'sbt' +- name: Build with SBT + run: sbt package +``` + ### Check latest In the basic examples above, the `check-latest` flag defaults to `false`. When set to `false`, the action tries to first resolve a version of Java from the local tool cache on the runner. If unable to find a specific version in the cache, the action will download a version of Java. Use the default or set `check-latest` to `false` if you prefer a faster more consistent setup experience that prioritizes trying to use the cached versions at the expense of newer versions sometimes being available for download. @@ -107,7 +121,7 @@ For Java distributions that are not cached on Hosted images, `check-latest` alwa ```yaml steps: -- uses: actions/checkout@v2 +- uses: actions/checkout@v3 - uses: actions/setup-java@v2 with: distribution: 'adopt' @@ -126,7 +140,7 @@ jobs: java: [ '8', '11', '13', '15' ] name: Java ${{ matrix.Java }} sample steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Setup java uses: actions/setup-java@v2 with: diff --git a/src/cache.ts b/src/cache.ts index fb97fb0b..493bf104 100644 --- a/src/cache.ts +++ b/src/cache.ts @@ -13,7 +13,7 @@ const CACHE_MATCHED_KEY = 'cache-matched-key'; const CACHE_KEY_PREFIX = 'setup-java'; interface PackageManager { - id: 'maven' | 'gradle'; + id: 'maven' | 'gradle' | 'sbt'; /** * Paths of the file that specify the files to cache. */ @@ -32,6 +32,12 @@ const supportedPackageManager: PackageManager[] = [ path: [join(os.homedir(), '.gradle', 'caches'), join(os.homedir(), '.gradle', 'wrapper')], // https://github.com/actions/cache/blob/0638051e9af2c23d10bb70fa9beffcad6cff9ce3/examples.md#java---gradle pattern: ['**/*.gradle*', '**/gradle-wrapper.properties'] + }, + { + id: 'sbt', + path: [join(os.homedir(), '.ivy2', 'cache'), join(os.homedir(), '.sbt')], + // https://github.com/actions/cache/blob/0638051e9af2c23d10bb70fa9beffcad6cff9ce3/examples.md#scala---sbt + pattern: ['**/build.sbt'] } ];