Skip to content

Commit

Permalink
fix: Fix cache keys.
Browse files Browse the repository at this point in the history
  • Loading branch information
milesj committed Nov 22, 2023
1 parent 88afbc4 commit 4b6d928
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# 0.1.2

- Improve cache key checks.
- Reduce globbing calls.

# 0.1.1

- Updated logging.
Expand Down
16 changes: 13 additions & 3 deletions helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,26 @@ export function isUsingMoon() {
return fs.existsSync(path.join(getWorkingDir(), core.getInput('workspace-root'), '.moon'));
}

export function getCacheKeyPrefix() {
return 'moonrepo-toolchain-v1';
}

export async function getToolchainCacheKey() {
const files = ['**/.prototools'];
const files = ['.prototools'];

if (isUsingMoon()) {
files.push(path.join(core.getInput('workspace-root'), '.moon/toolchain.yml'));
const root = core.getInput('workspace-root');

if (root) {
files.push(path.join(root, '.prototools'), path.join(root, '.moon/toolchain.yml'));
} else {
files.push('.moon/toolchain.yml');
}
}

const toolchainHash = await glob.hashFiles(files.join('\n'));

return `moonrepo-toolchain-v1-${process.platform}-${toolchainHash}`;
return `${getCacheKeyPrefix()}-${process.platform}-${toolchainHash}`;
}

export async function installBin(bin: string) {
Expand Down
4 changes: 3 additions & 1 deletion index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as cache from '@actions/cache';
import * as core from '@actions/core';
import {
getBinDir,
getCacheKeyPrefix,
getPluginsDir,
getShimsDir,
getToolchainCacheKey,
Expand All @@ -19,10 +20,11 @@ async function restoreCache() {
core.info('Attempting to restore cached toolchain');

const primaryKey = await getToolchainCacheKey();
const cachePrefix = getCacheKeyPrefix();
const cacheKey = await cache.restoreCache(
[getPluginsDir(), getToolsDir()],
primaryKey,
[`moonrepo-toolchain-${process.platform}`, 'moonrepo-toolchain'],
[`${cachePrefix}-${process.platform}`, cachePrefix],
{},
false,
);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@moonrepo/setup-toolchain",
"version": "0.1.1",
"version": "0.1.2",
"description": "A GitHub action to setup and cache the proto and moon toolchains.",
"main": "dist/index.js",
"scripts": {
Expand Down

0 comments on commit 4b6d928

Please sign in to comment.