feat(cache): change key to match actions/cache documentation

Signed-off-by: Matthieu MOREL <mmorel-35@users.noreply.github.com>
This commit is contained in:
MOREL Matthieu 2021-08-26 15:31:04 +02:00
parent 3bc31aaf88
commit 0f6dbb0a05
7 changed files with 39 additions and 25 deletions

2
.gitattributes vendored
View File

@ -1,3 +1,3 @@
dist/index.js -diff -merge
dist/index.js linguist-generated=true
.licenses/** -diff linguist-generated=true
.licenses/** -diff linguist-generated=true

View File

@ -1,11 +1,12 @@
{
"arrowParens": "avoid",
"bracketSpacing": true,
"endOfLine": "auto",
"parser": "typescript",
"printWidth": 100,
"tabWidth": 2,
"useTabs": false,
"semi": true,
"singleQuote": true,
"tabWidth": 2,
"trailingComma": "none",
"bracketSpacing": true,
"arrowParens": "avoid",
"parser": "typescript"
"useTabs": false
}

View File

@ -90,7 +90,9 @@ describe('dependency cache', () => {
await restore('maven');
expect(spyCacheRestore).toBeCalled();
expect(spyWarning).not.toBeCalled();
expect(spyInfo).toBeCalledWith('maven cache is not found');
expect(spyInfo).toBeCalledWith(
`Cache not found for input keys: ${process.env['RUNNER_OS']}-setup-java-maven-5df6e0e2761359d30a8275058e299fcc0381534545f55cf43e41983f5d4c9456, ${process.env['RUNNER_OS']}-setup-java-maven-, ${process.env['RUNNER_OS']}-setup-java-`
);
});
});
describe('for gradle', () => {
@ -107,7 +109,9 @@ describe('dependency cache', () => {
await restore('gradle');
expect(spyCacheRestore).toBeCalled();
expect(spyWarning).not.toBeCalled();
expect(spyInfo).toBeCalledWith('gradle cache is not found');
expect(spyInfo).toBeCalledWith(
`Cache not found for input keys: ${process.env['RUNNER_OS']}-setup-java-gradle-5df6e0e2761359d30a8275058e299fcc0381534545f55cf43e41983f5d4c9456, ${process.env['RUNNER_OS']}-setup-java-gradle-, ${process.env['RUNNER_OS']}-setup-java-`
);
});
it('downloads cache based on build.gradle.kts', async () => {
createFile(join(workspace, 'build.gradle.kts'));
@ -115,7 +119,9 @@ describe('dependency cache', () => {
await restore('gradle');
expect(spyCacheRestore).toBeCalled();
expect(spyWarning).not.toBeCalled();
expect(spyInfo).toBeCalledWith('gradle cache is not found');
expect(spyInfo).toBeCalledWith(
`Cache not found for input keys: ${process.env['RUNNER_OS']}-setup-java-gradle-5df6e0e2761359d30a8275058e299fcc0381534545f55cf43e41983f5d4c9456, ${process.env['RUNNER_OS']}-setup-java-gradle-, ${process.env['RUNNER_OS']}-setup-java-`
);
});
});
});

12
dist/cleanup/index.js vendored
View File

@ -64575,7 +64575,7 @@ function findPackageManager(id) {
function computeCacheKey(packageManager) {
return __awaiter(this, void 0, void 0, function* () {
const hash = yield glob.hashFiles(packageManager.pattern.join('\n'));
return `${CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-${packageManager.id}-${hash}`;
return `${process.env.RUNNER_OS}-${CACHE_KEY_PREFIX}-${packageManager.id}-${hash}`;
});
}
/**
@ -64591,15 +64591,17 @@ function restore(id) {
if (primaryKey.endsWith('-')) {
throw new Error(`No file in ${process.cwd()} matched to [${packageManager.pattern}], make sure you have checked out the target repository`);
}
const matchedKey = yield cache.restoreCache(packageManager.path, primaryKey, [
`${CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-${id}`
]);
const restoreKeys = [
`${process.env.RUNNER_OS}-${CACHE_KEY_PREFIX}-${id}-`,
`${process.env.RUNNER_OS}-${CACHE_KEY_PREFIX}-`
];
const matchedKey = yield cache.restoreCache(packageManager.path, primaryKey, restoreKeys);
if (matchedKey) {
core.saveState(CACHE_MATCHED_KEY, matchedKey);
core.info(`Cache restored from key: ${matchedKey}`);
}
else {
core.info(`${packageManager.id} cache is not found`);
core.info(`Cache not found for input keys: ${[primaryKey, ...restoreKeys].join(', ')}`);
}
});
}

12
dist/setup/index.js vendored
View File

@ -18962,7 +18962,7 @@ function findPackageManager(id) {
function computeCacheKey(packageManager) {
return __awaiter(this, void 0, void 0, function* () {
const hash = yield glob.hashFiles(packageManager.pattern.join('\n'));
return `${CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-${packageManager.id}-${hash}`;
return `${process.env.RUNNER_OS}-${CACHE_KEY_PREFIX}-${packageManager.id}-${hash}`;
});
}
/**
@ -18978,15 +18978,17 @@ function restore(id) {
if (primaryKey.endsWith('-')) {
throw new Error(`No file in ${process.cwd()} matched to [${packageManager.pattern}], make sure you have checked out the target repository`);
}
const matchedKey = yield cache.restoreCache(packageManager.path, primaryKey, [
`${CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-${id}`
]);
const restoreKeys = [
`${process.env.RUNNER_OS}-${CACHE_KEY_PREFIX}-${id}-`,
`${process.env.RUNNER_OS}-${CACHE_KEY_PREFIX}-`
];
const matchedKey = yield cache.restoreCache(packageManager.path, primaryKey, restoreKeys);
if (matchedKey) {
core.saveState(CACHE_MATCHED_KEY, matchedKey);
core.info(`Cache restored from key: ${matchedKey}`);
}
else {
core.info(`${packageManager.id} cache is not found`);
core.info(`Cache not found for input keys: ${[primaryKey, ...restoreKeys].join(', ')}`);
}
});
}

View File

@ -10,7 +10,8 @@
"format-check": "prettier --check \"{,!(node_modules)/**/}*.ts\"",
"prerelease": "npm run-script build",
"release": "git add -f dist/setup/index.js dist/cleanup/index.js",
"test": "jest"
"test": "jest",
"pre-checkin": "npm run format && npm run build && npm test"
},
"repository": {
"type": "git",

View File

@ -51,7 +51,7 @@ function findPackageManager(id: string): PackageManager {
*/
async function computeCacheKey(packageManager: PackageManager) {
const hash = await glob.hashFiles(packageManager.pattern.join('\n'));
return `${CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-${packageManager.id}-${hash}`;
return `${process.env.RUNNER_OS}-${CACHE_KEY_PREFIX}-${packageManager.id}-${hash}`;
}
/**
@ -72,14 +72,16 @@ export async function restore(id: string) {
);
}
const matchedKey = await cache.restoreCache(packageManager.path, primaryKey, [
`${CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-${id}`
]);
const restoreKeys = [
`${process.env.RUNNER_OS}-${CACHE_KEY_PREFIX}-${id}-`,
`${process.env.RUNNER_OS}-${CACHE_KEY_PREFIX}-`
];
const matchedKey = await cache.restoreCache(packageManager.path, primaryKey, restoreKeys);
if (matchedKey) {
core.saveState(CACHE_MATCHED_KEY, matchedKey);
core.info(`Cache restored from key: ${matchedKey}`);
} else {
core.info(`${packageManager.id} cache is not found`);
core.info(`Cache not found for input keys: ${[primaryKey, ...restoreKeys].join(', ')}`);
}
}