Merge pull request #47 from DeterminateSystems/colemickens/fix-stream-close

fix: end the FileStreamWriter for the installer file
This commit is contained in:
Ana Hobden 2023-10-24 09:22:10 -07:00 committed by GitHub
commit 721f94f7df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 534 additions and 561 deletions

View File

@ -47,6 +47,7 @@
"@typescript-eslint/no-array-constructor": "error",
"@typescript-eslint/no-empty-interface": "error",
"@typescript-eslint/no-explicit-any": "error",
"@typescript-eslint/no-floating-promises": "error",
"@typescript-eslint/no-extraneous-class": "error",
"@typescript-eslint/no-for-in-array": "error",
"@typescript-eslint/no-inferrable-types": "error",

400
dist/index.js vendored
View File

@ -2,58 +2,47 @@ require('./sourcemap-register.js');/******/ (() => { // webpackBootstrap
/******/ var __webpack_modules__ = ({
/***/ 3109:
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
/***/ ((module, __webpack_exports__, __nccwpck_require__) => {
"use strict";
__nccwpck_require__.a(module, async (__webpack_handle_async_dependencies__, __webpack_async_result__) => { try {
__nccwpck_require__.r(__webpack_exports__);
/* harmony import */ var _actions_core__WEBPACK_IMPORTED_MODULE_0__ = __nccwpck_require__(2186);
/* harmony import */ var _actions_core__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__nccwpck_require__.n(_actions_core__WEBPACK_IMPORTED_MODULE_0__);
/* harmony import */ var _actions_github__WEBPACK_IMPORTED_MODULE_1__ = __nccwpck_require__(5438);
/* harmony import */ var _actions_github__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__nccwpck_require__.n(_actions_github__WEBPACK_IMPORTED_MODULE_1__);
/* harmony import */ var node_fs_promises__WEBPACK_IMPORTED_MODULE_2__ = __nccwpck_require__(3977);
/* harmony import */ var node_fs_promises__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__nccwpck_require__.n(node_fs_promises__WEBPACK_IMPORTED_MODULE_2__);
/* harmony import */ var node_child_process__WEBPACK_IMPORTED_MODULE_3__ = __nccwpck_require__(7718);
/* harmony import */ var node_child_process__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__nccwpck_require__.n(node_child_process__WEBPACK_IMPORTED_MODULE_3__);
/* harmony import */ var node_crypto__WEBPACK_IMPORTED_MODULE_4__ = __nccwpck_require__(6005);
/* harmony import */ var node_crypto__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__nccwpck_require__.n(node_crypto__WEBPACK_IMPORTED_MODULE_4__);
/* harmony import */ var node_path__WEBPACK_IMPORTED_MODULE_5__ = __nccwpck_require__(9411);
/* harmony import */ var node_path__WEBPACK_IMPORTED_MODULE_5___default = /*#__PURE__*/__nccwpck_require__.n(node_path__WEBPACK_IMPORTED_MODULE_5__);
/* harmony import */ var node_os__WEBPACK_IMPORTED_MODULE_6__ = __nccwpck_require__(612);
/* harmony import */ var node_os__WEBPACK_IMPORTED_MODULE_6___default = /*#__PURE__*/__nccwpck_require__.n(node_os__WEBPACK_IMPORTED_MODULE_6__);
/* harmony import */ var node_stream__WEBPACK_IMPORTED_MODULE_7__ = __nccwpck_require__(4492);
/* harmony import */ var node_stream__WEBPACK_IMPORTED_MODULE_7___default = /*#__PURE__*/__nccwpck_require__.n(node_stream__WEBPACK_IMPORTED_MODULE_7__);
/* harmony import */ var node_stream_promises__WEBPACK_IMPORTED_MODULE_8__ = __nccwpck_require__(6402);
/* harmony import */ var node_stream_promises__WEBPACK_IMPORTED_MODULE_8___default = /*#__PURE__*/__nccwpck_require__.n(node_stream_promises__WEBPACK_IMPORTED_MODULE_8__);
/* harmony import */ var node_fs__WEBPACK_IMPORTED_MODULE_9__ = __nccwpck_require__(7561);
/* harmony import */ var node_fs__WEBPACK_IMPORTED_MODULE_9___default = /*#__PURE__*/__nccwpck_require__.n(node_fs__WEBPACK_IMPORTED_MODULE_9__);
/* harmony import */ var string_argv__WEBPACK_IMPORTED_MODULE_11__ = __nccwpck_require__(1810);
/* harmony import */ var fetch_retry__WEBPACK_IMPORTED_MODULE_10__ = __nccwpck_require__(9068);
/* harmony import */ var fetch_retry__WEBPACK_IMPORTED_MODULE_10___default = /*#__PURE__*/__nccwpck_require__.n(fetch_retry__WEBPACK_IMPORTED_MODULE_10__);
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
const actions_core = __importStar(__nccwpck_require__(2186));
const github = __importStar(__nccwpck_require__(5438));
const promises_1 = __nccwpck_require__(3977);
const node_child_process_1 = __nccwpck_require__(7718);
const node_crypto_1 = __nccwpck_require__(6005);
const node_path_1 = __nccwpck_require__(9411);
const node_os_1 = __nccwpck_require__(612);
const node_stream_1 = __importDefault(__nccwpck_require__(4492));
const node_fs_1 = __importDefault(__nccwpck_require__(7561));
const string_argv_1 = __importDefault(__nccwpck_require__(9663));
const fetch_retry_1 = __importDefault(__nccwpck_require__(9068));
const fetchRetry = (0, fetch_retry_1.default)(global.fetch);
const fetchRetry = fetch_retry__WEBPACK_IMPORTED_MODULE_10___default()(global.fetch);
class NixInstallerAction {
constructor() {
this.platform = get_nix_platform();
@ -87,8 +76,7 @@ class NixInstallerAction {
this.correlation = process.env["STATE_correlation"];
this.nix_installer_url = resolve_nix_installer_url(this.platform, this.correlation);
}
executionEnvironment() {
return __awaiter(this, void 0, void 0, function* () {
async executionEnvironment() {
const execution_env = {};
execution_env.NIX_INSTALLER_NO_CONFIRM = "true";
execution_env.NIX_INSTALLER_DIAGNOSTIC_ATTRIBUTION = this.correlation;
@ -189,7 +177,7 @@ class NixInstallerAction {
extra_conf += "\n";
}
if (this.flakehub) {
extra_conf += `netrc-file = ${yield this.flakehub_login()}`;
extra_conf += `netrc-file = ${await this.flakehub_login()}`;
extra_conf += "\n";
}
if (this.extra_conf !== null && this.extra_conf.length !== 0) {
@ -198,16 +186,14 @@ class NixInstallerAction {
}
execution_env.NIX_INSTALLER_EXTRA_CONF = extra_conf;
if (process.env.ACT && !process.env.NOT_ACT) {
actions_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`");
_actions_core__WEBPACK_IMPORTED_MODULE_0__.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`");
execution_env.NIX_INSTALLER_INIT = "none";
}
return execution_env;
});
}
execute_install(binary_path) {
return __awaiter(this, void 0, void 0, function* () {
const execution_env = yield this.executionEnvironment();
actions_core.info(`Execution environment: ${JSON.stringify(execution_env, null, 4)}`);
async execute_install(binary_path) {
const execution_env = await this.executionEnvironment();
_actions_core__WEBPACK_IMPORTED_MODULE_0__.info(`Execution environment: ${JSON.stringify(execution_env, null, 4)}`);
const args = ["install"];
if (this.planner) {
args.push(this.planner);
@ -216,124 +202,114 @@ class NixInstallerAction {
args.push(get_default_planner());
}
if (this.extra_args) {
const extra_args = (0, string_argv_1.default)(this.extra_args);
const extra_args = (0,string_argv__WEBPACK_IMPORTED_MODULE_11__/* ["default"] */ .Z)(this.extra_args);
args.concat(extra_args);
}
const merged_env = Object.assign(Object.assign({}, process.env), execution_env);
const spawned = (0, node_child_process_1.spawn)(`${binary_path}`, args, {
const spawned = (0,node_child_process__WEBPACK_IMPORTED_MODULE_3__.spawn)(`${binary_path}`, args, {
env: merged_env,
});
spawned.stdout.setEncoding("utf-8");
spawned.stdout.on("data", (data) => {
const trimmed = data.trimEnd();
if (trimmed.length >= 0) {
actions_core.info(trimmed);
_actions_core__WEBPACK_IMPORTED_MODULE_0__.info(trimmed);
}
});
spawned.stderr.setEncoding("utf-8");
spawned.stderr.on("data", (data) => {
const trimmed = data.trimEnd();
if (trimmed.length >= 0) {
actions_core.info(trimmed);
_actions_core__WEBPACK_IMPORTED_MODULE_0__.info(trimmed);
}
});
const exit_code = yield new Promise((resolve, _reject) => {
const exit_code = await new Promise((resolve, _reject) => {
spawned.on("close", resolve);
});
if (exit_code !== 0) {
throw new Error(`Non-zero exit code of \`${exit_code}\` detected`);
}
return exit_code;
});
}
install() {
return __awaiter(this, void 0, void 0, function* () {
const existing_install = yield this.detect_existing();
async install() {
const existing_install = await this.detect_existing();
if (existing_install) {
if (this.reinstall) {
// We need to uninstall, then reinstall
actions_core.info("Nix was already installed, `reinstall` is set, uninstalling for a reinstall");
yield this.execute_uninstall();
_actions_core__WEBPACK_IMPORTED_MODULE_0__.info("Nix was already installed, `reinstall` is set, uninstalling for a reinstall");
await this.execute_uninstall();
}
else {
// We're already installed, and not reinstalling, just set GITHUB_PATH and finish early
yield this.set_github_path();
actions_core.info("Nix was already installed, using existing install");
await this.set_github_path();
_actions_core__WEBPACK_IMPORTED_MODULE_0__.info("Nix was already installed, using existing install");
return;
}
}
// Normal just doing of the install
const binary_path = yield this.fetch_binary();
yield this.execute_install(binary_path);
yield this.set_github_path();
});
const binary_path = await this.fetch_binary();
await this.execute_install(binary_path);
await this.set_github_path();
}
set_github_path() {
return __awaiter(this, void 0, void 0, function* () {
async set_github_path() {
// Interim versions of the `nix-installer` crate may have already manipulated `$GITHUB_PATH`, as root even! Accessing that will be an error.
try {
const nix_var_nix_profile_path = "/nix/var/nix/profiles/default/bin";
const home_nix_profile_path = `${process.env.HOME}/.nix-profile/bin`;
actions_core.addPath(nix_var_nix_profile_path);
actions_core.addPath(home_nix_profile_path);
actions_core.info(`Added \`${nix_var_nix_profile_path}\` and \`${home_nix_profile_path}\` to \`$GITHUB_PATH\``);
_actions_core__WEBPACK_IMPORTED_MODULE_0__.addPath(nix_var_nix_profile_path);
_actions_core__WEBPACK_IMPORTED_MODULE_0__.addPath(home_nix_profile_path);
_actions_core__WEBPACK_IMPORTED_MODULE_0__.info(`Added \`${nix_var_nix_profile_path}\` and \`${home_nix_profile_path}\` to \`$GITHUB_PATH\``);
}
catch (error) {
actions_core.info("Skipping setting $GITHUB_PATH in action, the `nix-installer` crate seems to have done this already. From `nix-installer` version 0.11.0 and up, this step is done in the action. Prior to 0.11.0, this was only done in the `nix-installer` binary.");
_actions_core__WEBPACK_IMPORTED_MODULE_0__.info("Skipping setting $GITHUB_PATH in action, the `nix-installer` crate seems to have done this already. From `nix-installer` version 0.11.0 and up, this step is done in the action. Prior to 0.11.0, this was only done in the `nix-installer` binary.");
}
});
}
flakehub_login() {
async flakehub_login() {
var _a;
return __awaiter(this, void 0, void 0, function* () {
const netrc_path = `${process.env["RUNNER_TEMP"]}/determinate-nix-installer-netrc`;
const jwt = yield actions_core.getIDToken("api.flakehub.com");
yield (0, promises_1.writeFile)(netrc_path, [
const jwt = await _actions_core__WEBPACK_IMPORTED_MODULE_0__.getIDToken("api.flakehub.com");
await (0,node_fs_promises__WEBPACK_IMPORTED_MODULE_2__.writeFile)(netrc_path, [
`machine api.flakehub.com login flakehub password ${jwt}`,
`machine flakehub.com login flakehub password ${jwt}`,
].join("\n"));
actions_core.info("Logging in to FlakeHub.");
_actions_core__WEBPACK_IMPORTED_MODULE_0__.info("Logging in to FlakeHub.");
// the join followed by a match on ^... looks silly, but extra_config
// could contain multi-line values
if ((_a = this.extra_conf) === null || _a === void 0 ? void 0 : _a.join("\n").match(/^netrc-file/m)) {
actions_core.warning("Logging in to FlakeHub conflicts with the Nix option `netrc-file`.");
_actions_core__WEBPACK_IMPORTED_MODULE_0__.warning("Logging in to FlakeHub conflicts with the Nix option `netrc-file`.");
}
return netrc_path;
});
}
execute_uninstall() {
return __awaiter(this, void 0, void 0, function* () {
const spawned = (0, node_child_process_1.spawn)(`/nix/nix-installer`, ["uninstall"], {
async execute_uninstall() {
const spawned = (0,node_child_process__WEBPACK_IMPORTED_MODULE_3__.spawn)(`/nix/nix-installer`, ["uninstall"], {
env: Object.assign({ NIX_INSTALLER_NO_CONFIRM: "true" }, process.env),
});
spawned.stdout.setEncoding("utf-8");
spawned.stdout.on("data", (data) => {
const trimmed = data.trimEnd();
if (trimmed.length >= 0) {
actions_core.info(trimmed);
_actions_core__WEBPACK_IMPORTED_MODULE_0__.info(trimmed);
}
});
spawned.stderr.setEncoding("utf-8");
spawned.stderr.on("data", (data) => {
const trimmed = data.trimEnd();
if (trimmed.length >= 0) {
actions_core.info(trimmed);
_actions_core__WEBPACK_IMPORTED_MODULE_0__.info(trimmed);
}
});
const exit_code = yield new Promise((resolve, _reject) => {
const exit_code = await new Promise((resolve, _reject) => {
spawned.on("close", resolve);
});
if (exit_code !== 0) {
throw new Error(`Non-zero exit code of \`${exit_code}\` detected`);
}
return exit_code;
});
}
detect_existing() {
return __awaiter(this, void 0, void 0, function* () {
async detect_existing() {
const receipt_path = "/nix/receipt.json";
try {
yield (0, promises_1.access)(receipt_path);
await (0,node_fs_promises__WEBPACK_IMPORTED_MODULE_2__.access)(receipt_path);
// There is a /nix/receipt.json
return true;
}
@ -341,13 +317,11 @@ class NixInstallerAction {
// No /nix/receipt.json
return false;
}
});
}
fetch_binary() {
return __awaiter(this, void 0, void 0, function* () {
async fetch_binary() {
if (!this.local_root) {
actions_core.info(`Fetching binary from ${this.nix_installer_url}`);
const response = yield fetchRetry(this.nix_installer_url, {
_actions_core__WEBPACK_IMPORTED_MODULE_0__.info(`Fetching binary from ${this.nix_installer_url}`);
const response = await fetchRetry(this.nix_installer_url, {
retries: 5,
retryDelay(attempt, _error, _response) {
return Math.pow(2, attempt) * 1000; // 1000, 2000, 4000
@ -356,38 +330,40 @@ class NixInstallerAction {
if (!response.ok) {
throw new Error(`Got a status of ${response.status} from \`${this.nix_installer_url}\`, expected a 200`);
}
const tempdir = yield (0, promises_1.mkdtemp)((0, node_path_1.join)((0, node_os_1.tmpdir)(), "nix-installer-"));
const tempfile = (0, node_path_1.join)(tempdir, `nix-installer-${this.platform}`);
if (!response.ok) {
throw new Error(`unexpected response ${response.statusText}`);
}
const tempdir = await (0,node_fs_promises__WEBPACK_IMPORTED_MODULE_2__.mkdtemp)((0,node_path__WEBPACK_IMPORTED_MODULE_5__.join)((0,node_os__WEBPACK_IMPORTED_MODULE_6__.tmpdir)(), "nix-installer-"));
const tempfile = (0,node_path__WEBPACK_IMPORTED_MODULE_5__.join)(tempdir, `nix-installer-${this.platform}`);
if (response.body !== null) {
const fileStream = node_fs_1.default.createWriteStream(tempfile);
const fileStreamWeb = node_stream_1.default.Writable.toWeb(fileStream);
yield response.body.pipeTo(fileStreamWeb);
actions_core.info(`Downloaded \`nix-installer\` to \`${tempfile}\``);
const handle = await (0,node_fs_promises__WEBPACK_IMPORTED_MODULE_2__.open)(tempfile, (node_fs__WEBPACK_IMPORTED_MODULE_9___default().constants.O_CREAT) |
(node_fs__WEBPACK_IMPORTED_MODULE_9___default().constants.O_TRUNC) |
(node_fs__WEBPACK_IMPORTED_MODULE_9___default().constants.O_WRONLY) |
(node_fs__WEBPACK_IMPORTED_MODULE_9___default().constants.O_DSYNC));
const fileStream = handle.createWriteStream();
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const bodyCast = response.body;
const bodyReader = node_stream__WEBPACK_IMPORTED_MODULE_7___default().Readable.fromWeb(bodyCast);
await (0,node_stream_promises__WEBPACK_IMPORTED_MODULE_8__.finished)(bodyReader.pipe(fileStream));
fileStream.close();
_actions_core__WEBPACK_IMPORTED_MODULE_0__.info(`Downloaded \`nix-installer\` to \`${tempfile}\``);
}
else {
throw new Error("No response body recieved");
}
// Make executable
yield (0, promises_1.chmod)(tempfile, node_fs_1.default.constants.S_IXUSR | node_fs_1.default.constants.S_IXGRP);
await (0,node_fs_promises__WEBPACK_IMPORTED_MODULE_2__.chmod)(tempfile, (node_fs__WEBPACK_IMPORTED_MODULE_9___default().constants.S_IXUSR) | (node_fs__WEBPACK_IMPORTED_MODULE_9___default().constants.S_IXGRP));
return tempfile;
}
else {
const local_path = (0, node_path_1.join)(this.local_root, `nix-installer-${this.platform}`);
actions_core.info(`Using binary ${local_path}`);
const local_path = (0,node_path__WEBPACK_IMPORTED_MODULE_5__.join)(this.local_root, `nix-installer-${this.platform}`);
_actions_core__WEBPACK_IMPORTED_MODULE_0__.info(`Using binary ${local_path}`);
return local_path;
}
});
}
report_overall() {
return __awaiter(this, void 0, void 0, function* () {
async report_overall() {
if (this.diagnostic_endpoint == null) {
return;
}
try {
yield fetch(this.diagnostic_endpoint, {
await fetch(this.diagnostic_endpoint, {
method: "POST",
headers: {
"Content-Type": "application/json",
@ -395,30 +371,28 @@ class NixInstallerAction {
body: JSON.stringify({
"post-github-workflow-run-report": true,
correlation: this.correlation,
conclusion: yield this.get_workflow_conclusion(),
conclusion: await this.get_workflow_conclusion(),
}),
});
}
catch (error) {
actions_core.debug(`Error submitting post-run diagnostics report: ${error}`);
_actions_core__WEBPACK_IMPORTED_MODULE_0__.debug(`Error submitting post-run diagnostics report: ${error}`);
}
});
}
get_workflow_conclusion() {
return __awaiter(this, void 0, void 0, function* () {
async get_workflow_conclusion() {
if (this.github_token == null) {
return undefined;
}
try {
const octokit = github.getOctokit(this.github_token);
const jobs = yield octokit.paginate(octokit.rest.actions.listJobsForWorkflowRun, {
owner: github.context.repo.owner,
repo: github.context.repo.repo,
run_id: github.context.runId,
const octokit = _actions_github__WEBPACK_IMPORTED_MODULE_1__.getOctokit(this.github_token);
const jobs = await octokit.paginate(octokit.rest.actions.listJobsForWorkflowRun, {
owner: _actions_github__WEBPACK_IMPORTED_MODULE_1__.context.repo.owner,
repo: _actions_github__WEBPACK_IMPORTED_MODULE_1__.context.repo.repo,
run_id: _actions_github__WEBPACK_IMPORTED_MODULE_1__.context.runId,
});
actions_core.debug(`awaited jobs: ${jobs}`);
_actions_core__WEBPACK_IMPORTED_MODULE_0__.debug(`awaited jobs: ${jobs}`);
const job = jobs
.filter((candidate) => candidate.name === github.context.job)
.filter((candidate) => candidate.name === _actions_github__WEBPACK_IMPORTED_MODULE_1__.context.job)
.at(0);
if (job === undefined) {
return "no-jobs";
@ -438,10 +412,9 @@ class NixInstallerAction {
return "success";
}
catch (error) {
actions_core.debug(`Error determining final disposition: ${error}`);
_actions_core__WEBPACK_IMPORTED_MODULE_0__.debug(`Error determining final disposition: ${error}`);
return "unavailable";
}
});
}
}
function get_nix_platform() {
@ -514,7 +487,7 @@ function resolve_nix_installer_url(platform, correlation) {
return resolved_nix_installer_url;
}
function action_input_string_or_null(name) {
const value = actions_core.getInput(name);
const value = _actions_core__WEBPACK_IMPORTED_MODULE_0__.getInput(name);
if (value === "") {
return null;
}
@ -523,7 +496,7 @@ function action_input_string_or_null(name) {
}
}
function action_input_multiline_string_or_null(name) {
const value = actions_core.getMultilineInput(name);
const value = _actions_core__WEBPACK_IMPORTED_MODULE_0__.getMultilineInput(name);
if (value.length === 0) {
return null;
}
@ -532,7 +505,7 @@ function action_input_multiline_string_or_null(name) {
}
}
function action_input_number_or_null(name) {
const value = actions_core.getInput(name);
const value = _actions_core__WEBPACK_IMPORTED_MODULE_0__.getInput(name);
if (value === "") {
return null;
}
@ -541,34 +514,34 @@ function action_input_number_or_null(name) {
}
}
function action_input_bool(name) {
return actions_core.getBooleanInput(name);
return _actions_core__WEBPACK_IMPORTED_MODULE_0__.getBooleanInput(name);
}
function main() {
return __awaiter(this, void 0, void 0, function* () {
async function main() {
try {
if (!process.env["STATE_correlation"]) {
const correlation = `GH-${(0, node_crypto_1.randomUUID)()}`;
actions_core.saveState("correlation", correlation);
const correlation = `GH-${(0,node_crypto__WEBPACK_IMPORTED_MODULE_4__.randomUUID)()}`;
_actions_core__WEBPACK_IMPORTED_MODULE_0__.saveState("correlation", correlation);
process.env["STATE_correlation"] = correlation;
}
const installer = new NixInstallerAction();
const isPost = !!process.env["STATE_isPost"];
if (!isPost) {
actions_core.saveState("isPost", "true");
yield installer.install();
_actions_core__WEBPACK_IMPORTED_MODULE_0__.saveState("isPost", "true");
await installer.install();
}
else {
installer.report_overall();
await installer.report_overall();
}
}
catch (error) {
if (error instanceof Error)
actions_core.setFailed(error);
_actions_core__WEBPACK_IMPORTED_MODULE_0__.setFailed(error);
}
});
}
main();
await main();
__webpack_async_result__();
} catch(e) { __webpack_async_result__(e); } }, 1);
/***/ }),
@ -13589,6 +13562,14 @@ module.exports = require("node:stream");
/***/ }),
/***/ 6402:
/***/ ((module) => {
"use strict";
module.exports = require("node:stream/promises");
/***/ }),
/***/ 2037:
/***/ ((module) => {
@ -13661,13 +13642,15 @@ module.exports = require("zlib");
/***/ }),
/***/ 9663:
/***/ ((__unused_webpack_module, exports) => {
/***/ 1810:
/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __nccwpck_require__) => {
"use strict";
/* harmony export */ __nccwpck_require__.d(__webpack_exports__, {
/* harmony export */ "Z": () => (/* binding */ parseArgsStringToArgv)
/* harmony export */ });
/* unused harmony export parseArgsStringToArgv */
exports.__esModule = true;
exports.parseArgsStringToArgv = void 0;
function parseArgsStringToArgv(value, env, file) {
// ([^\s'"]([^\s'"]*(['"])([^\3]*?)\3)+[^\s'"]*) Matches nested quotes until the first space outside of quotes
// [^\s'"]+ or Match if not a space ' or "
@ -13694,8 +13677,6 @@ function parseArgsStringToArgv(value, env, file) {
} while (match !== null);
return myArray;
}
exports["default"] = parseArgsStringToArgv;
exports.parseArgsStringToArgv = parseArgsStringToArgv;
// Accepts any number of arguments, and returns the first one that is a string
// (even an empty string)
function firstString() {
@ -13819,6 +13800,115 @@ module.exports = JSON.parse('[[[0,44],"disallowed_STD3_valid"],[[45,46],"valid"]
/******/ }
/******/
/************************************************************************/
/******/ /* webpack/runtime/async module */
/******/ (() => {
/******/ var webpackQueues = typeof Symbol === "function" ? Symbol("webpack queues") : "__webpack_queues__";
/******/ var webpackExports = typeof Symbol === "function" ? Symbol("webpack exports") : "__webpack_exports__";
/******/ var webpackError = typeof Symbol === "function" ? Symbol("webpack error") : "__webpack_error__";
/******/ var resolveQueue = (queue) => {
/******/ if(queue && !queue.d) {
/******/ queue.d = 1;
/******/ queue.forEach((fn) => (fn.r--));
/******/ queue.forEach((fn) => (fn.r-- ? fn.r++ : fn()));
/******/ }
/******/ }
/******/ var wrapDeps = (deps) => (deps.map((dep) => {
/******/ if(dep !== null && typeof dep === "object") {
/******/ if(dep[webpackQueues]) return dep;
/******/ if(dep.then) {
/******/ var queue = [];
/******/ queue.d = 0;
/******/ dep.then((r) => {
/******/ obj[webpackExports] = r;
/******/ resolveQueue(queue);
/******/ }, (e) => {
/******/ obj[webpackError] = e;
/******/ resolveQueue(queue);
/******/ });
/******/ var obj = {};
/******/ obj[webpackQueues] = (fn) => (fn(queue));
/******/ return obj;
/******/ }
/******/ }
/******/ var ret = {};
/******/ ret[webpackQueues] = x => {};
/******/ ret[webpackExports] = dep;
/******/ return ret;
/******/ }));
/******/ __nccwpck_require__.a = (module, body, hasAwait) => {
/******/ var queue;
/******/ hasAwait && ((queue = []).d = 1);
/******/ var depQueues = new Set();
/******/ var exports = module.exports;
/******/ var currentDeps;
/******/ var outerResolve;
/******/ var reject;
/******/ var promise = new Promise((resolve, rej) => {
/******/ reject = rej;
/******/ outerResolve = resolve;
/******/ });
/******/ promise[webpackExports] = exports;
/******/ promise[webpackQueues] = (fn) => (queue && fn(queue), depQueues.forEach(fn), promise["catch"](x => {}));
/******/ module.exports = promise;
/******/ body((deps) => {
/******/ currentDeps = wrapDeps(deps);
/******/ var fn;
/******/ var getResult = () => (currentDeps.map((d) => {
/******/ if(d[webpackError]) throw d[webpackError];
/******/ return d[webpackExports];
/******/ }))
/******/ var promise = new Promise((resolve) => {
/******/ fn = () => (resolve(getResult));
/******/ fn.r = 0;
/******/ var fnQueue = (q) => (q !== queue && !depQueues.has(q) && (depQueues.add(q), q && !q.d && (fn.r++, q.push(fn))));
/******/ currentDeps.map((dep) => (dep[webpackQueues](fnQueue)));
/******/ });
/******/ return fn.r ? promise : getResult();
/******/ }, (err) => ((err ? reject(promise[webpackError] = err) : outerResolve(exports)), resolveQueue(queue)));
/******/ queue && (queue.d = 0);
/******/ };
/******/ })();
/******/
/******/ /* webpack/runtime/compat get default export */
/******/ (() => {
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __nccwpck_require__.n = (module) => {
/******/ var getter = module && module.__esModule ?
/******/ () => (module['default']) :
/******/ () => (module);
/******/ __nccwpck_require__.d(getter, { a: getter });
/******/ return getter;
/******/ };
/******/ })();
/******/
/******/ /* webpack/runtime/define property getters */
/******/ (() => {
/******/ // define getter functions for harmony exports
/******/ __nccwpck_require__.d = (exports, definition) => {
/******/ for(var key in definition) {
/******/ if(__nccwpck_require__.o(definition, key) && !__nccwpck_require__.o(exports, key)) {
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
/******/ }
/******/ }
/******/ };
/******/ })();
/******/
/******/ /* webpack/runtime/hasOwnProperty shorthand */
/******/ (() => {
/******/ __nccwpck_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
/******/ })();
/******/
/******/ /* webpack/runtime/make namespace object */
/******/ (() => {
/******/ // define __esModule on exports
/******/ __nccwpck_require__.r = (exports) => {
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ }
/******/ Object.defineProperty(exports, '__esModule', { value: true });
/******/ };
/******/ })();
/******/
/******/ /* webpack/runtime/compat */
/******/
/******/ if (typeof __nccwpck_require__ !== 'undefined') __nccwpck_require__.ab = __dirname + "/";
@ -13827,7 +13917,7 @@ module.exports = JSON.parse('[[[0,44],"disallowed_STD3_valid"],[[45,46],"valid"]
/******/
/******/ // startup
/******/ // Load entry module and return exports
/******/ // This entry module is referenced by other modules so it can't be inlined
/******/ // This entry module used 'module' so it can't be inlined
/******/ var __webpack_exports__ = __nccwpck_require__(3109);
/******/ module.exports = __webpack_exports__;
/******/

2
dist/index.js.map vendored

File diff suppressed because one or more lines are too long

127
package-lock.json generated
View File

@ -12,7 +12,6 @@
"@actions/core": "^1.10.0",
"@actions/github": "^5.1.1",
"fetch-retry": "^5.0.6",
"node-fetch": "^3.3.1",
"string-argv": "^0.3.2"
},
"devDependencies": {
@ -912,14 +911,6 @@
"node": ">= 8"
}
},
"node_modules/data-uri-to-buffer": {
"version": "4.0.1",
"resolved": "https://registry.npmjs.org/data-uri-to-buffer/-/data-uri-to-buffer-4.0.1.tgz",
"integrity": "sha512-0R9ikRb668HB7QDxT1vkpuUBtqc53YyAwMwGeUFKRojY/NWKvdZ+9UYtRfGmhqNbRkTSVpMbmyhXipFFv2cb/A==",
"engines": {
"node": ">= 12"
}
},
"node_modules/debug": {
"version": "4.3.4",
"resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz",
@ -1672,28 +1663,6 @@
"reusify": "^1.0.4"
}
},
"node_modules/fetch-blob": {
"version": "3.2.0",
"resolved": "https://registry.npmjs.org/fetch-blob/-/fetch-blob-3.2.0.tgz",
"integrity": "sha512-7yAQpD2UMJzLi1Dqv7qFYnPbaPx7ZfFK6PiIxQ4PfkGPyNyl2Ugx+a/umUonmKqjhM4DnfbMvdX6otXq83soQQ==",
"funding": [
{
"type": "github",
"url": "https://github.com/sponsors/jimmywarting"
},
{
"type": "paypal",
"url": "https://paypal.me/jimmywarting"
}
],
"dependencies": {
"node-domexception": "^1.0.0",
"web-streams-polyfill": "^3.0.3"
},
"engines": {
"node": "^12.20 || >= 14.13"
}
},
"node_modules/fetch-retry": {
"version": "5.0.6",
"resolved": "https://registry.npmjs.org/fetch-retry/-/fetch-retry-5.0.6.tgz",
@ -1767,17 +1736,6 @@
"is-callable": "^1.1.3"
}
},
"node_modules/formdata-polyfill": {
"version": "4.0.10",
"resolved": "https://registry.npmjs.org/formdata-polyfill/-/formdata-polyfill-4.0.10.tgz",
"integrity": "sha512-buewHzMvYL29jdeQTVILecSaZKnt/RJWjoZCF5OW60Z67/GmSLBkOFM7qh1PI3zFNtJbaZL5eQu1vLfazOwj4g==",
"dependencies": {
"fetch-blob": "^3.1.2"
},
"engines": {
"node": ">=12.20.0"
}
},
"node_modules/fs.realpath": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz",
@ -2634,41 +2592,6 @@
"integrity": "sha512-Tj+HTDSJJKaZnfiuw+iaF9skdPpTo2GtEly5JHnWV/hfv2Qj/9RKsGISQtLh2ox3l5EAGw487hnBee0sIJ6v2g==",
"dev": true
},
"node_modules/node-domexception": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/node-domexception/-/node-domexception-1.0.0.tgz",
"integrity": "sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ==",
"funding": [
{
"type": "github",
"url": "https://github.com/sponsors/jimmywarting"
},
{
"type": "github",
"url": "https://paypal.me/jimmywarting"
}
],
"engines": {
"node": ">=10.5.0"
}
},
"node_modules/node-fetch": {
"version": "3.3.2",
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-3.3.2.tgz",
"integrity": "sha512-dRB78srN/l6gqWulah9SrxeYnxeddIG30+GOqK/9OlLVyLg3HPnr6SqOWTWOXKRwC2eGYCkZ59NNuSgvSrpgOA==",
"dependencies": {
"data-uri-to-buffer": "^4.0.0",
"fetch-blob": "^3.1.4",
"formdata-polyfill": "^4.0.10"
},
"engines": {
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
},
"funding": {
"type": "opencollective",
"url": "https://opencollective.com/node-fetch"
}
},
"node_modules/node-releases": {
"version": "2.0.13",
"resolved": "https://registry.npmjs.org/node-releases/-/node-releases-2.0.13.tgz",
@ -3618,14 +3541,6 @@
"uuid": "dist/bin/uuid"
}
},
"node_modules/web-streams-polyfill": {
"version": "3.2.1",
"resolved": "https://registry.npmjs.org/web-streams-polyfill/-/web-streams-polyfill-3.2.1.tgz",
"integrity": "sha512-e0MO3wdXWKrLbL0DgGnUV7WHVuw9OUvL4hjgnPkIeEvESk74gAITi5G606JtZPp39cd8HA9VQzCIvA49LpPN5Q==",
"engines": {
"node": ">= 8"
}
},
"node_modules/webidl-conversions": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz",
@ -4334,11 +4249,6 @@
"which": "^2.0.1"
}
},
"data-uri-to-buffer": {
"version": "4.0.1",
"resolved": "https://registry.npmjs.org/data-uri-to-buffer/-/data-uri-to-buffer-4.0.1.tgz",
"integrity": "sha512-0R9ikRb668HB7QDxT1vkpuUBtqc53YyAwMwGeUFKRojY/NWKvdZ+9UYtRfGmhqNbRkTSVpMbmyhXipFFv2cb/A=="
},
"debug": {
"version": "4.3.4",
"resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz",
@ -4896,15 +4806,6 @@
"reusify": "^1.0.4"
}
},
"fetch-blob": {
"version": "3.2.0",
"resolved": "https://registry.npmjs.org/fetch-blob/-/fetch-blob-3.2.0.tgz",
"integrity": "sha512-7yAQpD2UMJzLi1Dqv7qFYnPbaPx7ZfFK6PiIxQ4PfkGPyNyl2Ugx+a/umUonmKqjhM4DnfbMvdX6otXq83soQQ==",
"requires": {
"node-domexception": "^1.0.0",
"web-streams-polyfill": "^3.0.3"
}
},
"fetch-retry": {
"version": "5.0.6",
"resolved": "https://registry.npmjs.org/fetch-retry/-/fetch-retry-5.0.6.tgz",
@ -4963,14 +4864,6 @@
"is-callable": "^1.1.3"
}
},
"formdata-polyfill": {
"version": "4.0.10",
"resolved": "https://registry.npmjs.org/formdata-polyfill/-/formdata-polyfill-4.0.10.tgz",
"integrity": "sha512-buewHzMvYL29jdeQTVILecSaZKnt/RJWjoZCF5OW60Z67/GmSLBkOFM7qh1PI3zFNtJbaZL5eQu1vLfazOwj4g==",
"requires": {
"fetch-blob": "^3.1.2"
}
},
"fs.realpath": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz",
@ -5568,21 +5461,6 @@
"integrity": "sha512-Tj+HTDSJJKaZnfiuw+iaF9skdPpTo2GtEly5JHnWV/hfv2Qj/9RKsGISQtLh2ox3l5EAGw487hnBee0sIJ6v2g==",
"dev": true
},
"node-domexception": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/node-domexception/-/node-domexception-1.0.0.tgz",
"integrity": "sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ=="
},
"node-fetch": {
"version": "3.3.2",
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-3.3.2.tgz",
"integrity": "sha512-dRB78srN/l6gqWulah9SrxeYnxeddIG30+GOqK/9OlLVyLg3HPnr6SqOWTWOXKRwC2eGYCkZ59NNuSgvSrpgOA==",
"requires": {
"data-uri-to-buffer": "^4.0.0",
"fetch-blob": "^3.1.4",
"formdata-polyfill": "^4.0.10"
}
},
"node-releases": {
"version": "2.0.13",
"resolved": "https://registry.npmjs.org/node-releases/-/node-releases-2.0.13.tgz",
@ -6214,11 +6092,6 @@
"resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz",
"integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg=="
},
"web-streams-polyfill": {
"version": "3.2.1",
"resolved": "https://registry.npmjs.org/web-streams-polyfill/-/web-streams-polyfill-3.2.1.tgz",
"integrity": "sha512-e0MO3wdXWKrLbL0DgGnUV7WHVuw9OUvL4hjgnPkIeEvESk74gAITi5G606JtZPp39cd8HA9VQzCIvA49LpPN5Q=="
},
"webidl-conversions": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz",

View File

@ -1,11 +1,13 @@
import * as actions_core from "@actions/core";
import * as github from "@actions/github";
import { mkdtemp, chmod, access, writeFile } from "node:fs/promises";
import { mkdtemp, chmod, access, writeFile, open } from "node:fs/promises";
import { spawn } from "node:child_process";
import { randomUUID } from "node:crypto";
import { join } from "node:path";
import { tmpdir } from "node:os";
import stream from "node:stream";
import stream_web from "node:stream/web";
import { finished } from "node:stream/promises";
import fs from "node:fs";
import stringArgv from "string-argv";
@ -429,14 +431,20 @@ class NixInstallerAction {
const tempdir = await mkdtemp(join(tmpdir(), "nix-installer-"));
const tempfile = join(tempdir, `nix-installer-${this.platform}`);
if (!response.ok) {
throw new Error(`unexpected response ${response.statusText}`);
}
if (response.body !== null) {
const fileStream = fs.createWriteStream(tempfile);
const fileStreamWeb = stream.Writable.toWeb(fileStream);
await response.body.pipeTo(fileStreamWeb);
const handle = await open(
tempfile,
fs.constants.O_CREAT |
fs.constants.O_TRUNC |
fs.constants.O_WRONLY |
fs.constants.O_DSYNC,
);
const fileStream = handle.createWriteStream();
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const bodyCast = response.body as stream_web.ReadableStream<any>;
const bodyReader = stream.Readable.fromWeb(bodyCast);
await finished(bodyReader.pipe(fileStream));
fileStream.close();
actions_core.info(`Downloaded \`nix-installer\` to \`${tempfile}\``);
} else {
@ -692,11 +700,11 @@ async function main(): Promise<void> {
actions_core.saveState("isPost", "true");
await installer.install();
} else {
installer.report_overall();
await installer.report_overall();
}
} catch (error) {
if (error instanceof Error) actions_core.setFailed(error);
}
}
main();
await main();

View File

@ -1,7 +1,8 @@
{
"compilerOptions": {
"target": "es6", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
"target": "es2017", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */
"module": "esnext",
"moduleResolution": "node",
"outDir": "./lib", /* Redirect output structure to the directory. */
"rootDir": "./src", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
"strict": true, /* Enable all strict type-checking options. */