Skip to content

Commit

Permalink
retries: switch back to piping with non-web node streams
Browse files Browse the repository at this point in the history
  • Loading branch information
colemickens committed Oct 24, 2023
1 parent 663467b commit d46d5b1
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 15 deletions.
35 changes: 24 additions & 11 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@ __nccwpck_require__.r(__webpack_exports__);
/* 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_fs__WEBPACK_IMPORTED_MODULE_8__ = __nccwpck_require__(7561);
/* harmony import */ var node_fs__WEBPACK_IMPORTED_MODULE_8___default = /*#__PURE__*/__nccwpck_require__.n(node_fs__WEBPACK_IMPORTED_MODULE_8__);
/* harmony import */ var string_argv__WEBPACK_IMPORTED_MODULE_10__ = __nccwpck_require__(1810);
/* harmony import */ var fetch_retry__WEBPACK_IMPORTED_MODULE_9__ = __nccwpck_require__(9068);
/* harmony import */ var fetch_retry__WEBPACK_IMPORTED_MODULE_9___default = /*#__PURE__*/__nccwpck_require__.n(fetch_retry__WEBPACK_IMPORTED_MODULE_9__);
/* 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__);



Expand All @@ -39,7 +41,8 @@ __nccwpck_require__.r(__webpack_exports__);



const fetchRetry = fetch_retry__WEBPACK_IMPORTED_MODULE_9___default()(global.fetch);

const fetchRetry = fetch_retry__WEBPACK_IMPORTED_MODULE_10___default()(global.fetch);
class NixInstallerAction {
constructor() {
this.platform = get_nix_platform();
Expand Down Expand Up @@ -199,7 +202,7 @@ class NixInstallerAction {
args.push(get_default_planner());
}
if (this.extra_args) {
const extra_args = (0,string_argv__WEBPACK_IMPORTED_MODULE_10__/* ["default"] */ .Z)(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);
Expand Down Expand Up @@ -332,18 +335,20 @@ class NixInstallerAction {
if (response.body !== null) {
const handle = await (0,node_fs_promises__WEBPACK_IMPORTED_MODULE_2__.open)(tempfile, "w");
const fileStream = handle.createWriteStream({ autoClose: false });
const fileStreamWeb = node_stream__WEBPACK_IMPORTED_MODULE_7___default().Writable.toWeb(fileStream);
await response.body.pipeTo(fileStreamWeb);
// fileStreamWeb is auto-closed by pipeTo, confirmed
// 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();
await handle.sync();
await handle.close();
_actions_core__WEBPACK_IMPORTED_MODULE_0__.info(`Downloaded \`nix-installer\` to \`${tempfile}\``);
}
else {
throw new Error("No response body recieved");
}
// Make executable
await (0,node_fs_promises__WEBPACK_IMPORTED_MODULE_2__.chmod)(tempfile, (node_fs__WEBPACK_IMPORTED_MODULE_8___default().constants.S_IXUSR) | (node_fs__WEBPACK_IMPORTED_MODULE_8___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 {
Expand Down Expand Up @@ -13556,6 +13561,14 @@ module.exports = require("node:stream");

/***/ }),

/***/ 6402:
/***/ ((module) => {

"use strict";
module.exports = require("node:stream/promises");

/***/ }),

/***/ 2037:
/***/ ((module) => {

Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

10 changes: 7 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ 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";

Expand Down Expand Up @@ -432,11 +434,13 @@ class NixInstallerAction {
if (response.body !== null) {
const handle = await open(tempfile, "w");
const fileStream = handle.createWriteStream({ autoClose: false });
const fileStreamWeb = stream.Writable.toWeb(fileStream);
await response.body.pipeTo(fileStreamWeb);
// fileStreamWeb is auto-closed by pipeTo, confirmed
// 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();
await handle.sync();
await handle.close();

actions_core.info(`Downloaded \`nix-installer\` to \`${tempfile}\``);
} else {
Expand Down

0 comments on commit d46d5b1

Please sign in to comment.