Skip to content

Commit 27863b3

Browse files
authored
Merge pull request #13 from namespacelabs/niklas-debug-support
Print more internal details on debug runs.
2 parents efcb54d + 33138c5 commit 27863b3

File tree

3 files changed

+30
-27
lines changed

3 files changed

+30
-27
lines changed

dist/index/index.js

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -27125,7 +27125,7 @@ const external_node_fs_namespaceObject = __WEBPACK_EXTERNAL_createRequire(import
2712527125
;// CONCATENATED MODULE: external "node:path"
2712627126
const external_node_path_namespaceObject = __WEBPACK_EXTERNAL_createRequire(import.meta.url)("node:path");
2712727127
// EXTERNAL MODULE: ./node_modules/@actions/core/lib/core.js
27128-
var core = __nccwpck_require__(2186);
27128+
var lib_core = __nccwpck_require__(2186);
2712927129
// EXTERNAL MODULE: ./node_modules/@actions/exec/lib/exec.js
2713027130
var lib_exec = __nccwpck_require__(1514);
2713127131
// EXTERNAL MODULE: ./node_modules/@actions/io/lib/io.js
@@ -27154,20 +27154,20 @@ async function sudoMkdirP(path) {
2715427154
const anc = ancestors(path);
2715527155
for (const p of anc) {
2715627156
if (external_node_fs_namespaceObject.existsSync(p)) {
27157-
core.debug(`${p} already exists`);
27157+
lib_core.debug(`${p} already exists`);
2715827158
continue;
2715927159
}
2716027160
const { exitCode, stderr } = await lib_exec.getExecOutput("sudo", ["mkdir", p], {
27161-
silent: true,
27161+
silent: !lib_core.isDebug(),
2716227162
ignoreReturnCode: true,
2716327163
});
2716427164
if (exitCode > 0) {
2716527165
// Sadly, the exit code is 1 and we cannot match for EEXIST in case of concurrent directory creation.
2716627166
if (external_node_fs_namespaceObject.existsSync(p)) {
27167-
core.debug(`${p} was concurrently created`);
27167+
lib_core.debug(`${p} was concurrently created`);
2716827168
continue;
2716927169
}
27170-
core.info(stderr);
27170+
lib_core.info(stderr);
2717127171
throw new Error(`'sudo mkdir ${p}' failed with exit code ${exitCode}`);
2717227172
}
2717327173
await chownSelf(p);
@@ -27193,7 +27193,7 @@ function ancestors(filepath) {
2719327193
}
2719427194
async function getCacheUtil(cachePath) {
2719527195
const { stdout } = await exec.getExecOutput(`/bin/sh -c "du -sb ${cachePath} | cut -f1"`, [], {
27196-
silent: true,
27196+
silent: !core.isDebug(),
2719727197
ignoreReturnCode: true,
2719827198
});
2719927199
const cacheUtil = Number.parseInt(stdout.trim());
@@ -27255,22 +27255,22 @@ See also https://namespace.so/docs/features/faster-github-actions#using-a-cache-
2725527255

2725627256
Are you running in a container? Check out https://namespace.so/docs/actions/nscloud-cache-action#advanced-running-github-jobs-in-containers`);
2725727257
}
27258-
core.info(`Found Namespace cross-invocation cache at ${localCachePath}.`);
27258+
lib_core.info(`Found Namespace cross-invocation cache at ${localCachePath}.`);
2725927259
const useSymlinks = process.env.RUNNER_OS === "macOS";
27260-
core.debug(`Using symlinks: ${useSymlinks} on ${process.env["RUNNER_OS"]}.`);
27260+
lib_core.debug(`Using symlinks: ${useSymlinks} on ${process.env["RUNNER_OS"]}.`);
2726127261
const cachePaths = await resolveCachePaths(localCachePath);
2726227262
const cacheMisses = await restoreLocalCache(cachePaths, useSymlinks);
2726327263
const fullHit = cacheMisses.length === 0;
27264-
core.setOutput(Output_CacheHit, fullHit.toString());
27264+
lib_core.setOutput(Output_CacheHit, fullHit.toString());
2726527265
if (!fullHit) {
27266-
core.info(`Some cache paths missing: ${cacheMisses}.`);
27267-
const failOnCacheMiss = core.getBooleanInput(Input_FailOnCacheMiss);
27266+
lib_core.info(`Some cache paths missing: ${cacheMisses}.`);
27267+
const failOnCacheMiss = lib_core.getBooleanInput(Input_FailOnCacheMiss);
2726827268
if (failOnCacheMiss) {
2726927269
throw new Error(`Some cache paths missing: ${cacheMisses}.`);
2727027270
}
2727127271
}
2727227272
else {
27273-
core.info("All cache paths found and restored.");
27273+
lib_core.info("All cache paths found and restored.");
2727427274
}
2727527275
try {
2727627276
// Write/update cache volume metadata file
@@ -27290,18 +27290,18 @@ Are you running in a container? Check out https://namespace.so/docs/actions/nscl
2729027290
writeCacheMetadata(localCachePath, metadata);
2729127291
}
2729227292
catch (e) {
27293-
core.warning("Failed to record cache metadata.");
27294-
core.info(e.message);
27293+
lib_core.warning("Failed to record cache metadata.");
27294+
lib_core.info(e.message);
2729527295
}
2729627296
// Save the list of cache paths to actions state for the post-cache action
27297-
core.saveState(StatePathsKey, cachePaths);
27297+
lib_core.saveState(StatePathsKey, cachePaths);
2729827298
const cacheUtilInfo = await getCacheSummaryUtil(localCachePath);
27299-
core.info(`Total available cache space is ${cacheUtilInfo.size}, and ${cacheUtilInfo.used} have been used.`);
27299+
lib_core.info(`Total available cache space is ${cacheUtilInfo.size}, and ${cacheUtilInfo.used} have been used.`);
2730027300
}
2730127301
catch (error) {
2730227302
// Fail the workflow run if an error occurs
2730327303
if (error instanceof Error)
27304-
core.setFailed(error.message);
27304+
lib_core.setFailed(error.message);
2730527305
}
2730627306
}
2730727307
async function restoreLocalCache(cachePaths, useSymlinks) {
@@ -27331,11 +27331,11 @@ async function restoreLocalCache(cachePaths, useSymlinks) {
2733127331
}
2733227332
async function resolveCachePaths(localCachePath) {
2733327333
const paths = [];
27334-
const manual = core.getMultilineInput(Input_Path);
27334+
const manual = lib_core.getMultilineInput(Input_Path);
2733527335
for (const p of manual) {
2733627336
paths.push({ mountTarget: p, framework: "custom" });
2733727337
}
27338-
const cacheModes = core.getMultilineInput(Input_Cache);
27338+
const cacheModes = lib_core.getMultilineInput(Input_Cache);
2733927339
for (const mode of cacheModes) {
2734027340
paths.push(...(await resolveCacheMode(mode)));
2734127341
}
@@ -27373,6 +27373,7 @@ async function resolveCacheMode(cacheMode) {
2737327373
{ mountTarget: pnpmCache, framework: cacheMode },
2737427374
];
2737527375
const json = await getExecStdout("pnpm m ls --depth -1 --json");
27376+
lib_core.debug(`Extracting PNPM workspaces from: ${json}`);
2737627377
const jsonMultiParse = __nccwpck_require__(3715);
2737727378
const parsed = jsonMultiParse(json);
2737827379
for (const list of parsed) {
@@ -27415,24 +27416,24 @@ async function resolveCacheMode(cacheMode) {
2741527416
case "uv": {
2741627417
// Defaults to clone (also known as Copy-on-Write) on macOS, and hardlink on Linux and Windows.
2741727418
// Neither works with cache volumes, and fall back to `copy`. Select `symlink` to avoid copies.
27418-
core.exportVariable("UV_LINK_MODE", "symlink");
27419+
lib_core.exportVariable("UV_LINK_MODE", "symlink");
2741927420
const uvCache = await getExecStdout("uv cache dir");
2742027421
return [{ mountTarget: uvCache, framework: cacheMode }];
2742127422
}
2742227423
default:
27423-
core.warning(`Unknown cache option: ${cacheMode}.`);
27424+
lib_core.warning(`Unknown cache option: ${cacheMode}.`);
2742427425
return [];
2742527426
}
2742627427
}
2742727428
async function getExecStdout(cmd) {
2742827429
const { stdout } = await lib_exec.getExecOutput(cmd, [], {
27429-
silent: true,
27430+
silent: !lib_core.isDebug(),
2743027431
});
2743127432
return stdout.trim();
2743227433
}
2743327434
async function getCacheSummaryUtil(cachePath) {
2743427435
const { stdout } = await lib_exec.getExecOutput(`/bin/sh -c "df -h ${cachePath} | awk 'FNR == 2 {print $2,$3}'"`, [], {
27435-
silent: true,
27436+
silent: !lib_core.isDebug(),
2743627437
ignoreReturnCode: true,
2743727438
});
2743827439
const cacheUtilData = stdout.trim().split(" ");

src/index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,8 @@ async function resolveCacheMode(cacheMode: string): Promise<utils.CachePath[]> {
188188
];
189189

190190
const json = await getExecStdout("pnpm m ls --depth -1 --json");
191+
192+
core.debug(`Extracting PNPM workspaces from: ${json}`);
191193
const jsonMultiParse = require("json-multi-parse");
192194
const parsed = jsonMultiParse(json);
193195

@@ -254,7 +256,7 @@ async function resolveCacheMode(cacheMode: string): Promise<utils.CachePath[]> {
254256

255257
async function getExecStdout(cmd: string): Promise<string> {
256258
const { stdout } = await exec.getExecOutput(cmd, [], {
257-
silent: true,
259+
silent: !core.isDebug(),
258260
});
259261

260262
return stdout.trim();
@@ -272,7 +274,7 @@ async function getCacheSummaryUtil(
272274
`/bin/sh -c "df -h ${cachePath} | awk 'FNR == 2 {print $2,$3}'"`,
273275
[],
274276
{
275-
silent: true,
277+
silent: !core.isDebug(),
276278
ignoreReturnCode: true,
277279
}
278280
);

src/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export async function sudoMkdirP(path: string) {
4040
"sudo",
4141
["mkdir", p],
4242
{
43-
silent: true,
43+
silent: !core.isDebug(),
4444
ignoreReturnCode: true,
4545
}
4646
);
@@ -84,7 +84,7 @@ export async function getCacheUtil(cachePath: string): Promise<number> {
8484
`/bin/sh -c "du -sb ${cachePath} | cut -f1"`,
8585
[],
8686
{
87-
silent: true,
87+
silent: !core.isDebug(),
8888
ignoreReturnCode: true,
8989
}
9090
);

0 commit comments

Comments
 (0)