Skip to content

Commit f8468be

Browse files
AButlerCopilot
andcommitted
Review comments
Co-authored-by: Copilot <copilot@github.com>
1 parent 963d4c0 commit f8468be

3 files changed

Lines changed: 25 additions & 27 deletions

File tree

‎__tests__/main.test.ts‎

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ const {
1515
mockGetOctokit,
1616
mockContext,
1717
mockFg,
18-
mockReadFileSync,
19-
mockStatSync,
18+
mockReadFile,
19+
mockStat,
2020
mockMimeLookup,
2121
} = vi.hoisted(() => {
2222
const mockGetReleaseByTag = vi.fn();
@@ -52,8 +52,8 @@ const {
5252
payload: { release: { id: 99 } },
5353
},
5454
mockFg: vi.fn(),
55-
mockReadFileSync: vi.fn(() => Buffer.from("file-content")),
56-
mockStatSync: vi.fn(() => ({ size: 12 })),
55+
mockReadFile: vi.fn(() => Promise.resolve(Buffer.from("file-content"))),
56+
mockStat: vi.fn(() => Promise.resolve({ size: 12 })),
5757
mockMimeLookup: vi.fn(() => "text/plain"),
5858
};
5959
});
@@ -71,11 +71,9 @@ vi.mock("@actions/github", () => ({
7171

7272
vi.mock("fast-glob", () => ({ default: mockFg }));
7373

74-
vi.mock("fs", () => ({
75-
default: {
76-
readFileSync: mockReadFileSync,
77-
statSync: mockStatSync,
78-
},
74+
vi.mock("fs/promises", () => ({
75+
readFile: mockReadFile,
76+
stat: mockStat,
7977
}));
8078

8179
vi.mock("mime-types", () => ({

‎dist/main.js‎

Lines changed: 14 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/run.ts‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { getInput, setFailed, debug } from "@actions/core";
22
import { context, getOctokit } from "@actions/github";
33
import fg from "fast-glob";
4-
import fs from "fs";
4+
import { readFile, stat } from "fs/promises";
55
import path from "path";
66
import mime from "mime-types";
77

@@ -89,15 +89,15 @@ export async function run() {
8989
});
9090
}
9191

92-
const fileStream = fs.readFileSync(file);
92+
const fileStream = await readFile(file);
9393
const contentType = mime.lookup(file) || "application/zip";
9494

9595
console.log(`Uploading ${file}...`);
9696
debug(`Content-Type = '${contentType}'`);
9797

9898
const headers = {
9999
"content-type": contentType,
100-
"content-length": fs.statSync(file).size,
100+
"content-length": (await stat(file)).size,
101101
};
102102

103103
await octokit.rest.repos.uploadReleaseAsset({
@@ -106,7 +106,7 @@ export async function run() {
106106
release_id: release_id,
107107
headers,
108108
name: fileName,
109-
// Octokits typings only accept string, but the code also accepts Buffer, so this tricks Typescript into allowing the buffer
109+
// Octokits typings only accept string, but the code also accepts Buffer, so this tricks TypeScript into allowing the buffer
110110
data: fileStream as unknown as string,
111111
});
112112
}

0 commit comments

Comments
 (0)