Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ Currently, the following distributions are supported:
### Caching packages dependencies
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 cache input is optional, and caching is turned off by default.

The interaction with the cache can be controlled by the `cache-mode` parameter. This allows for builds to
be performed with no cache, and the output cached (`write` mode), builds to read the cache before running
but not update the cache afterwards (`read` mode), or both (`both` mode). This feature allows you to
populate the cache from your `main` branch, and then let PR builds benefit from that cache without polluting
it with PR-specific build artifacts.

#### Caching gradle dependencies
```yaml
steps:
Expand Down
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ inputs:
cache:
description: 'Name of the build platform to cache dependencies. It can be "maven" or "gradle".'
required: false
cache-mode:
description: 'Whether the cache should be read from pre-build, written to afterwards, or both'
default: both
job-status:
description: 'Workaround to pass job status to post job step. This variable is not intended for manual setting'
default: ${{ job.status }}
Expand Down
4 changes: 3 additions & 1 deletion src/cleanup-java.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ async function removePrivateKeyFromKeychain() {
async function saveCache() {
const jobStatus = isJobStatusSuccess();
const cache = core.getInput(constants.INPUT_CACHE);
return jobStatus && cache ? save(cache) : Promise.resolve();
const cacheMode = core.getInput(constants.INPUT_CACHE_MODE)
const updateCache = Boolean(cacheMode === "both" || cacheMode === "write")
return jobStatus && cache && updateCache ? save(cache) : Promise.resolve();
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export const INPUT_DEFAULT_GPG_PRIVATE_KEY = undefined;
export const INPUT_DEFAULT_GPG_PASSPHRASE = 'GPG_PASSPHRASE';

export const INPUT_CACHE = 'cache';
export const INPUT_CACHE_MODE = "cache-mode";
export const INPUT_JOB_STATUS = 'job-status';

export const STATE_GPG_PRIVATE_KEY_FINGERPRINT = 'gpg-private-key-fingerprint';
4 changes: 3 additions & 1 deletion src/setup-java.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ async function run() {
core.info(`##[add-matcher]${path.join(matchersPath, 'java.json')}`);

await auth.configureAuthentication();
if (cache) {
const cacheMode = core.getInput(constants.INPUT_CACHE_MODE)
const restoreCache = Boolean(cacheMode === "both" || cacheMode === "read")
if (cache && restoreCache) {
await restore(cache);
}
} catch (error) {
Expand Down