mirror of
https://code.forgejo.org/actions/cache.git
synced 2025-04-23 03:45:31 +00:00
Add support to opt-in enable cross-os caching on windows (#1056)
* Add support to opt-in enable cross-os caching on windows * Fix tests * Address review comments and update tests * Fix tests * Address review comments * Address review comments
This commit is contained in:
parent
1f414295fe
commit
6fd2d4538c
22 changed files with 1172 additions and 496 deletions
|
@ -2,7 +2,8 @@ export enum Inputs {
|
|||
Key = "key", // Input for cache, restore, save action
|
||||
Path = "path", // Input for cache, restore, save action
|
||||
RestoreKeys = "restore-keys", // Input for cache, restore action
|
||||
UploadChunkSize = "upload-chunk-size" // Input for cache, save action
|
||||
UploadChunkSize = "upload-chunk-size", // Input for cache, save action
|
||||
EnableCrossOsArchive = "enableCrossOsArchive" // Input for cache, restore, save action
|
||||
}
|
||||
|
||||
export enum Outputs {
|
||||
|
|
|
@ -31,11 +31,16 @@ async function restoreImpl(
|
|||
const cachePaths = utils.getInputAsArray(Inputs.Path, {
|
||||
required: true
|
||||
});
|
||||
const enableCrossOsArchive = utils.getInputAsBool(
|
||||
Inputs.EnableCrossOsArchive
|
||||
);
|
||||
|
||||
const cacheKey = await cache.restoreCache(
|
||||
cachePaths,
|
||||
primaryKey,
|
||||
restoreKeys
|
||||
restoreKeys,
|
||||
{},
|
||||
enableCrossOsArchive
|
||||
);
|
||||
|
||||
if (!cacheKey) {
|
||||
|
|
|
@ -52,9 +52,16 @@ async function saveImpl(stateProvider: IStateProvider): Promise<number | void> {
|
|||
required: true
|
||||
});
|
||||
|
||||
cacheId = await cache.saveCache(cachePaths, primaryKey, {
|
||||
uploadChunkSize: utils.getInputAsInt(Inputs.UploadChunkSize)
|
||||
});
|
||||
const enableCrossOsArchive = utils.getInputAsBool(
|
||||
Inputs.EnableCrossOsArchive
|
||||
);
|
||||
|
||||
cacheId = await cache.saveCache(
|
||||
cachePaths,
|
||||
primaryKey,
|
||||
{ uploadChunkSize: utils.getInputAsInt(Inputs.UploadChunkSize) },
|
||||
enableCrossOsArchive
|
||||
);
|
||||
|
||||
if (cacheId != -1) {
|
||||
core.info(`Cache saved with key: ${primaryKey}`);
|
||||
|
|
|
@ -52,6 +52,14 @@ export function getInputAsInt(
|
|||
return value;
|
||||
}
|
||||
|
||||
export function getInputAsBool(
|
||||
name: string,
|
||||
options?: core.InputOptions
|
||||
): boolean {
|
||||
const result = core.getInput(name, options);
|
||||
return result.toLowerCase() === "true";
|
||||
}
|
||||
|
||||
export function isCacheFeatureAvailable(): boolean {
|
||||
if (cache.isFeatureAvailable()) {
|
||||
return true;
|
||||
|
|
|
@ -13,6 +13,7 @@ interface CacheInput {
|
|||
path: string;
|
||||
key: string;
|
||||
restoreKeys?: string[];
|
||||
enableCrossOsArchive?: boolean;
|
||||
}
|
||||
|
||||
export function setInputs(input: CacheInput): void {
|
||||
|
@ -20,6 +21,11 @@ export function setInputs(input: CacheInput): void {
|
|||
setInput(Inputs.Key, input.key);
|
||||
input.restoreKeys &&
|
||||
setInput(Inputs.RestoreKeys, input.restoreKeys.join("\n"));
|
||||
input.enableCrossOsArchive !== undefined &&
|
||||
setInput(
|
||||
Inputs.EnableCrossOsArchive,
|
||||
input.enableCrossOsArchive.toString()
|
||||
);
|
||||
}
|
||||
|
||||
export function clearInputs(): void {
|
||||
|
@ -27,4 +33,5 @@ export function clearInputs(): void {
|
|||
delete process.env[getInputName(Inputs.Key)];
|
||||
delete process.env[getInputName(Inputs.RestoreKeys)];
|
||||
delete process.env[getInputName(Inputs.UploadChunkSize)];
|
||||
delete process.env[getInputName(Inputs.EnableCrossOsArchive)];
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue