Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add force-overwrite for cache #1308

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
Also add "force-overwrite" option to save-only action
  • Loading branch information
PrinsFrank committed Aug 2, 2024
commit 0d93be3424692a737cd2a7333be007dcef9a45ea
4 changes: 4 additions & 0 deletions save/action.yml
Original file line number Diff line number Diff line change
@@ -15,6 +15,10 @@ inputs:
description: 'An optional boolean when enabled, allows windows runners to save caches that can be restored on other platforms'
default: 'false'
required: false
force-overwrite:
description: 'Delete any previous (incremental) cache before pushing a new cache even if a cache for the primary cache key exists'
default: 'false'
required: false
runs:
using: 'node20'
main: '../dist/save-only/index.js'
10 changes: 6 additions & 4 deletions src/saveImpl.ts
Original file line number Diff line number Diff line change
@@ -8,7 +8,6 @@ import {
StateProvider
} from "./stateProvider";
import * as utils from "./utils/actionUtils";
import { issueCommand } from "@actions/core/lib/command";

// Catch and log any unhandled exceptions. These exceptions can leak out of the uploadChunk method in
// @actions/toolkit when a failed upload closes the file descriptor causing any in-process reads to
@@ -51,13 +50,16 @@ export async function saveImpl(
const forceOverwrite = utils.getInputAsBool(Inputs.ForceOverwrite);
if (utils.isExactKeyMatch(primaryKey, restoredKey) && !forceOverwrite) {
core.info(
`Cache hit occurred on the primary key ${primaryKey} and force-overwrite is disabled, not saving cache.`
`Cache hit occurred on the primary key "${primaryKey}" and force-overwrite is disabled, not saving cache.`
);
return;
}

if (utils.isExactKeyMatch(primaryKey, restoredKey) && forceOverwrite) {
await issueCommand('actions-cache delete', {}, primaryKey);
if ((restoredKey == undefined || utils.isExactKeyMatch(primaryKey, restoredKey)) && forceOverwrite) {
core.info(
`Cache hit occurred on the primary key "${primaryKey}" or running as save-only and force-overwrite is enabled, deleting cache.`
);
await cache.deleteCache(primaryKey)
}

const cachePaths = utils.getInputAsArray(Inputs.Path, {