mirror of
https://github.com/DeterminateSystems/magic-nix-cache-action.git
synced 2024-12-27 01:30:35 +01:00
Don't be weird if the daemon is already running
This commit is contained in:
parent
7a12393ae8
commit
9f35ea0aec
3 changed files with 80 additions and 8 deletions
45
dist/index.js
generated
vendored
45
dist/index.js
generated
vendored
|
@ -94745,8 +94745,9 @@ async function flakeHubLogin(netrc) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var ENV_CACHE_DAEMONDIR = "MAGIC_NIX_CACHE_DAEMONDIR";
|
var ENV_DAEMON_DIR = "MAGIC_NIX_CACHE_DAEMONDIR";
|
||||||
var ENV_CACHE_STARTED = "MAGIC_NIX_CACHE_STARTED";
|
var STATE_DAEMONDIR = "MAGIC_NIX_CACHE_DAEMONDIR";
|
||||||
|
var STATE_STARTED = "MAGIC_NIX_CACHE_STARTED";
|
||||||
var STARTED_HINT = "true";
|
var STARTED_HINT = "true";
|
||||||
var MagicNixCacheAction = class {
|
var MagicNixCacheAction = class {
|
||||||
constructor() {
|
constructor() {
|
||||||
|
@ -94771,14 +94772,21 @@ var MagicNixCacheAction = class {
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
this.daemonStarted = process.env[ENV_CACHE_STARTED] === STARTED_HINT;
|
this.daemonStarted = core.getState(STATE_STARTED) === STARTED_HINT;
|
||||||
if (process.env[ENV_CACHE_DAEMONDIR]) {
|
if (core.getState(STATE_DAEMONDIR) !== "") {
|
||||||
this.daemonDir = process.env[ENV_CACHE_DAEMONDIR];
|
this.daemonDir = core.getState(STATE_DAEMONDIR);
|
||||||
} else {
|
} else {
|
||||||
this.daemonDir = this.idslib.getTemporaryName();
|
this.daemonDir = this.idslib.getTemporaryName();
|
||||||
(0,external_node_fs_namespaceObject.mkdirSync)(this.daemonDir);
|
(0,external_node_fs_namespaceObject.mkdirSync)(this.daemonDir);
|
||||||
core.exportVariable(ENV_CACHE_DAEMONDIR, this.daemonDir);
|
core.saveState(STATE_DAEMONDIR, this.daemonDir);
|
||||||
}
|
}
|
||||||
|
if (process.env[ENV_DAEMON_DIR] === void 0) {
|
||||||
|
this.noopMode = false;
|
||||||
|
core.exportVariable(ENV_DAEMON_DIR, this.daemonDir);
|
||||||
|
} else {
|
||||||
|
this.noopMode = process.env[ENV_DAEMON_DIR] !== this.daemonDir;
|
||||||
|
}
|
||||||
|
this.idslib.addFact("noop_mode", this.noopMode);
|
||||||
this.idslib.stapleFile(
|
this.idslib.stapleFile(
|
||||||
"daemon.log",
|
"daemon.log",
|
||||||
external_node_path_namespaceObject.join(this.daemonDir, "daemon.log")
|
external_node_path_namespaceObject.join(this.daemonDir, "daemon.log")
|
||||||
|
@ -94799,14 +94807,25 @@ var MagicNixCacheAction = class {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
this.idslib.addFact("authenticated_env", !anyMissing);
|
||||||
if (anyMissing) {
|
if (anyMissing) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (this.noopMode) {
|
||||||
|
core.warning(
|
||||||
|
"Magic Nix Cache is already running, this workflow job is in noop mode."
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (this.daemonStarted) {
|
||||||
|
core.debug("Already started.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
core.debug(
|
core.debug(
|
||||||
`GitHub Action Cache URL: ${process.env["ACTIONS_CACHE_URL"]}`
|
`GitHub Action Cache URL: ${process.env["ACTIONS_CACHE_URL"]}`
|
||||||
);
|
);
|
||||||
this.daemonStarted = true;
|
this.daemonStarted = true;
|
||||||
core.exportVariable(ENV_CACHE_STARTED, STARTED_HINT);
|
core.saveState(STATE_STARTED, STARTED_HINT);
|
||||||
const sourceBinary = inputs_exports.getStringOrNull("source-binary");
|
const sourceBinary = inputs_exports.getStringOrNull("source-binary");
|
||||||
const daemonBin = sourceBinary !== null ? sourceBinary : await this.fetchAutoCacher();
|
const daemonBin = sourceBinary !== null ? sourceBinary : await this.fetchAutoCacher();
|
||||||
let runEnv;
|
let runEnv;
|
||||||
|
@ -94917,6 +94936,12 @@ var MagicNixCacheAction = class {
|
||||||
return `${lastPath}/bin/magic-nix-cache`;
|
return `${lastPath}/bin/magic-nix-cache`;
|
||||||
}
|
}
|
||||||
async notifyAutoCache() {
|
async notifyAutoCache() {
|
||||||
|
if (this.noopMode) {
|
||||||
|
core.warning(
|
||||||
|
"Magic Nix Cache is already running, this workflow job is in noop mode."
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (!this.daemonStarted) {
|
if (!this.daemonStarted) {
|
||||||
core.debug("magic-nix-cache not started - Skipping");
|
core.debug("magic-nix-cache not started - Skipping");
|
||||||
return;
|
return;
|
||||||
|
@ -94933,6 +94958,12 @@ var MagicNixCacheAction = class {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
async tearDownAutoCache() {
|
async tearDownAutoCache() {
|
||||||
|
if (this.noopMode) {
|
||||||
|
core.warning(
|
||||||
|
"Magic Nix Cache is already running, this workflow job is in noop mode."
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (!this.daemonStarted) {
|
if (!this.daemonStarted) {
|
||||||
core.debug("magic-nix-cache not started - Skipping");
|
core.debug("magic-nix-cache not started - Skipping");
|
||||||
return;
|
return;
|
||||||
|
|
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
41
src/index.ts
41
src/index.ts
|
@ -10,6 +10,11 @@ import * as os from "node:os";
|
||||||
import * as path from "node:path";
|
import * as path from "node:path";
|
||||||
import { inspect, promisify } from "node:util";
|
import { inspect, promisify } from "node:util";
|
||||||
|
|
||||||
|
// The ENV_DAEMON_DIR is intended to determine if we "own" the daemon or not,
|
||||||
|
// in the case that a user has put the magic nix cache into their workflow
|
||||||
|
// twice.
|
||||||
|
const ENV_DAEMON_DIR = "MAGIC_NIX_CACHE_DAEMONDIR";
|
||||||
|
|
||||||
const STATE_DAEMONDIR = "MAGIC_NIX_CACHE_DAEMONDIR";
|
const STATE_DAEMONDIR = "MAGIC_NIX_CACHE_DAEMONDIR";
|
||||||
const STATE_STARTED = "MAGIC_NIX_CACHE_STARTED";
|
const STATE_STARTED = "MAGIC_NIX_CACHE_STARTED";
|
||||||
const STARTED_HINT = "true";
|
const STARTED_HINT = "true";
|
||||||
|
@ -18,6 +23,7 @@ class MagicNixCacheAction {
|
||||||
idslib: IdsToolbox;
|
idslib: IdsToolbox;
|
||||||
private client: Got;
|
private client: Got;
|
||||||
|
|
||||||
|
private noopMode: boolean;
|
||||||
private daemonDir: string;
|
private daemonDir: string;
|
||||||
private daemonStarted: boolean;
|
private daemonStarted: boolean;
|
||||||
|
|
||||||
|
@ -55,6 +61,14 @@ class MagicNixCacheAction {
|
||||||
actionsCore.saveState(STATE_DAEMONDIR, this.daemonDir);
|
actionsCore.saveState(STATE_DAEMONDIR, this.daemonDir);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (process.env[ENV_DAEMON_DIR] === undefined) {
|
||||||
|
this.noopMode = false;
|
||||||
|
actionsCore.exportVariable(ENV_DAEMON_DIR, this.daemonDir);
|
||||||
|
} else {
|
||||||
|
this.noopMode = process.env[ENV_DAEMON_DIR] !== this.daemonDir;
|
||||||
|
}
|
||||||
|
this.idslib.addFact("noop_mode", this.noopMode);
|
||||||
|
|
||||||
this.idslib.stapleFile(
|
this.idslib.stapleFile(
|
||||||
"daemon.log",
|
"daemon.log",
|
||||||
path.join(this.daemonDir, "daemon.log"),
|
path.join(this.daemonDir, "daemon.log"),
|
||||||
|
@ -78,10 +92,23 @@ class MagicNixCacheAction {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.idslib.addFact("authenticated_env", !anyMissing);
|
||||||
if (anyMissing) {
|
if (anyMissing) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.noopMode) {
|
||||||
|
actionsCore.warning(
|
||||||
|
"Magic Nix Cache is already running, this workflow job is in noop mode.",
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.daemonStarted) {
|
||||||
|
actionsCore.debug("Already started.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
actionsCore.debug(
|
actionsCore.debug(
|
||||||
`GitHub Action Cache URL: ${process.env["ACTIONS_CACHE_URL"]}`,
|
`GitHub Action Cache URL: ${process.env["ACTIONS_CACHE_URL"]}`,
|
||||||
);
|
);
|
||||||
|
@ -230,6 +257,13 @@ class MagicNixCacheAction {
|
||||||
}
|
}
|
||||||
|
|
||||||
async notifyAutoCache(): Promise<void> {
|
async notifyAutoCache(): Promise<void> {
|
||||||
|
if (this.noopMode) {
|
||||||
|
actionsCore.warning(
|
||||||
|
"Magic Nix Cache is already running, this workflow job is in noop mode.",
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!this.daemonStarted) {
|
if (!this.daemonStarted) {
|
||||||
actionsCore.debug("magic-nix-cache not started - Skipping");
|
actionsCore.debug("magic-nix-cache not started - Skipping");
|
||||||
return;
|
return;
|
||||||
|
@ -250,6 +284,13 @@ class MagicNixCacheAction {
|
||||||
}
|
}
|
||||||
|
|
||||||
async tearDownAutoCache(): Promise<void> {
|
async tearDownAutoCache(): Promise<void> {
|
||||||
|
if (this.noopMode) {
|
||||||
|
actionsCore.warning(
|
||||||
|
"Magic Nix Cache is already running, this workflow job is in noop mode.",
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!this.daemonStarted) {
|
if (!this.daemonStarted) {
|
||||||
actionsCore.debug("magic-nix-cache not started - Skipping");
|
actionsCore.debug("magic-nix-cache not started - Skipping");
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Reference in a new issue