Skip to content

Commit

Permalink
Add platform to cache key
Browse files Browse the repository at this point in the history
Even though caches are not shared across platforms by default, it seems
that they may not be namespaced as we are getting warnings that keys
already exist.
  • Loading branch information
elliotgoodrich committed Oct 8, 2024
1 parent 0a51a26 commit d8679a0
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/common.mts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { join } from "node:path";

export const archive = join("trimja-cache", "ninjafiles.tar.gz");

export const cachePrefix = `TRIMJA-${process.platform}-`;
8 changes: 5 additions & 3 deletions src/main.m.mts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { promisify } from "node:util";
import { join } from "node:path";
import { execFile as execFileCallback } from "node:child_process";
import { appendFile, writeFile } from "node:fs/promises";
import { archive } from "./common.mjs";
import { archive, cachePrefix } from "./common.mjs";
const execFile = promisify(execFileCallback);

function getPlatformVars(version: string): {
Expand Down Expand Up @@ -77,15 +77,17 @@ try {
});

info("Getting affected files");
const matchedCache = await restoreCache([archive], "TRIMJA-", ["TRIMJA-"]);
const matchedCache = await restoreCache([archive], cachePrefix, [
cachePrefix,
]);
if (matchedCache === undefined) {
info("No cache found, skipping trimja");
return;
}

info("Extracting ninja files");
await extractTar(archive, builddir);
const hash = matchedCache.slice("TRIMJA-".length);
const hash = matchedCache.slice(cachePrefix.length);

info(`Attempting to fetch ${hash}...`);
try {
Expand Down
4 changes: 2 additions & 2 deletions src/post.m.mts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { exec } from "@actions/exec";
import { join } from "node:path";
import { existsSync } from "node:fs";
import { mkdir } from "node:fs/promises";
import { archive } from "./common.mjs";
import { archive, cachePrefix } from "./common.mjs";

try {
(async () => {
Expand All @@ -27,7 +27,7 @@ try {
info(`Creating ${archive}`);
await exec("tar", ["-czvf", archive, "-C", builddir, ...files]);

const key = `TRIMJA-${HASH}`;
const key = `${cachePrefix}${HASH}`;
info(`Saving cache '${key}'`);
await saveCache([archive], key);
})();
Expand Down

0 comments on commit d8679a0

Please sign in to comment.