mirror of
https://github.com/DeterminateSystems/magic-nix-cache-action.git
synced 2024-12-23 13:32:03 +01:00
Extract out the daemonDir into a class member
This commit is contained in:
parent
6e8580ecdc
commit
4ae13c51d8
5 changed files with 110 additions and 29 deletions
87
dist/index.js
generated
vendored
87
dist/index.js
generated
vendored
|
@ -93750,7 +93750,9 @@ const got = source_create(defaults);
|
||||||
|
|
||||||
;// CONCATENATED MODULE: external "node:stream/promises"
|
;// CONCATENATED MODULE: external "node:stream/promises"
|
||||||
const external_node_stream_promises_namespaceObject = __WEBPACK_EXTERNAL_createRequire(import.meta.url)("node:stream/promises");
|
const external_node_stream_promises_namespaceObject = __WEBPACK_EXTERNAL_createRequire(import.meta.url)("node:stream/promises");
|
||||||
;// CONCATENATED MODULE: ./node_modules/.pnpm/github.com+DeterminateSystems+detsys-ts@5abcb239472d24b114a53f70800f0e42fc30819c_ey4bwtjkop43mcem42nicbf3we/node_modules/detsys-ts/dist/index.js
|
;// CONCATENATED MODULE: external "node:zlib"
|
||||||
|
const external_node_zlib_namespaceObject = __WEBPACK_EXTERNAL_createRequire(import.meta.url)("node:zlib");
|
||||||
|
;// CONCATENATED MODULE: ./node_modules/.pnpm/github.com+DeterminateSystems+detsys-ts@3baa96b315ee9f6b26033191a123eb9015522791_2fnsfzpup2itrpjvndt6evj3qu/node_modules/detsys-ts/dist/index.js
|
||||||
var __defProp = Object.defineProperty;
|
var __defProp = Object.defineProperty;
|
||||||
var __export = (target, all) => {
|
var __export = (target, all) => {
|
||||||
for (var name in all)
|
for (var name in all)
|
||||||
|
@ -94096,17 +94098,27 @@ function getNixPlatform(archOs) {
|
||||||
// src/inputs.ts
|
// src/inputs.ts
|
||||||
var inputs_exports = {};
|
var inputs_exports = {};
|
||||||
__export(inputs_exports, {
|
__export(inputs_exports, {
|
||||||
|
getArrayOfStrings: () => getArrayOfStrings,
|
||||||
getBool: () => getBool,
|
getBool: () => getBool,
|
||||||
getMultilineStringOrNull: () => getMultilineStringOrNull,
|
getMultilineStringOrNull: () => getMultilineStringOrNull,
|
||||||
getNumberOrNull: () => getNumberOrNull,
|
getNumberOrNull: () => getNumberOrNull,
|
||||||
getString: () => getString,
|
getString: () => getString,
|
||||||
getStringOrNull: () => getStringOrNull,
|
getStringOrNull: () => getStringOrNull,
|
||||||
getStringOrUndefined: () => getStringOrUndefined
|
getStringOrUndefined: () => getStringOrUndefined,
|
||||||
|
handleString: () => handleString
|
||||||
});
|
});
|
||||||
|
|
||||||
var getBool = (name) => {
|
var getBool = (name) => {
|
||||||
return core.getBooleanInput(name);
|
return core.getBooleanInput(name);
|
||||||
};
|
};
|
||||||
|
var getArrayOfStrings = (name, separator) => {
|
||||||
|
const original = getString(name);
|
||||||
|
return handleString(original, separator);
|
||||||
|
};
|
||||||
|
var handleString = (input, separator) => {
|
||||||
|
const sepChar = separator === "comma" ? "," : /\s+/;
|
||||||
|
return input.trim().split(sepChar).map((s) => s.trim());
|
||||||
|
};
|
||||||
var getMultilineStringOrNull = (name) => {
|
var getMultilineStringOrNull = (name) => {
|
||||||
const value = core.getMultilineInput(name);
|
const value = core.getMultilineInput(name);
|
||||||
if (value.length === 0) {
|
if (value.length === 0) {
|
||||||
|
@ -94186,18 +94198,24 @@ function constructSourceParameters(legacyPrefix) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var DEFAULT_IDS_HOST = "https://install.determinate.systems";
|
var DEFAULT_IDS_HOST = "https://install.determinate.systems";
|
||||||
var IDS_HOST = process.env["IDS_HOST"] ?? DEFAULT_IDS_HOST;
|
var IDS_HOST = process.env["IDS_HOST"] ?? DEFAULT_IDS_HOST;
|
||||||
var EVENT_EXCEPTION = "exception";
|
var EVENT_EXCEPTION = "exception";
|
||||||
var EVENT_ARTIFACT_CACHE_HIT = "artifact_cache_hit";
|
var EVENT_ARTIFACT_CACHE_HIT = "artifact_cache_hit";
|
||||||
var EVENT_ARTIFACT_CACHE_MISS = "artifact_cache_miss";
|
var EVENT_ARTIFACT_CACHE_MISS = "artifact_cache_miss";
|
||||||
|
var EVENT_ARTIFACT_CACHE_PERSIST = "artifact_cache_persist";
|
||||||
var FACT_ENDED_WITH_EXCEPTION = "ended_with_exception";
|
var FACT_ENDED_WITH_EXCEPTION = "ended_with_exception";
|
||||||
var FACT_FINAL_EXCEPTION = "final_exception";
|
var FACT_FINAL_EXCEPTION = "final_exception";
|
||||||
|
var FACT_SOURCE_URL = "source_url";
|
||||||
|
var FACT_SOURCE_URL_ETAG = "source_url_etag";
|
||||||
var IdsToolbox = class {
|
var IdsToolbox = class {
|
||||||
constructor(actionOptions) {
|
constructor(actionOptions) {
|
||||||
this.actionOptions = makeOptionsConfident(actionOptions);
|
this.actionOptions = makeOptionsConfident(actionOptions);
|
||||||
this.hookMain = void 0;
|
this.hookMain = void 0;
|
||||||
this.hookPost = void 0;
|
this.hookPost = void 0;
|
||||||
|
this.exceptionAttachments = /* @__PURE__ */ new Map();
|
||||||
this.events = [];
|
this.events = [];
|
||||||
this.client = got_dist_source.extend({
|
this.client = got_dist_source.extend({
|
||||||
retry: {
|
retry: {
|
||||||
|
@ -94276,6 +94294,10 @@ var IdsToolbox = class {
|
||||||
);
|
);
|
||||||
this.recordEvent(`begin_${this.executionPhase}`);
|
this.recordEvent(`begin_${this.executionPhase}`);
|
||||||
}
|
}
|
||||||
|
// Attach a file to the diagnostics data in error conditions.
|
||||||
|
stapleFile(name, location) {
|
||||||
|
this.exceptionAttachments.set(name, location);
|
||||||
|
}
|
||||||
onMain(callback) {
|
onMain(callback) {
|
||||||
this.hookMain = callback;
|
this.hookMain = callback;
|
||||||
}
|
}
|
||||||
|
@ -94288,6 +94310,9 @@ var IdsToolbox = class {
|
||||||
process.exitCode = 1;
|
process.exitCode = 1;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
stringifyError(error2) {
|
||||||
|
return error2 instanceof Error || typeof error2 == "string" ? error2.toString() : JSON.stringify(error2);
|
||||||
|
}
|
||||||
async executeAsync() {
|
async executeAsync() {
|
||||||
try {
|
try {
|
||||||
process.env.DETSYS_CORRELATION = JSON.stringify(
|
process.env.DETSYS_CORRELATION = JSON.stringify(
|
||||||
|
@ -94305,14 +94330,29 @@ var IdsToolbox = class {
|
||||||
this.addFact(FACT_ENDED_WITH_EXCEPTION, false);
|
this.addFact(FACT_ENDED_WITH_EXCEPTION, false);
|
||||||
} catch (error2) {
|
} catch (error2) {
|
||||||
this.addFact(FACT_ENDED_WITH_EXCEPTION, true);
|
this.addFact(FACT_ENDED_WITH_EXCEPTION, true);
|
||||||
const reportable = error2 instanceof Error || typeof error2 == "string" ? error2.toString() : JSON.stringify(error2);
|
const reportable = this.stringifyError(error2);
|
||||||
this.addFact(FACT_FINAL_EXCEPTION, reportable);
|
this.addFact(FACT_FINAL_EXCEPTION, reportable);
|
||||||
if (this.executionPhase === "post") {
|
if (this.executionPhase === "post") {
|
||||||
core.warning(reportable);
|
core.warning(reportable);
|
||||||
} else {
|
} else {
|
||||||
core.setFailed(reportable);
|
core.setFailed(reportable);
|
||||||
}
|
}
|
||||||
this.recordEvent(EVENT_EXCEPTION);
|
const do_deflate = (0,external_node_util_.promisify)(external_node_zlib_namespaceObject.deflate);
|
||||||
|
const exceptionContext = /* @__PURE__ */ new Map();
|
||||||
|
for (const [attachmentLabel, filePath] of this.exceptionAttachments) {
|
||||||
|
let logText;
|
||||||
|
try {
|
||||||
|
logText = (0,external_node_fs_namespaceObject.readFileSync)(filePath);
|
||||||
|
} catch (e) {
|
||||||
|
logText = Buffer.from(this.stringifyError(e));
|
||||||
|
}
|
||||||
|
const buf = await do_deflate(logText);
|
||||||
|
exceptionContext.set(
|
||||||
|
`staple_${attachmentLabel}`,
|
||||||
|
buf.toString("base64")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
this.recordEvent(EVENT_EXCEPTION, Object.fromEntries(exceptionContext));
|
||||||
} finally {
|
} finally {
|
||||||
await this.complete();
|
await this.complete();
|
||||||
}
|
}
|
||||||
|
@ -94354,6 +94394,7 @@ var IdsToolbox = class {
|
||||||
const versionCheckup = await this.client.head(correlatedUrl);
|
const versionCheckup = await this.client.head(correlatedUrl);
|
||||||
if (versionCheckup.headers.etag) {
|
if (versionCheckup.headers.etag) {
|
||||||
const v = versionCheckup.headers.etag;
|
const v = versionCheckup.headers.etag;
|
||||||
|
this.addFact(FACT_SOURCE_URL_ETAG, v);
|
||||||
core.debug(
|
core.debug(
|
||||||
`Checking the tool cache for ${this.getUrl()} at ${v}`
|
`Checking the tool cache for ${this.getUrl()} at ${v}`
|
||||||
);
|
);
|
||||||
|
@ -94402,6 +94443,7 @@ var IdsToolbox = class {
|
||||||
getUrl() {
|
getUrl() {
|
||||||
const p = this.sourceParameters;
|
const p = this.sourceParameters;
|
||||||
if (p.url) {
|
if (p.url) {
|
||||||
|
this.addFact(FACT_SOURCE_URL, p.url);
|
||||||
return new URL(p.url);
|
return new URL(p.url);
|
||||||
}
|
}
|
||||||
const fetchUrl = new URL(IDS_HOST);
|
const fetchUrl = new URL(IDS_HOST);
|
||||||
|
@ -94418,6 +94460,7 @@ var IdsToolbox = class {
|
||||||
fetchUrl.pathname += `/stable`;
|
fetchUrl.pathname += `/stable`;
|
||||||
}
|
}
|
||||||
fetchUrl.pathname += `/${this.architectureFetchSuffix}`;
|
fetchUrl.pathname += `/${this.architectureFetchSuffix}`;
|
||||||
|
this.addFact(FACT_SOURCE_URL, fetchUrl.toString());
|
||||||
return fetchUrl;
|
return fetchUrl;
|
||||||
}
|
}
|
||||||
cacheKey(version2) {
|
cacheKey(version2) {
|
||||||
|
@ -94465,7 +94508,7 @@ var IdsToolbox = class {
|
||||||
void 0,
|
void 0,
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
this.recordEvent(EVENT_ARTIFACT_CACHE_HIT);
|
this.recordEvent(EVENT_ARTIFACT_CACHE_PERSIST);
|
||||||
} finally {
|
} finally {
|
||||||
process.env.GITHUB_WORKSPACE = process.env.GITHUB_WORKSPACE_BACKUP;
|
process.env.GITHUB_WORKSPACE = process.env.GITHUB_WORKSPACE_BACKUP;
|
||||||
delete process.env.GITHUB_WORKSPACE_BACKUP;
|
delete process.env.GITHUB_WORKSPACE_BACKUP;
|
||||||
|
@ -94624,6 +94667,8 @@ function mungeDiagnosticEndpoint(inputUrl) {
|
||||||
* Copyright (c) 2018-2020 [Samuel Carreira]
|
* Copyright (c) 2018-2020 [Samuel Carreira]
|
||||||
*/
|
*/
|
||||||
//# sourceMappingURL=index.js.map
|
//# sourceMappingURL=index.js.map
|
||||||
|
;// CONCATENATED MODULE: external "fs/promises"
|
||||||
|
const external_fs_promises_namespaceObject = __WEBPACK_EXTERNAL_createRequire(import.meta.url)("fs/promises");
|
||||||
// EXTERNAL MODULE: external "http"
|
// EXTERNAL MODULE: external "http"
|
||||||
var external_http_ = __nccwpck_require__(3685);
|
var external_http_ = __nccwpck_require__(3685);
|
||||||
;// CONCATENATED MODULE: external "node:child_process"
|
;// CONCATENATED MODULE: external "node:child_process"
|
||||||
|
@ -94689,6 +94734,7 @@ async function flakeHubLogin(netrc) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var ENV_CACHE_DAEMONDIR = "MAGIC_NIX_CACHE_DAEMONDIR";
|
var ENV_CACHE_DAEMONDIR = "MAGIC_NIX_CACHE_DAEMONDIR";
|
||||||
var MagicNixCacheAction = class {
|
var MagicNixCacheAction = class {
|
||||||
constructor() {
|
constructor() {
|
||||||
|
@ -94713,9 +94759,27 @@ var MagicNixCacheAction = class {
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
if (process.env[ENV_CACHE_DAEMONDIR]) {
|
||||||
|
this.unsafeDaemonDir = process.env[ENV_CACHE_DAEMONDIR];
|
||||||
|
} else {
|
||||||
|
this.unsafeDaemonDir = this.idslib.getTemporaryName();
|
||||||
|
core.exportVariable(ENV_CACHE_DAEMONDIR, this.unsafeDaemonDir);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async getDaemonDir() {
|
||||||
|
if (this.daemonDir === void 0) {
|
||||||
|
await (0,external_fs_promises_namespaceObject.mkdir)(this.unsafeDaemonDir, { recursive: true });
|
||||||
|
this.daemonDir = this.unsafeDaemonDir;
|
||||||
|
return this.unsafeDaemonDir;
|
||||||
|
} else {
|
||||||
|
return this.daemonDir;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async daemonDirExists() {
|
||||||
|
const statRes = await (0,external_fs_promises_namespaceObject.stat)(this.unsafeDaemonDir);
|
||||||
|
return statRes.isDirectory();
|
||||||
}
|
}
|
||||||
async setUpAutoCache() {
|
async setUpAutoCache() {
|
||||||
const tmpdir3 = process.env["RUNNER_TEMP"] || external_node_os_.tmpdir();
|
|
||||||
const requiredEnv = [
|
const requiredEnv = [
|
||||||
"ACTIONS_CACHE_URL",
|
"ACTIONS_CACHE_URL",
|
||||||
"ACTIONS_RUNTIME_URL",
|
"ACTIONS_RUNTIME_URL",
|
||||||
|
@ -94736,7 +94800,6 @@ var MagicNixCacheAction = class {
|
||||||
core.debug(
|
core.debug(
|
||||||
`GitHub Action Cache URL: ${process.env["ACTIONS_CACHE_URL"]}`
|
`GitHub Action Cache URL: ${process.env["ACTIONS_CACHE_URL"]}`
|
||||||
);
|
);
|
||||||
const daemonDir = await promises_namespaceObject.mkdtemp(external_node_path_namespaceObject.join(tmpdir3, "magic-nix-cache-"));
|
|
||||||
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;
|
||||||
|
@ -94768,6 +94831,7 @@ var MagicNixCacheAction = class {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
const daemonDir = await this.getDaemonDir();
|
||||||
const outputPath = `${daemonDir}/daemon.log`;
|
const outputPath = `${daemonDir}/daemon.log`;
|
||||||
const output = (0,external_node_fs_namespaceObject.openSync)(outputPath, "a");
|
const output = (0,external_node_fs_namespaceObject.openSync)(outputPath, "a");
|
||||||
const log = tailLog(daemonDir);
|
const log = tailLog(daemonDir);
|
||||||
|
@ -94834,7 +94898,6 @@ var MagicNixCacheAction = class {
|
||||||
});
|
});
|
||||||
daemon.unref();
|
daemon.unref();
|
||||||
core.info("Launched Magic Nix Cache");
|
core.info("Launched Magic Nix Cache");
|
||||||
core.exportVariable(ENV_CACHE_DAEMONDIR, daemonDir);
|
|
||||||
log.unwatch();
|
log.unwatch();
|
||||||
}
|
}
|
||||||
async fetchAutoCacher() {
|
async fetchAutoCacher() {
|
||||||
|
@ -94848,10 +94911,6 @@ var MagicNixCacheAction = class {
|
||||||
return `${lastPath}/bin/magic-nix-cache`;
|
return `${lastPath}/bin/magic-nix-cache`;
|
||||||
}
|
}
|
||||||
async notifyAutoCache() {
|
async notifyAutoCache() {
|
||||||
const daemonDir = process.env[ENV_CACHE_DAEMONDIR];
|
|
||||||
if (!daemonDir) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
core.debug(`Indicating workflow start`);
|
core.debug(`Indicating workflow start`);
|
||||||
const hostAndPort = inputs_exports.getString("listen");
|
const hostAndPort = inputs_exports.getString("listen");
|
||||||
|
@ -94864,11 +94923,11 @@ var MagicNixCacheAction = class {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
async tearDownAutoCache() {
|
async tearDownAutoCache() {
|
||||||
const daemonDir = process.env[ENV_CACHE_DAEMONDIR];
|
if (await this.daemonDirExists()) {
|
||||||
if (!daemonDir) {
|
|
||||||
core.debug("magic-nix-cache not started - Skipping");
|
core.debug("magic-nix-cache not started - Skipping");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
const daemonDir = await this.getDaemonDir();
|
||||||
const pidFile = external_node_path_namespaceObject.join(daemonDir, "daemon.pid");
|
const pidFile = external_node_path_namespaceObject.join(daemonDir, "daemon.pid");
|
||||||
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}`);
|
||||||
|
|
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
|
@ -27,7 +27,7 @@
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/core": "^1.10.1",
|
"@actions/core": "^1.10.1",
|
||||||
"@actions/exec": "^1.1.1",
|
"@actions/exec": "^1.1.1",
|
||||||
"detsys-ts": "github:DeterminateSystems/detsys-ts",
|
"detsys-ts": "github:DeterminateSystems/detsys-ts#error-condition",
|
||||||
"got": "^14.2.1",
|
"got": "^14.2.1",
|
||||||
"tail": "^2.2.6"
|
"tail": "^2.2.6"
|
||||||
},
|
},
|
||||||
|
|
|
@ -12,8 +12,8 @@ dependencies:
|
||||||
specifier: ^1.1.1
|
specifier: ^1.1.1
|
||||||
version: 1.1.1
|
version: 1.1.1
|
||||||
detsys-ts:
|
detsys-ts:
|
||||||
specifier: github:DeterminateSystems/detsys-ts
|
specifier: github:DeterminateSystems/detsys-ts#error-condition
|
||||||
version: github.com/DeterminateSystems/detsys-ts/d872d42fb693faad3027a08c78620639f23168e1
|
version: github.com/DeterminateSystems/detsys-ts/3baa96b315ee9f6b26033191a123eb9015522791
|
||||||
got:
|
got:
|
||||||
specifier: ^14.2.1
|
specifier: ^14.2.1
|
||||||
version: 14.2.1
|
version: 14.2.1
|
||||||
|
@ -3831,8 +3831,8 @@ packages:
|
||||||
engines: {node: '>=10'}
|
engines: {node: '>=10'}
|
||||||
dev: true
|
dev: true
|
||||||
|
|
||||||
github.com/DeterminateSystems/detsys-ts/d872d42fb693faad3027a08c78620639f23168e1:
|
github.com/DeterminateSystems/detsys-ts/3baa96b315ee9f6b26033191a123eb9015522791:
|
||||||
resolution: {tarball: https://codeload.github.com/DeterminateSystems/detsys-ts/tar.gz/d872d42fb693faad3027a08c78620639f23168e1}
|
resolution: {tarball: https://codeload.github.com/DeterminateSystems/detsys-ts/tar.gz/3baa96b315ee9f6b26033191a123eb9015522791}
|
||||||
name: detsys-ts
|
name: detsys-ts
|
||||||
version: 1.0.0
|
version: 1.0.0
|
||||||
dependencies:
|
dependencies:
|
||||||
|
|
40
src/index.ts
40
src/index.ts
|
@ -1,6 +1,7 @@
|
||||||
import { netrcPath, tailLog } from "./helpers.js";
|
import { netrcPath, tailLog } from "./helpers.js";
|
||||||
import * as actionsCore from "@actions/core";
|
import * as actionsCore from "@actions/core";
|
||||||
import { IdsToolbox, inputs } from "detsys-ts";
|
import { IdsToolbox, inputs } from "detsys-ts";
|
||||||
|
import { mkdir, stat } from "fs/promises";
|
||||||
import got, { Got } from "got";
|
import got, { Got } from "got";
|
||||||
import * as http from "http";
|
import * as http from "http";
|
||||||
import { SpawnOptions, exec, spawn } from "node:child_process";
|
import { SpawnOptions, exec, spawn } from "node:child_process";
|
||||||
|
@ -16,6 +17,9 @@ class MagicNixCacheAction {
|
||||||
idslib: IdsToolbox;
|
idslib: IdsToolbox;
|
||||||
private client: Got;
|
private client: Got;
|
||||||
|
|
||||||
|
private daemonDir?: string;
|
||||||
|
private unsafeDaemonDir: string;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.idslib = new IdsToolbox({
|
this.idslib = new IdsToolbox({
|
||||||
name: "magic-nix-cache",
|
name: "magic-nix-cache",
|
||||||
|
@ -39,10 +43,31 @@ class MagicNixCacheAction {
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (process.env[ENV_CACHE_DAEMONDIR]) {
|
||||||
|
this.unsafeDaemonDir = process.env[ENV_CACHE_DAEMONDIR];
|
||||||
|
} else {
|
||||||
|
this.unsafeDaemonDir = this.idslib.getTemporaryName();
|
||||||
|
actionsCore.exportVariable(ENV_CACHE_DAEMONDIR, this.unsafeDaemonDir);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async getDaemonDir(): Promise<string> {
|
||||||
|
if (this.daemonDir === undefined) {
|
||||||
|
await mkdir(this.unsafeDaemonDir, { recursive: true });
|
||||||
|
this.daemonDir = this.unsafeDaemonDir;
|
||||||
|
return this.unsafeDaemonDir;
|
||||||
|
} else {
|
||||||
|
return this.daemonDir;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async daemonDirExists(): Promise<boolean> {
|
||||||
|
const statRes = await stat(this.unsafeDaemonDir);
|
||||||
|
return statRes.isDirectory();
|
||||||
}
|
}
|
||||||
|
|
||||||
async setUpAutoCache(): Promise<void> {
|
async setUpAutoCache(): Promise<void> {
|
||||||
const tmpdir = process.env["RUNNER_TEMP"] || os.tmpdir();
|
|
||||||
const requiredEnv = [
|
const requiredEnv = [
|
||||||
"ACTIONS_CACHE_URL",
|
"ACTIONS_CACHE_URL",
|
||||||
"ACTIONS_RUNTIME_URL",
|
"ACTIONS_RUNTIME_URL",
|
||||||
|
@ -67,7 +92,6 @@ class MagicNixCacheAction {
|
||||||
`GitHub Action Cache URL: ${process.env["ACTIONS_CACHE_URL"]}`,
|
`GitHub Action Cache URL: ${process.env["ACTIONS_CACHE_URL"]}`,
|
||||||
);
|
);
|
||||||
|
|
||||||
const daemonDir = await fs.mkdtemp(path.join(tmpdir, "magic-nix-cache-"));
|
|
||||||
const sourceBinary = inputs.getStringOrNull("source-binary");
|
const sourceBinary = inputs.getStringOrNull("source-binary");
|
||||||
const daemonBin =
|
const daemonBin =
|
||||||
sourceBinary !== null ? sourceBinary : await this.fetchAutoCacher();
|
sourceBinary !== null ? sourceBinary : await this.fetchAutoCacher();
|
||||||
|
@ -106,6 +130,7 @@ class MagicNixCacheAction {
|
||||||
});
|
});
|
||||||
|
|
||||||
// Start tailing the daemon log.
|
// Start tailing the daemon log.
|
||||||
|
const daemonDir = await this.getDaemonDir();
|
||||||
const outputPath = `${daemonDir}/daemon.log`;
|
const outputPath = `${daemonDir}/daemon.log`;
|
||||||
const output = openSync(outputPath, "a");
|
const output = openSync(outputPath, "a");
|
||||||
const log = tailLog(daemonDir);
|
const log = tailLog(daemonDir);
|
||||||
|
@ -192,7 +217,6 @@ class MagicNixCacheAction {
|
||||||
daemon.unref();
|
daemon.unref();
|
||||||
|
|
||||||
actionsCore.info("Launched Magic Nix Cache");
|
actionsCore.info("Launched Magic Nix Cache");
|
||||||
actionsCore.exportVariable(ENV_CACHE_DAEMONDIR, daemonDir);
|
|
||||||
|
|
||||||
log.unwatch();
|
log.unwatch();
|
||||||
}
|
}
|
||||||
|
@ -211,9 +235,8 @@ class MagicNixCacheAction {
|
||||||
}
|
}
|
||||||
|
|
||||||
async notifyAutoCache(): Promise<void> {
|
async notifyAutoCache(): Promise<void> {
|
||||||
const daemonDir = process.env[ENV_CACHE_DAEMONDIR];
|
if (!await this.daemonDirExists()) {
|
||||||
|
actionsCore.debug("magic-nix-cache not started - Skipping");
|
||||||
if (!daemonDir) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -232,12 +255,11 @@ class MagicNixCacheAction {
|
||||||
}
|
}
|
||||||
|
|
||||||
async tearDownAutoCache(): Promise<void> {
|
async tearDownAutoCache(): Promise<void> {
|
||||||
const daemonDir = process.env[ENV_CACHE_DAEMONDIR];
|
if (!await this.daemonDirExists()) {
|
||||||
|
|
||||||
if (!daemonDir) {
|
|
||||||
actionsCore.debug("magic-nix-cache not started - Skipping");
|
actionsCore.debug("magic-nix-cache not started - Skipping");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
const daemonDir = await this.getDaemonDir();
|
||||||
|
|
||||||
const pidFile = path.join(daemonDir, "daemon.pid");
|
const pidFile = path.join(daemonDir, "daemon.pid");
|
||||||
const pid = parseInt(await fs.readFile(pidFile, { encoding: "ascii" }));
|
const pid = parseInt(await fs.readFile(pidFile, { encoding: "ascii" }));
|
||||||
|
|
Loading…
Reference in a new issue