From 62c27dc501707489e5184d1fcf0f73cac6feb40f Mon Sep 17 00:00:00 2001 From: Al Sutton Date: Thu, 23 Dec 2021 11:51:34 +0000 Subject: [PATCH] Switch to mode setting so we can write, read, or both --- action.yml | 6 +++--- src/cleanup-java.ts | 5 +++-- src/constants.ts | 2 +- src/setup-java.ts | 4 +++- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/action.yml b/action.yml index 07967e17..b6b9cf12 100644 --- a/action.yml +++ b/action.yml @@ -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 }} diff --git a/src/cleanup-java.ts b/src/cleanup-java.ts index e52de8ef..f62a1b07 100644 --- a/src/cleanup-java.ts +++ b/src/cleanup-java.ts @@ -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(); } /** diff --git a/src/constants.ts b/src/constants.ts index a5fdfeea..c39a043e 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -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'; diff --git a/src/setup-java.ts b/src/setup-java.ts index c6b12875..7a1e8d58 100644 --- a/src/setup-java.ts +++ b/src/setup-java.ts @@ -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) {