Skip to content

Commit

Permalink
Merge pull request #47 from DeterminateSystems/colemickens/fix-stream…
Browse files Browse the repository at this point in the history
…-close

fix: end the FileStreamWriter for the installer file
  • Loading branch information
Hoverbear committed Oct 24, 2023
2 parents a5a150b + bb22c86 commit 721f94f
Show file tree
Hide file tree
Showing 6 changed files with 520 additions and 547 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -71,4 +72,4 @@
"node": true,
"es6": true
}
}
}
900 changes: 495 additions & 405 deletions dist/index.js

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

127 changes: 0 additions & 127 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 18 additions & 10 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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();
7 changes: 4 additions & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -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. */
Expand All @@ -12,4 +13,4 @@
"node_modules",
"**/*.test.ts"
]
}
}

0 comments on commit 721f94f

Please sign in to comment.