Skip post phase with warning on error in main

This commit is contained in:
Luc Perkins 2024-06-03 15:37:36 -07:00
parent b2e770e214
commit 0cb62a86ec
No known key found for this signature in database
GPG key ID: 16DB1108FB591835
3 changed files with 51 additions and 24 deletions

12
dist/index.js generated vendored
View file

@ -95483,6 +95483,7 @@ var MagicNixCacheAction = class extends DetSysAction {
requireNix: "warn", requireNix: "warn",
diagnosticsSuffix: "perf" diagnosticsSuffix: "perf"
}); });
this.errorInMain = false;
this.hostAndPort = inputs_exports.getString("listen"); this.hostAndPort = inputs_exports.getString("listen");
this.diffStore = inputs_exports.getBool("diff-store"); this.diffStore = inputs_exports.getBool("diff-store");
this.addFact(FACT_DIFF_STORE_ENABLED, this.diffStore); this.addFact(FACT_DIFF_STORE_ENABLED, this.diffStore);
@ -95533,6 +95534,9 @@ var MagicNixCacheAction = class extends DetSysAction {
await this.notifyAutoCache(); await this.notifyAutoCache();
} }
async post() { async post() {
if (!this.strictMode && this.errorInMain) {
this.exitWithWarning(`skipping post phase due to error in main phase`);
} else {
if (this.noopMode) { if (this.noopMode) {
core.debug(TEXT_NOOP); core.debug(TEXT_NOOP);
return; return;
@ -95545,6 +95549,7 @@ var MagicNixCacheAction = class extends DetSysAction {
} }
await this.tearDownAutoCache(); await this.tearDownAutoCache();
} }
}
async setUpAutoCache() { async setUpAutoCache() {
const requiredEnv = [ const requiredEnv = [
"ACTIONS_CACHE_URL", "ACTIONS_CACHE_URL",
@ -95658,6 +95663,7 @@ var MagicNixCacheAction = class extends DetSysAction {
if (this.strictMode) { if (this.strictMode) {
reject(new Error(`error in notifyPromise: ${msg}`)); reject(new Error(`error in notifyPromise: ${msg}`));
} else { } else {
this.errorInMain = true;
this.exitWithWarning(`failed to start daemon: ${msg}`); this.exitWithWarning(`failed to start daemon: ${msg}`);
} }
}); });
@ -95670,7 +95676,12 @@ var MagicNixCacheAction = class extends DetSysAction {
} else { } else {
msg = "Daemon unexpectedly exited"; msg = "Daemon unexpectedly exited";
} }
if (this.strictMode) {
reject(new Error(msg)); reject(new Error(msg));
} else {
this.errorInMain = true;
this.exitWithWarning(`Failed to kill daemon: ${msg}`);
}
}); });
}); });
daemon.unref(); daemon.unref();
@ -95700,6 +95711,7 @@ var MagicNixCacheAction = class extends DetSysAction {
if (this.strictMode) { if (this.strictMode) {
core.setFailed(`Magic Nix Cache failed to start: ${(0,external_node_util_.inspect)(e)}`); core.setFailed(`Magic Nix Cache failed to start: ${(0,external_node_util_.inspect)(e)}`);
} else { } else {
this.errorInMain = true;
core.warning(`Error marking the workflow as started:`); core.warning(`Error marking the workflow as started:`);
core.warning((0,external_node_util_.inspect)(e)); core.warning((0,external_node_util_.inspect)(e));
core.warning( core.warning(

2
dist/index.js.map generated vendored

File diff suppressed because one or more lines are too long

View file

@ -30,6 +30,7 @@ const TEXT_TRUST_UNKNOWN =
"The Nix daemon may not consider the user running this workflow to be trusted. Magic Nix Cache may not start correctly."; "The Nix daemon may not consider the user running this workflow to be trusted. Magic Nix Cache may not start correctly.";
class MagicNixCacheAction extends DetSysAction { class MagicNixCacheAction extends DetSysAction {
private errorInMain: boolean;
private hostAndPort: string; private hostAndPort: string;
private diffStore: boolean; private diffStore: boolean;
private httpClient: Got; private httpClient: Got;
@ -46,6 +47,7 @@ class MagicNixCacheAction extends DetSysAction {
diagnosticsSuffix: "perf", diagnosticsSuffix: "perf",
}); });
this.errorInMain = false;
this.hostAndPort = inputs.getString("listen"); this.hostAndPort = inputs.getString("listen");
this.diffStore = inputs.getBool("diff-store"); this.diffStore = inputs.getBool("diff-store");
@ -106,6 +108,9 @@ class MagicNixCacheAction extends DetSysAction {
} }
async post(): Promise<void> { async post(): Promise<void> {
if (!this.strictMode && this.errorInMain) {
this.exitWithWarning(`skipping post phase due to error in main phase`);
} else {
if (this.noopMode) { if (this.noopMode) {
actionsCore.debug(TEXT_NOOP); actionsCore.debug(TEXT_NOOP);
return; return;
@ -120,6 +125,7 @@ class MagicNixCacheAction extends DetSysAction {
await this.tearDownAutoCache(); await this.tearDownAutoCache();
} }
}
async setUpAutoCache(): Promise<void> { async setUpAutoCache(): Promise<void> {
const requiredEnv = [ const requiredEnv = [
@ -265,9 +271,11 @@ class MagicNixCacheAction extends DetSysAction {
if (this.strictMode) { if (this.strictMode) {
reject(new Error(`error in notifyPromise: ${msg}`)); reject(new Error(`error in notifyPromise: ${msg}`));
} else { } else {
this.errorInMain = true;
this.exitWithWarning(`failed to start daemon: ${msg}`); this.exitWithWarning(`failed to start daemon: ${msg}`);
} }
}); });
daemon.on("exit", async (code, signal) => { daemon.on("exit", async (code, signal) => {
let msg: string; let msg: string;
if (signal) { if (signal) {
@ -277,7 +285,13 @@ class MagicNixCacheAction extends DetSysAction {
} else { } else {
msg = "Daemon unexpectedly exited"; msg = "Daemon unexpectedly exited";
} }
if (this.strictMode) {
reject(new Error(msg)); reject(new Error(msg));
} else {
this.errorInMain = true;
this.exitWithWarning(`Failed to kill daemon: ${msg}`);
}
}); });
}); });
@ -315,6 +329,7 @@ class MagicNixCacheAction extends DetSysAction {
if (this.strictMode) { if (this.strictMode) {
actionsCore.setFailed(`Magic Nix Cache failed to start: ${inspect(e)}`); actionsCore.setFailed(`Magic Nix Cache failed to start: ${inspect(e)}`);
} else { } else {
this.errorInMain = true;
actionsCore.warning(`Error marking the workflow as started:`); actionsCore.warning(`Error marking the workflow as started:`);
actionsCore.warning(inspect(e)); actionsCore.warning(inspect(e));
actionsCore.warning( actionsCore.warning(