mirror of
https://github.com/DeterminateSystems/magic-nix-cache-action.git
synced 2024-12-27 01:30:35 +01:00
Add strict mode
This commit is contained in:
parent
5555b8bb7b
commit
d828acb704
4 changed files with 49 additions and 11 deletions
|
@ -51,6 +51,10 @@ inputs:
|
||||||
source-url:
|
source-url:
|
||||||
description: A URL pointing to a `magic-nix-cache` binary. Overrides all other `source-*` options.
|
description: A URL pointing to a `magic-nix-cache` binary. Overrides all other `source-*` options.
|
||||||
required: false
|
required: false
|
||||||
|
strict-mode:
|
||||||
|
description: "Whether to fail when any errors are thrown. Used only to test the Action; do not set this in your own workflows."
|
||||||
|
default: false
|
||||||
|
required: false
|
||||||
|
|
||||||
runs:
|
runs:
|
||||||
using: "node20"
|
using: "node20"
|
||||||
|
|
25
dist/index.js
generated
vendored
25
dist/index.js
generated
vendored
|
@ -94810,6 +94810,7 @@ var MagicNixCacheAction = class {
|
||||||
idsProjectName: "magic-nix-cache-closure",
|
idsProjectName: "magic-nix-cache-closure",
|
||||||
requireNix: "warn"
|
requireNix: "warn"
|
||||||
});
|
});
|
||||||
|
this.failMode = inputs_exports.getBool("fail-mode");
|
||||||
this.client = got_dist_source.extend({
|
this.client = got_dist_source.extend({
|
||||||
retry: {
|
retry: {
|
||||||
limit: 1,
|
limit: 1,
|
||||||
|
@ -94956,16 +94957,21 @@ var MagicNixCacheAction = class {
|
||||||
notifyPromise.then((_value) => {
|
notifyPromise.then((_value) => {
|
||||||
resolve();
|
resolve();
|
||||||
}).catch((err) => {
|
}).catch((err) => {
|
||||||
reject(new Error(`error in notifyPromise: ${err}`));
|
const msg = `error in notifyPromise: ${err}`;
|
||||||
|
reject(new Error(msg));
|
||||||
|
this.failInFailMode(msg);
|
||||||
});
|
});
|
||||||
daemon.on("exit", async (code, signal) => {
|
daemon.on("exit", async (code, signal) => {
|
||||||
|
let msg;
|
||||||
if (signal) {
|
if (signal) {
|
||||||
reject(new Error(`Daemon was killed by signal ${signal}`));
|
msg = `Daemon was killed by signal ${signal}`;
|
||||||
} else if (code) {
|
} else if (code) {
|
||||||
reject(new Error(`Daemon exited with code ${code}`));
|
msg = `Daemon exited with code ${code}`;
|
||||||
} else {
|
} else {
|
||||||
reject(new Error(`Daemon unexpectedly exited`));
|
msg = "Daemon unexpectedly exited";
|
||||||
}
|
}
|
||||||
|
reject(new Error(msg));
|
||||||
|
this.failInFailMode(msg);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
daemon.unref();
|
daemon.unref();
|
||||||
|
@ -94996,6 +95002,7 @@ var MagicNixCacheAction = class {
|
||||||
core.info(`Error marking the workflow as started:`);
|
core.info(`Error marking the workflow as started:`);
|
||||||
core.info((0,external_node_util_.inspect)(e));
|
core.info((0,external_node_util_.inspect)(e));
|
||||||
core.info(`Magic Nix Cache may not be running for this workflow.`);
|
core.info(`Magic Nix Cache may not be running for this workflow.`);
|
||||||
|
this.failInFailMode(`Magic Nix Cache failed to start: ${(0,external_node_util_.inspect)(e)}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
async tearDownAutoCache() {
|
async tearDownAutoCache() {
|
||||||
|
@ -95007,7 +95014,9 @@ var MagicNixCacheAction = class {
|
||||||
const pid = parseInt(await promises_namespaceObject.readFile(pidFile, { encoding: "ascii" }));
|
const pid = parseInt(await promises_namespaceObject.readFile(pidFile, { encoding: "ascii" }));
|
||||||
core.debug(`found daemon pid: ${pid}`);
|
core.debug(`found daemon pid: ${pid}`);
|
||||||
if (!pid) {
|
if (!pid) {
|
||||||
throw new Error("magic-nix-cache did not start successfully");
|
const msg = "magic-nix-cache did not start successfully";
|
||||||
|
this.failInFailMode(msg);
|
||||||
|
throw new Error(msg);
|
||||||
}
|
}
|
||||||
const log = tailLog(this.daemonDir);
|
const log = tailLog(this.daemonDir);
|
||||||
try {
|
try {
|
||||||
|
@ -95024,6 +95033,7 @@ var MagicNixCacheAction = class {
|
||||||
process.kill(pid, "SIGTERM");
|
process.kill(pid, "SIGTERM");
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (typeof e === "object" && e && "code" in e && e.code !== "ESRCH") {
|
if (typeof e === "object" && e && "code" in e && e.code !== "ESRCH") {
|
||||||
|
this.failInFailMode(e.toString());
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
|
@ -95034,6 +95044,11 @@ var MagicNixCacheAction = class {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
failInFailMode(msg) {
|
||||||
|
if (this.failMode) {
|
||||||
|
core.setFailed(`fail-mode error: ${msg}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
function main() {
|
function main() {
|
||||||
const cacheAction = new MagicNixCacheAction();
|
const cacheAction = new MagicNixCacheAction();
|
||||||
|
|
2
dist/index.js.map
generated
vendored
2
dist/index.js.map
generated
vendored
File diff suppressed because one or more lines are too long
29
src/index.ts
29
src/index.ts
|
@ -28,6 +28,7 @@ const TEXT_TRUST_UNKNOWN =
|
||||||
|
|
||||||
class MagicNixCacheAction {
|
class MagicNixCacheAction {
|
||||||
idslib: IdsToolbox;
|
idslib: IdsToolbox;
|
||||||
|
private strictMode: boolean;
|
||||||
private client: Got;
|
private client: Got;
|
||||||
|
|
||||||
noopMode: boolean;
|
noopMode: boolean;
|
||||||
|
@ -42,6 +43,8 @@ class MagicNixCacheAction {
|
||||||
requireNix: "warn",
|
requireNix: "warn",
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.strictMode = inputs.getBool("strict-mode");
|
||||||
|
|
||||||
this.client = got.extend({
|
this.client = got.extend({
|
||||||
retry: {
|
retry: {
|
||||||
limit: 1,
|
limit: 1,
|
||||||
|
@ -224,16 +227,21 @@ class MagicNixCacheAction {
|
||||||
})
|
})
|
||||||
// eslint-disable-next-line github/no-then
|
// eslint-disable-next-line github/no-then
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
reject(new Error(`error in notifyPromise: ${err}`));
|
const msg = `error in notifyPromise: ${err}`;
|
||||||
|
reject(new Error(msg));
|
||||||
|
this.failInStrictMode(msg);
|
||||||
});
|
});
|
||||||
daemon.on("exit", async (code, signal) => {
|
daemon.on("exit", async (code, signal) => {
|
||||||
|
let msg: string;
|
||||||
if (signal) {
|
if (signal) {
|
||||||
reject(new Error(`Daemon was killed by signal ${signal}`));
|
msg = `Daemon was killed by signal ${signal}`;
|
||||||
} else if (code) {
|
} else if (code) {
|
||||||
reject(new Error(`Daemon exited with code ${code}`));
|
msg = `Daemon exited with code ${code}`;
|
||||||
} else {
|
} else {
|
||||||
reject(new Error(`Daemon unexpectedly exited`));
|
msg = "Daemon unexpectedly exited";
|
||||||
}
|
}
|
||||||
|
reject(new Error(msg));
|
||||||
|
this.failInStrictMode(msg);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -274,6 +282,8 @@ class MagicNixCacheAction {
|
||||||
actionsCore.info(`Error marking the workflow as started:`);
|
actionsCore.info(`Error marking the workflow as started:`);
|
||||||
actionsCore.info(inspect(e));
|
actionsCore.info(inspect(e));
|
||||||
actionsCore.info(`Magic Nix Cache may not be running for this workflow.`);
|
actionsCore.info(`Magic Nix Cache may not be running for this workflow.`);
|
||||||
|
|
||||||
|
this.failInStrictMode(`Magic Nix Cache failed to start: ${inspect(e)}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -287,7 +297,9 @@ class MagicNixCacheAction {
|
||||||
const pid = parseInt(await fs.readFile(pidFile, { encoding: "ascii" }));
|
const pid = parseInt(await fs.readFile(pidFile, { encoding: "ascii" }));
|
||||||
actionsCore.debug(`found daemon pid: ${pid}`);
|
actionsCore.debug(`found daemon pid: ${pid}`);
|
||||||
if (!pid) {
|
if (!pid) {
|
||||||
throw new Error("magic-nix-cache did not start successfully");
|
const msg = "magic-nix-cache did not start successfully";
|
||||||
|
this.failInStrictMode(msg);
|
||||||
|
throw new Error(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
const log = tailLog(this.daemonDir);
|
const log = tailLog(this.daemonDir);
|
||||||
|
@ -309,6 +321,7 @@ class MagicNixCacheAction {
|
||||||
process.kill(pid, "SIGTERM");
|
process.kill(pid, "SIGTERM");
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (typeof e === "object" && e && "code" in e && e.code !== "ESRCH") {
|
if (typeof e === "object" && e && "code" in e && e.code !== "ESRCH") {
|
||||||
|
this.failInStrictMode(e.toString());
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
|
@ -319,6 +332,12 @@ class MagicNixCacheAction {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private failInStrictMode(msg: string): void {
|
||||||
|
if (this.strictMode) {
|
||||||
|
actionsCore.setFailed(`strict mode error: ${msg}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function main(): void {
|
function main(): void {
|
||||||
|
|
Loading…
Reference in a new issue