fix(monitor): use global console channel and implement shard filtering #87
+14
-24
@@ -12,19 +12,19 @@ vi.mock("@actions/core", () => ({
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
import * as artifact from "@actions/artifact";
|
import * as artifact from "@actions/artifact";
|
||||||
vi.mock("@actions/artifact", () => ({
|
vi.mock("@actions/artifact", () => {
|
||||||
DefaultArtifactClient: class {
|
const mockClient = {
|
||||||
uploadArtifact() {
|
uploadArtifact: vi.fn().mockResolvedValue({}),
|
||||||
return Promise.resolve({});
|
};
|
||||||
}
|
return {
|
||||||
},
|
create: vi.fn(() => mockClient),
|
||||||
}));
|
};
|
||||||
|
});
|
||||||
|
|
||||||
import * as core from "@actions/core";
|
import * as core from "@actions/core";
|
||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
import os from "os";
|
import os from "os";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import { DefaultArtifactClient } from "@actions/artifact";
|
|
||||||
|
|
||||||
import {
|
import {
|
||||||
isOfficialServer,
|
isOfficialServer,
|
||||||
@@ -178,29 +178,22 @@ describe("uploadLogArtifacts", () => {
|
|||||||
vi.clearAllMocks();
|
vi.clearAllMocks();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("instantiates DefaultArtifactClient and calls uploadArtifact", async () => {
|
it("instantiates client and calls uploadArtifact", async () => {
|
||||||
const spy = vi.spyOn(
|
|
||||||
artifact.DefaultArtifactClient.prototype,
|
|
||||||
"uploadArtifact",
|
|
||||||
);
|
|
||||||
await uploadLogArtifacts(
|
await uploadLogArtifacts(
|
||||||
["/path/to/shard0_console_log.txt"],
|
["/path/to/shard0_console_log.txt"],
|
||||||
"custom-name",
|
"custom-name",
|
||||||
);
|
);
|
||||||
expect(spy).toHaveBeenCalledWith(
|
expect(artifact.create().uploadArtifact).toHaveBeenCalledWith(
|
||||||
"custom-name",
|
"custom-name",
|
||||||
["/path/to/shard0_console_log.txt"],
|
["/path/to/shard0_console_log.txt"],
|
||||||
"/path/to",
|
"/path/to",
|
||||||
|
{ continueOnError: true },
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("does nothing if filePaths is empty", async () => {
|
it("does nothing if filePaths is empty", async () => {
|
||||||
const spy = vi.spyOn(
|
|
||||||
artifact.DefaultArtifactClient.prototype,
|
|
||||||
"uploadArtifact",
|
|
||||||
);
|
|
||||||
await uploadLogArtifacts([]);
|
await uploadLogArtifacts([]);
|
||||||
expect(spy).not.toHaveBeenCalled();
|
expect(artifact.create().uploadArtifact).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -622,22 +615,19 @@ describe("monitorConsole", () => {
|
|||||||
}, 50);
|
}, 50);
|
||||||
|
|
||||||
// Verify uploadArtifact was called with two files
|
// Verify uploadArtifact was called with two files
|
||||||
const spy = vi.spyOn(
|
|
||||||
artifact.DefaultArtifactClient.prototype,
|
|
||||||
"uploadArtifact",
|
|
||||||
);
|
|
||||||
await monitorConsole(api, {
|
await monitorConsole(api, {
|
||||||
...BASE_OPTS,
|
...BASE_OPTS,
|
||||||
logToFile: true,
|
logToFile: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(spy).toHaveBeenCalledWith(
|
expect(artifact.create().uploadArtifact).toHaveBeenCalledWith(
|
||||||
"screeps-console-log",
|
"screeps-console-log",
|
||||||
expect.arrayContaining([
|
expect.arrayContaining([
|
||||||
expect.stringContaining("shard0_console_log.txt"),
|
expect.stringContaining("shard0_console_log.txt"),
|
||||||
expect.stringContaining("shard1_console_log.txt"),
|
expect.stringContaining("shard1_console_log.txt"),
|
||||||
]),
|
]),
|
||||||
expect.any(String),
|
expect.any(String),
|
||||||
|
{ continueOnError: true },
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Vendored
+11
-84
File diff suppressed because one or more lines are too long
+5
-3
@@ -1,5 +1,5 @@
|
|||||||
import * as core from "@actions/core";
|
import * as core from "@actions/core";
|
||||||
import { DefaultArtifactClient } from "@actions/artifact";
|
import { create } from "@actions/artifact";
|
||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import os from "os";
|
import os from "os";
|
||||||
@@ -143,9 +143,11 @@ export async function uploadLogArtifacts(
|
|||||||
) {
|
) {
|
||||||
if (!filePaths || filePaths.length === 0) return;
|
if (!filePaths || filePaths.length === 0) return;
|
||||||
try {
|
try {
|
||||||
const client = new DefaultArtifactClient();
|
const client = create();
|
||||||
const rootDir = path.dirname(filePaths[0]);
|
const rootDir = path.dirname(filePaths[0]);
|
||||||
await client.uploadArtifact(artifactName, filePaths, rootDir);
|
await client.uploadArtifact(artifactName, filePaths, rootDir, {
|
||||||
|
continueOnError: true,
|
||||||
|
});
|
||||||
core.info(`[Monitor] Console logs uploaded as artifact '${artifactName}'.`);
|
core.info(`[Monitor] Console logs uploaded as artifact '${artifactName}'.`);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
core.warning(
|
core.warning(
|
||||||
|
|||||||
Generated
+28
-1816
File diff suppressed because it is too large
Load Diff
@@ -10,6 +10,7 @@
|
|||||||
"build": "ncc build index.js -o dist -m --external utf-8-validate --external bufferutil"
|
"build": "ncc build index.js -o dist -m --external utf-8-validate --external bufferutil"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@actions/artifact": "^1.1.2",
|
||||||
"@actions/core": "^3.0.0",
|
"@actions/core": "^3.0.0",
|
||||||
"glob": "^13.0.0",
|
"glob": "^13.0.0",
|
||||||
"screeps-api": "^1.7.2"
|
"screeps-api": "^1.7.2"
|
||||||
|
|||||||
Reference in New Issue
Block a user