Skip to content
Open
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
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ inputs:
cache-dependency-path:
description: 'The path to a dependency file: pom.xml, build.gradle, build.sbt, etc. This option can be used with the `cache` option. If this option is omitted, the action searches for the dependency file in the entire repository. This option supports wildcards and a list of file names for caching multiple dependencies.'
required: false
cache-write:
description: 'Whether to save the cache at the end of the workflow. Set to false for cache read-only mode, useful for preventing cache poisoning from untrusted PR builds.'
required: false
default: true
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
5 changes: 5 additions & 0 deletions dist/cleanup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -76919,6 +76919,11 @@ function removePrivateKeyFromKeychain() {
*/
function saveCache() {
return __awaiter(this, void 0, void 0, function* () {
const cacheWriteEnabled = core.getInput('cache-write');
if (cacheWriteEnabled === 'false') {
core.info('Cache write is disabled (read-only mode). Skipping cache save.');
return Promise.resolve();
}
const jobStatus = (0, util_1.isJobStatusSuccess)();
const cache = core.getInput(constants.INPUT_CACHE);
return jobStatus && cache ? (0, cache_1.save)(cache) : Promise.resolve();
Expand Down
6 changes: 6 additions & 0 deletions src/cleanup-java.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ async function removePrivateKeyFromKeychain() {
* @returns Promise that will be resolved when the save process finishes
*/
async function saveCache() {
const cacheWriteEnabled = core.getInput('cache-write');
if (cacheWriteEnabled === 'false') {
Comment on lines +28 to +29
Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The codebase has an established getBooleanInput() utility in src/util.ts that handles case-insensitive comparison (via .toUpperCase() === 'TRUE'). It's used for all other boolean inputs: check-latest in setup-java.ts:30, overwrite-settings in auth.ts:20 and toolchains.ts:30.

Using raw string comparison === 'false' here is fragile — it won't match 'False' or 'FALSE', which users might reasonably pass. This should use getBooleanInput from src/util.ts instead, with the logic inverted (skip save when the result is false).

Additionally, the input name 'cache-write' is hardcoded as a string literal, whereas the codebase convention is to define input name constants in src/constants.ts (e.g., INPUT_CACHE, INPUT_CACHE_DEPENDENCY_PATH at line 20-21). A constant like INPUT_CACHE_WRITE should be added there and used here.

Copilot uses AI. Check for mistakes.
core.info('Cache write is disabled (read-only mode). Skipping cache save.');
return Promise.resolve();
}
Comment on lines +28 to +32
Copy link

Copilot AI Mar 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The existing test file has tests for cache save behavior (error handling, successful saves), but no test was added for the new cache-write: false code path. A test should verify that when cache-write input is 'false', saveCache returns early without calling cache.saveCache. This is important because this is the core behavior being added by this PR.

Copilot uses AI. Check for mistakes.

const jobStatus = isJobStatusSuccess();
const cache = core.getInput(constants.INPUT_CACHE);
return jobStatus && cache ? save(cache) : Promise.resolve();
Expand Down
Loading