Skip to content

Commit

Permalink
Add option to override cache key. Add workflow name to default cache …
Browse files Browse the repository at this point in the history
…key.

Fixes Hardcoded cache key prevents multiple workflows or jobs from caching emsdk #20
  • Loading branch information
mymindstorm committed Jan 22, 2024
1 parent d233ac1 commit 4193ab1
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ inputs:
actions-cache-folder:
description: "Directory to cache emsdk in. This folder will go under $GITHUB_HOME (I.e. build dir) and be cached using @actions/cache."
default: ''
cache-key:
description: "Override the cache key. By default, it is `{Github workflow name}-{Emscripten version}-{OS type}-${CPU architecture}`."
default: ''
update:
description: "Fetch package information for all the new tools and SDK versions"
default: false
Expand Down
3 changes: 2 additions & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ function run() {
noInstall: yield core.getInput("no-install"),
noCache: yield core.getInput("no-cache"),
actionsCacheFolder: yield core.getInput("actions-cache-folder"),
cacheKey: yield core.getInput("cache-key"),
// XXX: update-tags is deprecated and used for backwards compatibility.
update: (yield core.getInput("update")) || (yield core.getInput("update-tags"))
};
Expand All @@ -64,7 +65,7 @@ function run() {
if (emArgs.version !== "latest" && emArgs.version !== "tot" && emArgs.noCache === "false" && !emArgs.actionsCacheFolder) {
emsdkFolder = yield tc.find('emsdk', emArgs.version, os.arch());
}
const cacheKey = `${emArgs.version}-${os.platform()}-${os.arch()}-master`;
const cacheKey = emArgs.cacheKey || `${process.env.GITHUB_WORKFLOW}-${emArgs.version}-${os.platform()}-${os.arch()}`;
if (emArgs.actionsCacheFolder && process.env.GITHUB_WORKSPACE) {
const fullCachePath = path.join(process.env.GITHUB_WORKSPACE, emArgs.actionsCacheFolder);
try {
Expand Down
5 changes: 3 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ async function run() {
noInstall: await core.getInput("no-install"),
noCache: await core.getInput("no-cache"),
actionsCacheFolder: await core.getInput("actions-cache-folder"),
cacheKey: await core.getInput("cache-key"),
// XXX: update-tags is deprecated and used for backwards compatibility.
update: await core.getInput("update") || await core.getInput("update-tags")
};
Expand All @@ -26,7 +27,7 @@ async function run() {
emsdkFolder = await tc.find('emsdk', emArgs.version, os.arch());
}

const cacheKey = `${emArgs.version}-${ os.platform() }-${os.arch()}-master`;
const cacheKey = emArgs.cacheKey || `${process.env.GITHUB_WORKFLOW}-${emArgs.version}-${os.platform()}-${os.arch()}`;
if (emArgs.actionsCacheFolder && process.env.GITHUB_WORKSPACE) {
const fullCachePath = path.join(process.env.GITHUB_WORKSPACE, emArgs.actionsCacheFolder);
try {
Expand Down Expand Up @@ -100,7 +101,7 @@ async function run() {
await cache.saveCache([emArgs.actionsCacheFolder], cacheKey);
}
} catch (error) {
if (error &&
if (error &&
typeof error === "object" &&
"message" in error &&
(
Expand Down

0 comments on commit 4193ab1

Please sign in to comment.