Skip to content

Commit

Permalink
collect pre-exec util
Browse files Browse the repository at this point in the history
  • Loading branch information
gmichelo committed Jan 26, 2024
1 parent de54bc7 commit dd773df
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
15 changes: 10 additions & 5 deletions dist/index/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27002,7 +27002,7 @@ var external_path_ = __nccwpck_require__(1017);
// EXTERNAL MODULE: ./node_modules/@actions/core/lib/core.js
var core = __nccwpck_require__(2186);
// EXTERNAL MODULE: ./node_modules/@actions/exec/lib/exec.js
var lib_exec = __nccwpck_require__(1514);
var exec = __nccwpck_require__(1514);
// EXTERNAL MODULE: ./node_modules/@actions/io/lib/io.js
var io = __nccwpck_require__(7436);
;// CONCATENATED MODULE: ./src/utils.ts
Expand Down Expand Up @@ -27057,7 +27057,7 @@ const Input_Path = "path";
const Input_Cache = "cache";
const Input_FailOnCacheMiss = "fail-on-cache-miss";
const Output_CacheHit = "cache-hit";
const ActionVersion = "nscloud-action-cache@v4";
const ActionVersion = "nscloud-action-cache@v1";
void main();
async function main() {
const localCachePath = process.env[Env_CacheRoot];
Expand All @@ -27079,14 +27079,19 @@ async function main() {
else {
core.info(`All cache paths found and restored.`);
}
// Write/update cache volume metadata file
let metadata = await ensureCacheMetadata(localCachePath);
metadata.updatedAt = new Date().toISOString();
metadata.version = 1;
if (!metadata.userRequest) {
metadata.userRequest = {};
}
if (!metadata.preExecution) {
metadata.preExecution = { usage: {} };
}
for (const p of cachePaths) {
metadata.userRequest[p.pathInCache] = { cacheFramework: p.framework, mountTarget: [p.mountTarget], source: ActionVersion };
metadata.preExecution.usage[p.pathInCache] = await getCacheUtil(p.pathInCache);
}
writeCacheMetadata(localCachePath, metadata);
const cacheUtilInfo = await getCacheSummaryUtil(localCachePath);
Expand All @@ -27104,7 +27109,7 @@ async function restoreLocalCache(cachePaths) {
const expandedFilePath = resolveHome(p.mountTarget);
await io.mkdirP(expandedFilePath);
await io.mkdirP(p.pathInCache);
await lib_exec.exec(`sudo mount --bind ${p.pathInCache} ${expandedFilePath}`);
await exec.exec(`sudo mount --bind ${p.pathInCache} ${expandedFilePath}`);
}
return cacheMisses;
}
Expand Down Expand Up @@ -27171,13 +27176,13 @@ async function resolveCacheMode(cacheMode) {
}
}
async function getExecStdout(cmd) {
const { stdout } = await lib_exec.getExecOutput(cmd, [], {
const { stdout } = await exec.getExecOutput(cmd, [], {
silent: true,
});
return stdout.trim();
}
async function getCacheSummaryUtil(cachePath) {
const { stdout } = await lib_exec.getExecOutput(`/bin/sh -c "df -h ${cachePath} | awk 'FNR == 2 {print $2,$3}'"`, [], {
const { stdout } = await exec.getExecOutput(`/bin/sh -c "df -h ${cachePath} | awk 'FNR == 2 {print $2,$3}'"`, [], {
silent: true,
ignoreReturnCode: true,
});
Expand Down
7 changes: 6 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const Input_Path = "path";
const Input_Cache = "cache";
const Input_FailOnCacheMiss = "fail-on-cache-miss";
const Output_CacheHit = "cache-hit";
const ActionVersion = "nscloud-action-cache@v4";
const ActionVersion = "nscloud-action-cache@v1";

void main();

Expand Down Expand Up @@ -47,15 +47,20 @@ async function main() {
core.info(`All cache paths found and restored.`);
}

// Write/update cache volume metadata file
let metadata = await utils.ensureCacheMetadata(localCachePath);
metadata.updatedAt = new Date().toISOString();
metadata.version = 1;
if (!metadata.userRequest) {
metadata.userRequest = {};
}
if (!metadata.preExecution) {
metadata.preExecution = {usage: {}};
}

for (const p of cachePaths) {
metadata.userRequest[p.pathInCache] = {cacheFramework: p.framework, mountTarget: [p.mountTarget], source: ActionVersion};
metadata.preExecution.usage[p.pathInCache] = await utils.getCacheUtil(p.pathInCache);
}
utils.writeCacheMetadata(localCachePath, metadata);

Expand Down

0 comments on commit dd773df

Please sign in to comment.