1
0
Fork 0
mirror of https://github.com/actions/cache.git synced 2025-07-16 21:27:54 +00:00
This commit is contained in:
Caleb Gosiak 2021-09-30 18:56:21 -05:00
parent 9d956bc62d
commit 0b4a0a4930
4 changed files with 26 additions and 13 deletions

View file

@ -38,7 +38,7 @@ export class CacheService {
restoreKeys: string[]
): Promise<string | undefined> {
restoreKeys = restoreKeys || [];
const keys = [primaryKey, ...restoreKeys];
const keys = [primaryKey, ...restoreKeys].map(x => this.formatKey(x));
core.debug("Resolved Keys:");
core.debug(JSON.stringify(keys));
@ -85,6 +85,7 @@ export class CacheService {
}
async saveCache(paths: string[], key: string): Promise<string> {
const formattedKey: string = this.formatKey(key);
const compressionMethod = await utils.getCompressionMethod();
const cachePaths = await utils.resolvePaths(paths);
@ -109,8 +110,8 @@ export class CacheService {
`Archive Size: ${filesize(fs.statSync(archivePath).size)}`
);
core.debug(`Saving Cache (ID: ${key})`);
await this.uploadToS3(key, archivePath);
core.debug(`Saving Cache (ID: ${formattedKey})`);
await this.uploadToS3(formattedKey, archivePath);
} finally {
// Try to delete the archive to save space
try {
@ -120,7 +121,7 @@ export class CacheService {
}
}
return key;
return formattedKey;
}
private async uploadToS3(
@ -218,4 +219,8 @@ export class CacheService {
.replace("/", "-")
.toLowerCase();
}
private formatKey(key: string): string {
return key.replace(/[^\w\s]/gi, "-");
}
}