@@ -27230,54 +27230,74 @@ const Output_CacheHit = "cache-hit";
27230
27230
const ActionVersion = "nscloud-action-cache@v1";
27231
27231
void main();
27232
27232
async function main() {
27233
- const localCachePath = process.env[Env_CacheRoot];
27234
- if (localCachePath == null) {
27235
- throw new Error(`Local cache path not found.
27236
-
27237
- Did you configure the Namespace cross-invocation cache? https://namespace.so/docs/features/faster-github-actions#using-a-cache-volume
27233
+ try {
27234
+ const localCachePath = process.env[Env_CacheRoot];
27235
+ if (localCachePath == null) {
27236
+ let hint = `Please update your \x1b[1mruns-on\x1b[0m labels. E.g.:
27237
+
27238
+ \x1b[32mruns-on\x1b[34m:\x1b[0m
27239
+ - \x1b[34mnscloud-ubuntu-22.04-amd64-8x16-\x1b[1mwith-cache\x1b[0m
27240
+ - \x1b[34m\x1b[1mnscloud-cache-size-50gb\x1b[0m
27241
+ - \x1b[34m\x1b[1mnscloud-cache-tag-my-cache-key\x1b[0m
27242
+
27243
+ You can replace \x1b[1mmy-cache-key\x1b[0m with something that represents what you’re storing in the cache.`;
27244
+ if (process.env.NSC_RUNNER_PROFILE_INFO) {
27245
+ hint = "Please enable \x1b[1mCaching\x1b[0m in your runner profile.";
27246
+ }
27247
+ throw new Error(`nscloud-cache-action requires a cache volume to be configured.
27248
+
27249
+ ${hint}
27250
+
27251
+ See also https://namespace.so/docs/features/faster-github-actions#using-a-cache-volume
27238
27252
27239
27253
Are you running in a container? Check out https://namespace.so/docs/actions/nscloud-cache-action#advanced-running-github-jobs-in-containers`);
27240
- }
27241
- core.info(`Found Namespace cross-invocation cache at ${localCachePath}.`);
27242
- const cachePaths = await resolveCachePaths(localCachePath);
27243
- const cacheMisses = await restoreLocalCache(cachePaths);
27244
- const fullHit = cacheMisses.length === 0;
27245
- core.setOutput(Output_CacheHit, fullHit.toString());
27246
- if (!fullHit) {
27247
- core.info(`Some cache paths missing: ${cacheMisses}.`);
27248
- const failOnCacheMiss = core.getBooleanInput(Input_FailOnCacheMiss);
27249
- if (failOnCacheMiss) {
27250
- throw new Error(`Some cache paths missing: ${cacheMisses}.`);
27251
27254
}
27252
- }
27253
- else {
27254
- core.info("All cache paths found and restored." );
27255
- }
27256
- try {
27257
- // Write/update cache volume metadata file
27258
- const metadata = ensureCacheMetadata(localCachePath );
27259
- metadata.updatedAt = new Date().toISOString( );
27260
- metadata.version = 1;
27261
- if (!metadata.userRequest) {
27262
- metadata.userRequest = {};
27255
+ core.info(`Found Namespace cross-invocation cache at ${localCachePath}.`);
27256
+ const cachePaths = await resolveCachePaths(localCachePath);
27257
+ const cacheMisses = await restoreLocalCache(cachePaths );
27258
+ const fullHit = cacheMisses.length === 0;
27259
+ core.setOutput(Output_CacheHit, fullHit.toString());
27260
+ if (!fullHit) {
27261
+ core.info(`Some cache paths missing: ${cacheMisses}.` );
27262
+ const failOnCacheMiss = core.getBooleanInput(Input_FailOnCacheMiss );
27263
+ if (failOnCacheMiss) {
27264
+ throw new Error(`Some cache paths missing: ${cacheMisses}.`);
27265
+ }
27263
27266
}
27264
- for (const p of cachePaths) {
27265
- metadata.userRequest[p.pathInCache] = {
27266
- cacheFramework: p.framework,
27267
- mountTarget: [p.mountTarget],
27268
- source: ActionVersion,
27269
- };
27267
+ else {
27268
+ core.info("All cache paths found and restored.");
27269
+ }
27270
+ try {
27271
+ // Write/update cache volume metadata file
27272
+ const metadata = ensureCacheMetadata(localCachePath);
27273
+ metadata.updatedAt = new Date().toISOString();
27274
+ metadata.version = 1;
27275
+ if (!metadata.userRequest) {
27276
+ metadata.userRequest = {};
27277
+ }
27278
+ for (const p of cachePaths) {
27279
+ metadata.userRequest[p.pathInCache] = {
27280
+ cacheFramework: p.framework,
27281
+ mountTarget: [p.mountTarget],
27282
+ source: ActionVersion,
27283
+ };
27284
+ }
27285
+ writeCacheMetadata(localCachePath, metadata);
27286
+ }
27287
+ catch (e) {
27288
+ core.warning("Failed to record cache metadata.");
27289
+ core.info(e.message);
27270
27290
}
27271
- writeCacheMetadata(localCachePath, metadata);
27291
+ // Save the list of cache paths to actions state for the post-cache action
27292
+ core.saveState(StatePathsKey, cachePaths);
27293
+ const cacheUtilInfo = await getCacheSummaryUtil(localCachePath);
27294
+ core.info(`Total available cache space is ${cacheUtilInfo.size}, and ${cacheUtilInfo.used} have been used.`);
27272
27295
}
27273
- catch (e) {
27274
- core.warning("Failed to record cache metadata.");
27275
- core.info(e.message);
27296
+ catch (error) {
27297
+ // Fail the workflow run if an error occurs
27298
+ if (error instanceof Error)
27299
+ core.setFailed(error.message);
27276
27300
}
27277
- // Save the list of cache paths to actions state for the post-cache action
27278
- core.saveState(StatePathsKey, cachePaths);
27279
- const cacheUtilInfo = await getCacheSummaryUtil(localCachePath);
27280
- core.info(`Total available cache space is ${cacheUtilInfo.size}, and ${cacheUtilInfo.used} have been used.`);
27281
27301
}
27282
27302
async function restoreLocalCache(cachePaths) {
27283
27303
const cacheMisses = [];
0 commit comments