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(cache): change key to match actions/cache documentation #213

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -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
11 changes: 6 additions & 5 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -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
}
12 changes: 9 additions & 3 deletions __tests__/cache.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand All @@ -107,15 +109,19 @@ 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'));

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-`
);
});
});
});
Expand Down
12 changes: 7 additions & 5 deletions dist/cleanup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`;
});
}
/**
Expand All @@ -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(', ')}`);
}
});
}
Expand Down
12 changes: 7 additions & 5 deletions dist/setup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`;
});
}
/**
Expand All @@ -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(', ')}`);
}
});
}
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
12 changes: 7 additions & 5 deletions src/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`;
}

/**
Expand All @@ -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(', ')}`);
}
}

Expand Down