mirror of
https://github.com/DeterminateSystems/magic-nix-cache-action.git
synced 2024-12-26 01:12:17 +01:00
parent
053b0cc1f9
commit
60141574d0
3 changed files with 46 additions and 1 deletions
20
dist/index.js
generated
vendored
20
dist/index.js
generated
vendored
|
@ -95468,6 +95468,7 @@ var ENV_DAEMON_DIR = "MAGIC_NIX_CACHE_DAEMONDIR";
|
|||
var FACT_ENV_VARS_PRESENT = "required_env_vars_present";
|
||||
var FACT_DIFF_STORE_ENABLED = "diff_store";
|
||||
var FACT_NOOP_MODE = "noop_mode";
|
||||
var STATE_ERROR_IN_MAIN = "ERROR_IN_MAIN";
|
||||
var STATE_DAEMONDIR = "MAGIC_NIX_CACHE_DAEMONDIR";
|
||||
var STATE_STARTED = "MAGIC_NIX_CACHE_STARTED";
|
||||
var STARTED_HINT = "true";
|
||||
|
@ -95533,6 +95534,9 @@ var MagicNixCacheAction = class extends DetSysAction {
|
|||
await this.notifyAutoCache();
|
||||
}
|
||||
async post() {
|
||||
if (!this.strictMode && this.mainError) {
|
||||
this.exitWithWarning(this.mainError);
|
||||
}
|
||||
if (this.noopMode) {
|
||||
core.debug(TEXT_NOOP);
|
||||
return;
|
||||
|
@ -95658,6 +95662,7 @@ var MagicNixCacheAction = class extends DetSysAction {
|
|||
if (this.strictMode) {
|
||||
reject(new Error(`error in notifyPromise: ${msg}`));
|
||||
} else {
|
||||
this.setMainError(msg);
|
||||
this.exitWithWarning(`failed to start daemon: ${msg}`);
|
||||
}
|
||||
});
|
||||
|
@ -95673,6 +95678,7 @@ var MagicNixCacheAction = class extends DetSysAction {
|
|||
if (this.strictMode) {
|
||||
reject(new Error(msg));
|
||||
} else {
|
||||
this.setMainError(msg);
|
||||
this.exitWithWarning(`Failed to kill daemon: ${msg}`);
|
||||
}
|
||||
});
|
||||
|
@ -95709,6 +95715,9 @@ var MagicNixCacheAction = class extends DetSysAction {
|
|||
core.warning(
|
||||
`Magic Nix Cache may not be running for this workflow.`
|
||||
);
|
||||
this.setMainError(
|
||||
`Error starting the Magic Nix Cache: ${stringifyError(e)}`
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -95765,6 +95774,17 @@ var MagicNixCacheAction = class extends DetSysAction {
|
|||
core.warning(`strict mode not enabled; exiting`);
|
||||
process.exit(0);
|
||||
}
|
||||
// If the main phase errors, save the state for use in post.
|
||||
// This matters only when strict mode is NOT set.
|
||||
setMainError(msg) {
|
||||
core.saveState(STATE_ERROR_IN_MAIN, msg);
|
||||
}
|
||||
// In the post phase, if the main phase errored, return `true` so that the
|
||||
// phase can be skipped (with a warning).
|
||||
get mainError() {
|
||||
const state = core.getState(STATE_ERROR_IN_MAIN);
|
||||
return state !== "" ? state : void 0;
|
||||
}
|
||||
};
|
||||
function main() {
|
||||
new MagicNixCacheAction().execute();
|
||||
|
|
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
25
src/index.ts
25
src/index.ts
|
@ -18,6 +18,7 @@ const FACT_ENV_VARS_PRESENT = "required_env_vars_present";
|
|||
const FACT_DIFF_STORE_ENABLED = "diff_store";
|
||||
const FACT_NOOP_MODE = "noop_mode";
|
||||
|
||||
const STATE_ERROR_IN_MAIN = "ERROR_IN_MAIN";
|
||||
const STATE_DAEMONDIR = "MAGIC_NIX_CACHE_DAEMONDIR";
|
||||
const STATE_STARTED = "MAGIC_NIX_CACHE_STARTED";
|
||||
const STARTED_HINT = "true";
|
||||
|
@ -106,6 +107,12 @@ class MagicNixCacheAction extends DetSysAction {
|
|||
}
|
||||
|
||||
async post(): Promise<void> {
|
||||
// If strict mode is off and there was an error in main, such as the daemon not starting,
|
||||
// then the post phase is skipped with a warning.
|
||||
if (!this.strictMode && this.mainError) {
|
||||
this.exitWithWarning(this.mainError);
|
||||
}
|
||||
|
||||
if (this.noopMode) {
|
||||
actionsCore.debug(TEXT_NOOP);
|
||||
return;
|
||||
|
@ -265,6 +272,7 @@ class MagicNixCacheAction extends DetSysAction {
|
|||
if (this.strictMode) {
|
||||
reject(new Error(`error in notifyPromise: ${msg}`));
|
||||
} else {
|
||||
this.setMainError(msg);
|
||||
this.exitWithWarning(`failed to start daemon: ${msg}`);
|
||||
}
|
||||
});
|
||||
|
@ -282,6 +290,7 @@ class MagicNixCacheAction extends DetSysAction {
|
|||
if (this.strictMode) {
|
||||
reject(new Error(msg));
|
||||
} else {
|
||||
this.setMainError(msg);
|
||||
this.exitWithWarning(`Failed to kill daemon: ${msg}`);
|
||||
}
|
||||
});
|
||||
|
@ -326,6 +335,9 @@ class MagicNixCacheAction extends DetSysAction {
|
|||
actionsCore.warning(
|
||||
`Magic Nix Cache may not be running for this workflow.`,
|
||||
);
|
||||
this.setMainError(
|
||||
`Error starting the Magic Nix Cache: ${stringifyError(e)}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -391,6 +403,19 @@ class MagicNixCacheAction extends DetSysAction {
|
|||
actionsCore.warning(`strict mode not enabled; exiting`);
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
// If the main phase errors, save the state for use in post.
|
||||
// This matters only when strict mode is NOT set.
|
||||
private setMainError(msg: string): void {
|
||||
actionsCore.saveState(STATE_ERROR_IN_MAIN, msg);
|
||||
}
|
||||
|
||||
// In the post phase, if the main phase errored, return `true` so that the
|
||||
// phase can be skipped (with a warning).
|
||||
private get mainError(): string | undefined {
|
||||
const state = actionsCore.getState(STATE_ERROR_IN_MAIN);
|
||||
return state !== "" ? state : undefined;
|
||||
}
|
||||
}
|
||||
|
||||
function main(): void {
|
||||
|
|
Loading…
Reference in a new issue