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

34
dist/index.js generated vendored
View file

@ -95483,6 +95483,7 @@ var MagicNixCacheAction = class extends DetSysAction {
requireNix: "warn",
diagnosticsSuffix: "perf"
});
this.errorInMain = false;
this.hostAndPort = inputs_exports.getString("listen");
this.diffStore = inputs_exports.getBool("diff-store");
this.addFact(FACT_DIFF_STORE_ENABLED, this.diffStore);
@ -95533,17 +95534,21 @@ var MagicNixCacheAction = class extends DetSysAction {
await this.notifyAutoCache();
}
async post() {
if (this.noopMode) {
core.debug(TEXT_NOOP);
return;
if (!this.strictMode && this.errorInMain) {
this.exitWithWarning(`skipping post phase due to error in main phase`);
} else {
if (this.noopMode) {
core.debug(TEXT_NOOP);
return;
}
if (this.nixStoreTrust === "untrusted") {
core.debug(TEXT_TRUST_UNTRUSTED);
return;
} else if (this.nixStoreTrust === "unknown") {
core.debug(TEXT_TRUST_UNKNOWN);
}
await this.tearDownAutoCache();
}
if (this.nixStoreTrust === "untrusted") {
core.debug(TEXT_TRUST_UNTRUSTED);
return;
} else if (this.nixStoreTrust === "unknown") {
core.debug(TEXT_TRUST_UNKNOWN);
}
await this.tearDownAutoCache();
}
async setUpAutoCache() {
const requiredEnv = [
@ -95658,6 +95663,7 @@ var MagicNixCacheAction = class extends DetSysAction {
if (this.strictMode) {
reject(new Error(`error in notifyPromise: ${msg}`));
} else {
this.errorInMain = true;
this.exitWithWarning(`failed to start daemon: ${msg}`);
}
});
@ -95670,7 +95676,12 @@ var MagicNixCacheAction = class extends DetSysAction {
} else {
msg = "Daemon unexpectedly exited";
}
reject(new Error(msg));
if (this.strictMode) {
reject(new Error(msg));
} else {
this.errorInMain = true;
this.exitWithWarning(`Failed to kill daemon: ${msg}`);
}
});
});
daemon.unref();
@ -95700,6 +95711,7 @@ var MagicNixCacheAction = class extends DetSysAction {
if (this.strictMode) {
core.setFailed(`Magic Nix Cache failed to start: ${(0,external_node_util_.inspect)(e)}`);
} else {
this.errorInMain = true;
core.warning(`Error marking the workflow as started:`);
core.warning((0,external_node_util_.inspect)(e));
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.";
class MagicNixCacheAction extends DetSysAction {
private errorInMain: boolean;
private hostAndPort: string;
private diffStore: boolean;
private httpClient: Got;
@ -46,6 +47,7 @@ class MagicNixCacheAction extends DetSysAction {
diagnosticsSuffix: "perf",
});
this.errorInMain = false;
this.hostAndPort = inputs.getString("listen");
this.diffStore = inputs.getBool("diff-store");
@ -106,19 +108,23 @@ class MagicNixCacheAction extends DetSysAction {
}
async post(): Promise<void> {
if (this.noopMode) {
actionsCore.debug(TEXT_NOOP);
return;
}
if (!this.strictMode && this.errorInMain) {
this.exitWithWarning(`skipping post phase due to error in main phase`);
} else {
if (this.noopMode) {
actionsCore.debug(TEXT_NOOP);
return;
}
if (this.nixStoreTrust === "untrusted") {
actionsCore.debug(TEXT_TRUST_UNTRUSTED);
return;
} else if (this.nixStoreTrust === "unknown") {
actionsCore.debug(TEXT_TRUST_UNKNOWN);
}
if (this.nixStoreTrust === "untrusted") {
actionsCore.debug(TEXT_TRUST_UNTRUSTED);
return;
} else if (this.nixStoreTrust === "unknown") {
actionsCore.debug(TEXT_TRUST_UNKNOWN);
}
await this.tearDownAutoCache();
await this.tearDownAutoCache();
}
}
async setUpAutoCache(): Promise<void> {
@ -265,9 +271,11 @@ class MagicNixCacheAction extends DetSysAction {
if (this.strictMode) {
reject(new Error(`error in notifyPromise: ${msg}`));
} else {
this.errorInMain = true;
this.exitWithWarning(`failed to start daemon: ${msg}`);
}
});
daemon.on("exit", async (code, signal) => {
let msg: string;
if (signal) {
@ -277,7 +285,13 @@ class MagicNixCacheAction extends DetSysAction {
} else {
msg = "Daemon unexpectedly exited";
}
reject(new Error(msg));
if (this.strictMode) {
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) {
actionsCore.setFailed(`Magic Nix Cache failed to start: ${inspect(e)}`);
} else {
this.errorInMain = true;
actionsCore.warning(`Error marking the workflow as started:`);
actionsCore.warning(inspect(e));
actionsCore.warning(