Switch to mode setting so we can write, read, or both

This commit is contained in:
Al Sutton 2021-12-23 11:51:34 +00:00
parent cec4e33030
commit 62c27dc501
4 changed files with 10 additions and 7 deletions

View file

@ -56,9 +56,9 @@ inputs:
cache:
description: 'Name of the build platform to cache dependencies. It can be "maven" or "gradle".'
required: false
cache-is-read-only:
description: 'Whether or not the build output should be cached. Default is true.'
default: true
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 }}

View file

@ -23,8 +23,9 @@ async function removePrivateKeyFromKeychain() {
async function saveCache() {
const jobStatus = isJobStatusSuccess();
const cache = core.getInput(constants.INPUT_CACHE);
const readOnlyCache = core.getInput(constants.INPUT_CACHE_READ_ONLY)
return jobStatus && cache && !readOnlyCache ? 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();
}
/**

View file

@ -17,7 +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_READ_ONLY = "cache-is-read-only";
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';

View file

@ -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) {