Constify events and facts

This commit is contained in:
Luc Perkins 2024-04-15 19:34:51 -03:00
parent 8f4ca496eb
commit 413fb1beb4
No known key found for this signature in database
GPG key ID: 16DB1108FB591835
3 changed files with 113 additions and 51 deletions

53
dist/index.js generated vendored
View file

@ -97673,6 +97673,25 @@ function mungeDiagnosticEndpoint(inputUrl) {
// Nix installation events
const EVENT_INSTALL_NIX_FAILURE = "install_nix_failure";
const EVENT_INSTALL_NIX_START = "install_nix_start";
const EVENT_INSTALL_NIX_SUCCESS = "install_nix_start";
const EVENT_SETUP_KVM = "setup_kvm";
const EVENT_UNINSTALL_NIX = "uninstall";
// Docker events
const EVENT_CLEAN_UP_DOCKER_SHIM = "clean_up_docker_shim";
const EVENT_START_DOCKER_SHIM = "start_docker_shim";
// FlakeHub events
const EVENT_LOGIN_TO_FLAKEHUB = "login_to_flakehub";
// Other events
const EVENT_CONCLUDE_WORKFLOW = "conclude_workflow";
// Facts
const FACT_HAS_DOCKER = "has_docker";
const FACT_HAS_SYSTEMD = "has_systemd";
const FACT_IN_GITHUB_ACTIONS = "in_act";
const FACT_IN_NAMESPACE_SO = "in_namespace_so";
const FACT_NIX_INSTALLER_PLANNER = "nix_installer_planner";
class NixInstallerAction { class NixInstallerAction {
constructor() { constructor() {
this.idslib = new IdsToolbox({ this.idslib = new IdsToolbox({
@ -97730,13 +97749,13 @@ class NixInstallerAction {
core.warning("Systemd is detected, but ignoring it since force-docker-shim is enabled."); core.warning("Systemd is detected, but ignoring it since force-docker-shim is enabled.");
} }
else { else {
this.idslib.addFact("has_systemd", true); this.idslib.addFact(FACT_HAS_SYSTEMD, true);
return; return;
} }
} }
this.idslib.addFact("has_systemd", false); this.idslib.addFact(FACT_HAS_SYSTEMD, false);
core.debug("Linux detected without systemd, testing for Docker with `docker info` as an alternative daemon supervisor."); core.debug("Linux detected without systemd, testing for Docker with `docker info` as an alternative daemon supervisor.");
this.idslib.addFact("has_docker", false); // Set to false here, and only in the success case do we set it to true this.idslib.addFact(FACT_HAS_DOCKER, false); // Set to false here, and only in the success case do we set it to true
let exitCode; let exitCode;
try { try {
exitCode = await exec.exec("docker", ["info"], { exitCode = await exec.exec("docker", ["info"], {
@ -97769,7 +97788,7 @@ class NixInstallerAction {
return; return;
} }
} }
this.idslib.addFact("has_docker", true); this.idslib.addFact(FACT_HAS_DOCKER, true);
if (!this.forceDockerShim && if (!this.forceDockerShim &&
(await this.detectDockerWithMountedDockerSocket())) { (await this.detectDockerWithMountedDockerSocket())) {
core.debug("Detected a Docker container with a Docker socket mounted, not enabling docker shim."); core.debug("Detected a Docker container with a Docker socket mounted, not enabling docker shim.");
@ -97985,12 +98004,12 @@ class NixInstallerAction {
} }
executionEnv.NIX_INSTALLER_EXTRA_CONF = extraConf; executionEnv.NIX_INSTALLER_EXTRA_CONF = extraConf;
if (process.env.ACT && !process.env.NOT_ACT) { if (process.env.ACT && !process.env.NOT_ACT) {
this.idslib.addFact("in_act", true); this.idslib.addFact(FACT_IN_GITHUB_ACTIONS, true);
core.info("Detected `$ACT` environment, assuming this is a https://github.com/nektos/act created container, set `NOT_ACT=true` to override this. This will change the setting of the `init` to be compatible with `act`"); core.info("Detected `$ACT` environment, assuming this is a https://github.com/nektos/act created container, set `NOT_ACT=true` to override this. This will change the setting of the `init` to be compatible with `act`");
executionEnv.NIX_INSTALLER_INIT = "none"; executionEnv.NIX_INSTALLER_INIT = "none";
} }
if (process.env.NSC_VM_ID && !process.env.NOT_NAMESPACE) { if (process.env.NSC_VM_ID && !process.env.NOT_NAMESPACE) {
this.idslib.addFact("in_namespace_so", true); this.idslib.addFact(FACT_IN_NAMESPACE_SO, true);
core.info("Detected Namespace runner, assuming this is a https://namespace.so created container, set `NOT_NAMESPACE=true` to override this. This will change the setting of the `init` to be compatible with Namespace"); core.info("Detected Namespace runner, assuming this is a https://namespace.so created container, set `NOT_NAMESPACE=true` to override this. This will change the setting of the `init` to be compatible with Namespace");
executionEnv.NIX_INSTALLER_INIT = "none"; executionEnv.NIX_INSTALLER_INIT = "none";
} }
@ -98001,18 +98020,18 @@ class NixInstallerAction {
core.debug(`Execution environment: ${JSON.stringify(executionEnv, null, 4)}`); core.debug(`Execution environment: ${JSON.stringify(executionEnv, null, 4)}`);
const args = ["install"]; const args = ["install"];
if (this.planner) { if (this.planner) {
this.idslib.addFact("nix_installer_planner", this.planner); this.idslib.addFact(FACT_NIX_INSTALLER_PLANNER, this.planner);
args.push(this.planner); args.push(this.planner);
} }
else { else {
this.idslib.addFact("nix_installer_planner", getDefaultPlanner()); this.idslib.addFact(FACT_NIX_INSTALLER_PLANNER, getDefaultPlanner());
args.push(getDefaultPlanner()); args.push(getDefaultPlanner());
} }
if (this.extraArgs) { if (this.extraArgs) {
const extraArgs = parseArgsStringToArgv(this.extraArgs); const extraArgs = parseArgsStringToArgv(this.extraArgs);
args.concat(extraArgs); args.concat(extraArgs);
} }
this.idslib.recordEvent("install_nix_start"); this.idslib.recordEvent(EVENT_INSTALL_NIX_START);
const exitCode = await exec.exec(binaryPath, args, { const exitCode = await exec.exec(binaryPath, args, {
env: { env: {
...executionEnv, ...executionEnv,
@ -98020,12 +98039,12 @@ class NixInstallerAction {
}, },
}); });
if (exitCode !== 0) { if (exitCode !== 0) {
this.idslib.recordEvent("install_nix_failure", { this.idslib.recordEvent(EVENT_INSTALL_NIX_FAILURE, {
exitCode, exitCode,
}); });
throw new Error(`Non-zero exit code of \`${exitCode}\` detected`); throw new Error(`Non-zero exit code of \`${exitCode}\` detected`);
} }
this.idslib.recordEvent("install_nix_success"); this.idslib.recordEvent(EVENT_INSTALL_NIX_SUCCESS);
return exitCode; return exitCode;
} }
async install() { async install() {
@ -98107,7 +98126,7 @@ class NixInstallerAction {
} }
{ {
core.debug("Starting the Nix daemon through Docker..."); core.debug("Starting the Nix daemon through Docker...");
this.idslib.recordEvent("start_docker_shim"); this.idslib.recordEvent(EVENT_START_DOCKER_SHIM);
const exitCode = await exec.exec("docker", [ const exitCode = await exec.exec("docker", [
"--log-level=debug", "--log-level=debug",
"run", "run",
@ -98184,7 +98203,7 @@ class NixInstallerAction {
} }
} }
if (cleaned) { if (cleaned) {
this.idslib.recordEvent("clean_up_docker_shim"); this.idslib.recordEvent(EVENT_CLEAN_UP_DOCKER_SHIM);
} }
else { else {
core.warning("Giving up on cleaning up the nix daemon container"); core.warning("Giving up on cleaning up the nix daemon container");
@ -98206,7 +98225,7 @@ class NixInstallerAction {
} }
} }
async flakehubLogin() { async flakehubLogin() {
this.idslib.recordEvent("login_to_flakehub"); this.idslib.recordEvent(EVENT_LOGIN_TO_FLAKEHUB);
const netrcPath = `${process.env["RUNNER_TEMP"]}/determinate-nix-installer-netrc`; const netrcPath = `${process.env["RUNNER_TEMP"]}/determinate-nix-installer-netrc`;
const jwt = await core.getIDToken("api.flakehub.com"); const jwt = await core.getIDToken("api.flakehub.com");
await (0,promises_namespaceObject.writeFile)(netrcPath, [ await (0,promises_namespaceObject.writeFile)(netrcPath, [
@ -98222,7 +98241,7 @@ class NixInstallerAction {
return netrcPath; return netrcPath;
} }
async executeUninstall() { async executeUninstall() {
this.idslib.recordEvent("uninstall"); this.idslib.recordEvent(EVENT_UNINSTALL_NIX);
const exitCode = await exec.exec(`/nix/nix-installer`, ["uninstall"], { const exitCode = await exec.exec(`/nix/nix-installer`, ["uninstall"], {
env: { env: {
NIX_INSTALLER_NO_CONFIRM: "true", NIX_INSTALLER_NO_CONFIRM: "true",
@ -98247,7 +98266,7 @@ class NixInstallerAction {
} }
} }
async setupKvm() { async setupKvm() {
this.idslib.recordEvent("setup_kvm"); this.idslib.recordEvent(EVENT_SETUP_KVM);
const currentUser = (0,external_node_os_.userInfo)(); const currentUser = (0,external_node_os_.userInfo)();
const isRoot = currentUser.uid === 0; const isRoot = currentUser.uid === 0;
const maybeSudo = isRoot ? "" : "sudo"; const maybeSudo = isRoot ? "" : "sudo";
@ -98334,7 +98353,7 @@ class NixInstallerAction {
} }
async reportOverall() { async reportOverall() {
try { try {
this.idslib.recordEvent("conclude_workflow", { this.idslib.recordEvent(EVENT_CONCLUDE_WORKFLOW, {
conclusion: await this.getWorkflowConclusion(), conclusion: await this.getWorkflowConclusion(),
}); });
} }

53
dist/main.js generated vendored
View file

@ -9,6 +9,25 @@ import stringArgv from "string-argv";
import * as path from "path"; import * as path from "path";
import { IdsToolbox, inputs, platform } from "detsys-ts"; import { IdsToolbox, inputs, platform } from "detsys-ts";
import { randomUUID } from "node:crypto"; import { randomUUID } from "node:crypto";
// Nix installation events
const EVENT_INSTALL_NIX_FAILURE = "install_nix_failure";
const EVENT_INSTALL_NIX_START = "install_nix_start";
const EVENT_INSTALL_NIX_SUCCESS = "install_nix_start";
const EVENT_SETUP_KVM = "setup_kvm";
const EVENT_UNINSTALL_NIX = "uninstall";
// Docker events
const EVENT_CLEAN_UP_DOCKER_SHIM = "clean_up_docker_shim";
const EVENT_START_DOCKER_SHIM = "start_docker_shim";
// FlakeHub events
const EVENT_LOGIN_TO_FLAKEHUB = "login_to_flakehub";
// Other events
const EVENT_CONCLUDE_WORKFLOW = "conclude_workflow";
// Facts
const FACT_HAS_DOCKER = "has_docker";
const FACT_HAS_SYSTEMD = "has_systemd";
const FACT_IN_GITHUB_ACTIONS = "in_act";
const FACT_IN_NAMESPACE_SO = "in_namespace_so";
const FACT_NIX_INSTALLER_PLANNER = "nix_installer_planner";
class NixInstallerAction { class NixInstallerAction {
constructor() { constructor() {
this.idslib = new IdsToolbox({ this.idslib = new IdsToolbox({
@ -66,13 +85,13 @@ class NixInstallerAction {
actionsCore.warning("Systemd is detected, but ignoring it since force-docker-shim is enabled."); actionsCore.warning("Systemd is detected, but ignoring it since force-docker-shim is enabled.");
} }
else { else {
this.idslib.addFact("has_systemd", true); this.idslib.addFact(FACT_HAS_SYSTEMD, true);
return; return;
} }
} }
this.idslib.addFact("has_systemd", false); this.idslib.addFact(FACT_HAS_SYSTEMD, false);
actionsCore.debug("Linux detected without systemd, testing for Docker with `docker info` as an alternative daemon supervisor."); actionsCore.debug("Linux detected without systemd, testing for Docker with `docker info` as an alternative daemon supervisor.");
this.idslib.addFact("has_docker", false); // Set to false here, and only in the success case do we set it to true this.idslib.addFact(FACT_HAS_DOCKER, false); // Set to false here, and only in the success case do we set it to true
let exitCode; let exitCode;
try { try {
exitCode = await actionsExec.exec("docker", ["info"], { exitCode = await actionsExec.exec("docker", ["info"], {
@ -105,7 +124,7 @@ class NixInstallerAction {
return; return;
} }
} }
this.idslib.addFact("has_docker", true); this.idslib.addFact(FACT_HAS_DOCKER, true);
if (!this.forceDockerShim && if (!this.forceDockerShim &&
(await this.detectDockerWithMountedDockerSocket())) { (await this.detectDockerWithMountedDockerSocket())) {
actionsCore.debug("Detected a Docker container with a Docker socket mounted, not enabling docker shim."); actionsCore.debug("Detected a Docker container with a Docker socket mounted, not enabling docker shim.");
@ -321,12 +340,12 @@ class NixInstallerAction {
} }
executionEnv.NIX_INSTALLER_EXTRA_CONF = extraConf; executionEnv.NIX_INSTALLER_EXTRA_CONF = extraConf;
if (process.env.ACT && !process.env.NOT_ACT) { if (process.env.ACT && !process.env.NOT_ACT) {
this.idslib.addFact("in_act", true); this.idslib.addFact(FACT_IN_GITHUB_ACTIONS, true);
actionsCore.info("Detected `$ACT` environment, assuming this is a https://github.com/nektos/act created container, set `NOT_ACT=true` to override this. This will change the setting of the `init` to be compatible with `act`"); actionsCore.info("Detected `$ACT` environment, assuming this is a https://github.com/nektos/act created container, set `NOT_ACT=true` to override this. This will change the setting of the `init` to be compatible with `act`");
executionEnv.NIX_INSTALLER_INIT = "none"; executionEnv.NIX_INSTALLER_INIT = "none";
} }
if (process.env.NSC_VM_ID && !process.env.NOT_NAMESPACE) { if (process.env.NSC_VM_ID && !process.env.NOT_NAMESPACE) {
this.idslib.addFact("in_namespace_so", true); this.idslib.addFact(FACT_IN_NAMESPACE_SO, true);
actionsCore.info("Detected Namespace runner, assuming this is a https://namespace.so created container, set `NOT_NAMESPACE=true` to override this. This will change the setting of the `init` to be compatible with Namespace"); actionsCore.info("Detected Namespace runner, assuming this is a https://namespace.so created container, set `NOT_NAMESPACE=true` to override this. This will change the setting of the `init` to be compatible with Namespace");
executionEnv.NIX_INSTALLER_INIT = "none"; executionEnv.NIX_INSTALLER_INIT = "none";
} }
@ -337,18 +356,18 @@ class NixInstallerAction {
actionsCore.debug(`Execution environment: ${JSON.stringify(executionEnv, null, 4)}`); actionsCore.debug(`Execution environment: ${JSON.stringify(executionEnv, null, 4)}`);
const args = ["install"]; const args = ["install"];
if (this.planner) { if (this.planner) {
this.idslib.addFact("nix_installer_planner", this.planner); this.idslib.addFact(FACT_NIX_INSTALLER_PLANNER, this.planner);
args.push(this.planner); args.push(this.planner);
} }
else { else {
this.idslib.addFact("nix_installer_planner", getDefaultPlanner()); this.idslib.addFact(FACT_NIX_INSTALLER_PLANNER, getDefaultPlanner());
args.push(getDefaultPlanner()); args.push(getDefaultPlanner());
} }
if (this.extraArgs) { if (this.extraArgs) {
const extraArgs = stringArgv(this.extraArgs); const extraArgs = stringArgv(this.extraArgs);
args.concat(extraArgs); args.concat(extraArgs);
} }
this.idslib.recordEvent("install_nix_start"); this.idslib.recordEvent(EVENT_INSTALL_NIX_START);
const exitCode = await actionsExec.exec(binaryPath, args, { const exitCode = await actionsExec.exec(binaryPath, args, {
env: { env: {
...executionEnv, ...executionEnv,
@ -356,12 +375,12 @@ class NixInstallerAction {
}, },
}); });
if (exitCode !== 0) { if (exitCode !== 0) {
this.idslib.recordEvent("install_nix_failure", { this.idslib.recordEvent(EVENT_INSTALL_NIX_FAILURE, {
exitCode, exitCode,
}); });
throw new Error(`Non-zero exit code of \`${exitCode}\` detected`); throw new Error(`Non-zero exit code of \`${exitCode}\` detected`);
} }
this.idslib.recordEvent("install_nix_success"); this.idslib.recordEvent(EVENT_INSTALL_NIX_SUCCESS);
return exitCode; return exitCode;
} }
async install() { async install() {
@ -443,7 +462,7 @@ class NixInstallerAction {
} }
{ {
actionsCore.debug("Starting the Nix daemon through Docker..."); actionsCore.debug("Starting the Nix daemon through Docker...");
this.idslib.recordEvent("start_docker_shim"); this.idslib.recordEvent(EVENT_START_DOCKER_SHIM);
const exitCode = await actionsExec.exec("docker", [ const exitCode = await actionsExec.exec("docker", [
"--log-level=debug", "--log-level=debug",
"run", "run",
@ -520,7 +539,7 @@ class NixInstallerAction {
} }
} }
if (cleaned) { if (cleaned) {
this.idslib.recordEvent("clean_up_docker_shim"); this.idslib.recordEvent(EVENT_CLEAN_UP_DOCKER_SHIM);
} }
else { else {
actionsCore.warning("Giving up on cleaning up the nix daemon container"); actionsCore.warning("Giving up on cleaning up the nix daemon container");
@ -542,7 +561,7 @@ class NixInstallerAction {
} }
} }
async flakehubLogin() { async flakehubLogin() {
this.idslib.recordEvent("login_to_flakehub"); this.idslib.recordEvent(EVENT_LOGIN_TO_FLAKEHUB);
const netrcPath = `${process.env["RUNNER_TEMP"]}/determinate-nix-installer-netrc`; const netrcPath = `${process.env["RUNNER_TEMP"]}/determinate-nix-installer-netrc`;
const jwt = await actionsCore.getIDToken("api.flakehub.com"); const jwt = await actionsCore.getIDToken("api.flakehub.com");
await writeFile(netrcPath, [ await writeFile(netrcPath, [
@ -558,7 +577,7 @@ class NixInstallerAction {
return netrcPath; return netrcPath;
} }
async executeUninstall() { async executeUninstall() {
this.idslib.recordEvent("uninstall"); this.idslib.recordEvent(EVENT_UNINSTALL_NIX);
const exitCode = await actionsExec.exec(`/nix/nix-installer`, ["uninstall"], { const exitCode = await actionsExec.exec(`/nix/nix-installer`, ["uninstall"], {
env: { env: {
NIX_INSTALLER_NO_CONFIRM: "true", NIX_INSTALLER_NO_CONFIRM: "true",
@ -583,7 +602,7 @@ class NixInstallerAction {
} }
} }
async setupKvm() { async setupKvm() {
this.idslib.recordEvent("setup_kvm"); this.idslib.recordEvent(EVENT_SETUP_KVM);
const currentUser = userInfo(); const currentUser = userInfo();
const isRoot = currentUser.uid === 0; const isRoot = currentUser.uid === 0;
const maybeSudo = isRoot ? "" : "sudo"; const maybeSudo = isRoot ? "" : "sudo";
@ -670,7 +689,7 @@ class NixInstallerAction {
} }
async reportOverall() { async reportOverall() {
try { try {
this.idslib.recordEvent("conclude_workflow", { this.idslib.recordEvent(EVENT_CONCLUDE_WORKFLOW, {
conclusion: await this.getWorkflowConclusion(), conclusion: await this.getWorkflowConclusion(),
}); });
} }

View file

@ -10,6 +10,30 @@ import * as path from "path";
import { IdsToolbox, inputs, platform } from "detsys-ts"; import { IdsToolbox, inputs, platform } from "detsys-ts";
import { randomUUID } from "node:crypto"; import { randomUUID } from "node:crypto";
// Nix installation events
const EVENT_INSTALL_NIX_FAILURE = "install_nix_failure";
const EVENT_INSTALL_NIX_START = "install_nix_start";
const EVENT_INSTALL_NIX_SUCCESS = "install_nix_start";
const EVENT_SETUP_KVM = "setup_kvm";
const EVENT_UNINSTALL_NIX = "uninstall";
// Docker events
const EVENT_CLEAN_UP_DOCKER_SHIM = "clean_up_docker_shim";
const EVENT_START_DOCKER_SHIM = "start_docker_shim";
// FlakeHub events
const EVENT_LOGIN_TO_FLAKEHUB = "login_to_flakehub";
// Other events
const EVENT_CONCLUDE_WORKFLOW = "conclude_workflow";
// Facts
const FACT_HAS_DOCKER = "has_docker";
const FACT_HAS_SYSTEMD = "has_systemd";
const FACT_IN_GITHUB_ACTIONS = "in_act";
const FACT_IN_NAMESPACE_SO = "in_namespace_so";
const FACT_NIX_INSTALLER_PLANNER = "nix_installer_planner";
class NixInstallerAction { class NixInstallerAction {
idslib: IdsToolbox; idslib: IdsToolbox;
platform: string; platform: string;
@ -105,17 +129,17 @@ class NixInstallerAction {
"Systemd is detected, but ignoring it since force-docker-shim is enabled.", "Systemd is detected, but ignoring it since force-docker-shim is enabled.",
); );
} else { } else {
this.idslib.addFact("has_systemd", true); this.idslib.addFact(FACT_HAS_SYSTEMD, true);
return; return;
} }
} }
this.idslib.addFact("has_systemd", false); this.idslib.addFact(FACT_HAS_SYSTEMD, false);
actionsCore.debug( actionsCore.debug(
"Linux detected without systemd, testing for Docker with `docker info` as an alternative daemon supervisor.", "Linux detected without systemd, testing for Docker with `docker info` as an alternative daemon supervisor.",
); );
this.idslib.addFact("has_docker", false); // Set to false here, and only in the success case do we set it to true this.idslib.addFact(FACT_HAS_DOCKER, false); // Set to false here, and only in the success case do we set it to true
let exitCode; let exitCode;
try { try {
exitCode = await actionsExec.exec("docker", ["info"], { exitCode = await actionsExec.exec("docker", ["info"], {
@ -149,7 +173,7 @@ class NixInstallerAction {
return; return;
} }
} }
this.idslib.addFact("has_docker", true); this.idslib.addFact(FACT_HAS_DOCKER, true);
if ( if (
!this.forceDockerShim && !this.forceDockerShim &&
@ -420,7 +444,7 @@ class NixInstallerAction {
executionEnv.NIX_INSTALLER_EXTRA_CONF = extraConf; executionEnv.NIX_INSTALLER_EXTRA_CONF = extraConf;
if (process.env.ACT && !process.env.NOT_ACT) { if (process.env.ACT && !process.env.NOT_ACT) {
this.idslib.addFact("in_act", true); this.idslib.addFact(FACT_IN_GITHUB_ACTIONS, true);
actionsCore.info( actionsCore.info(
"Detected `$ACT` environment, assuming this is a https://github.com/nektos/act created container, set `NOT_ACT=true` to override this. This will change the setting of the `init` to be compatible with `act`", "Detected `$ACT` environment, assuming this is a https://github.com/nektos/act created container, set `NOT_ACT=true` to override this. This will change the setting of the `init` to be compatible with `act`",
); );
@ -428,7 +452,7 @@ class NixInstallerAction {
} }
if (process.env.NSC_VM_ID && !process.env.NOT_NAMESPACE) { if (process.env.NSC_VM_ID && !process.env.NOT_NAMESPACE) {
this.idslib.addFact("in_namespace_so", true); this.idslib.addFact(FACT_IN_NAMESPACE_SO, true);
actionsCore.info( actionsCore.info(
"Detected Namespace runner, assuming this is a https://namespace.so created container, set `NOT_NAMESPACE=true` to override this. This will change the setting of the `init` to be compatible with Namespace", "Detected Namespace runner, assuming this is a https://namespace.so created container, set `NOT_NAMESPACE=true` to override this. This will change the setting of the `init` to be compatible with Namespace",
); );
@ -446,10 +470,10 @@ class NixInstallerAction {
const args = ["install"]; const args = ["install"];
if (this.planner) { if (this.planner) {
this.idslib.addFact("nix_installer_planner", this.planner); this.idslib.addFact(FACT_NIX_INSTALLER_PLANNER, this.planner);
args.push(this.planner); args.push(this.planner);
} else { } else {
this.idslib.addFact("nix_installer_planner", getDefaultPlanner()); this.idslib.addFact(FACT_NIX_INSTALLER_PLANNER, getDefaultPlanner());
args.push(getDefaultPlanner()); args.push(getDefaultPlanner());
} }
@ -458,7 +482,7 @@ class NixInstallerAction {
args.concat(extraArgs); args.concat(extraArgs);
} }
this.idslib.recordEvent("install_nix_start"); this.idslib.recordEvent(EVENT_INSTALL_NIX_START);
const exitCode = await actionsExec.exec(binaryPath, args, { const exitCode = await actionsExec.exec(binaryPath, args, {
env: { env: {
...executionEnv, ...executionEnv,
@ -467,13 +491,13 @@ class NixInstallerAction {
}); });
if (exitCode !== 0) { if (exitCode !== 0) {
this.idslib.recordEvent("install_nix_failure", { this.idslib.recordEvent(EVENT_INSTALL_NIX_FAILURE, {
exitCode, exitCode,
}); });
throw new Error(`Non-zero exit code of \`${exitCode}\` detected`); throw new Error(`Non-zero exit code of \`${exitCode}\` detected`);
} }
this.idslib.recordEvent("install_nix_success"); this.idslib.recordEvent(EVENT_INSTALL_NIX_SUCCESS);
return exitCode; return exitCode;
} }
@ -571,7 +595,7 @@ class NixInstallerAction {
{ {
actionsCore.debug("Starting the Nix daemon through Docker..."); actionsCore.debug("Starting the Nix daemon through Docker...");
this.idslib.recordEvent("start_docker_shim"); this.idslib.recordEvent(EVENT_START_DOCKER_SHIM);
const exitCode = await actionsExec.exec( const exitCode = await actionsExec.exec(
"docker", "docker",
[ [
@ -661,7 +685,7 @@ class NixInstallerAction {
} }
if (cleaned) { if (cleaned) {
this.idslib.recordEvent("clean_up_docker_shim"); this.idslib.recordEvent(EVENT_CLEAN_UP_DOCKER_SHIM);
} else { } else {
actionsCore.warning( actionsCore.warning(
"Giving up on cleaning up the nix daemon container", "Giving up on cleaning up the nix daemon container",
@ -690,7 +714,7 @@ class NixInstallerAction {
} }
async flakehubLogin(): Promise<string> { async flakehubLogin(): Promise<string> {
this.idslib.recordEvent("login_to_flakehub"); this.idslib.recordEvent(EVENT_LOGIN_TO_FLAKEHUB);
const netrcPath = `${process.env["RUNNER_TEMP"]}/determinate-nix-installer-netrc`; const netrcPath = `${process.env["RUNNER_TEMP"]}/determinate-nix-installer-netrc`;
const jwt = await actionsCore.getIDToken("api.flakehub.com"); const jwt = await actionsCore.getIDToken("api.flakehub.com");
@ -717,7 +741,7 @@ class NixInstallerAction {
} }
async executeUninstall(): Promise<number> { async executeUninstall(): Promise<number> {
this.idslib.recordEvent("uninstall"); this.idslib.recordEvent(EVENT_UNINSTALL_NIX);
const exitCode = await actionsExec.exec( const exitCode = await actionsExec.exec(
`/nix/nix-installer`, `/nix/nix-installer`,
["uninstall"], ["uninstall"],
@ -749,7 +773,7 @@ class NixInstallerAction {
} }
private async setupKvm(): Promise<boolean> { private async setupKvm(): Promise<boolean> {
this.idslib.recordEvent("setup_kvm"); this.idslib.recordEvent(EVENT_SETUP_KVM);
const currentUser = userInfo(); const currentUser = userInfo();
const isRoot = currentUser.uid === 0; const isRoot = currentUser.uid === 0;
const maybeSudo = isRoot ? "" : "sudo"; const maybeSudo = isRoot ? "" : "sudo";
@ -855,7 +879,7 @@ class NixInstallerAction {
async reportOverall(): Promise<void> { async reportOverall(): Promise<void> {
try { try {
this.idslib.recordEvent("conclude_workflow", { this.idslib.recordEvent(EVENT_CONCLUDE_WORKFLOW, {
conclusion: await this.getWorkflowConclusion(), conclusion: await this.getWorkflowConclusion(),
}); });
} catch (error) { } catch (error) {