fix(monitor): use global console channel and implement shard filtering #87

Merged
Philipp merged 3 commits from fix/shard-monitoring into main 2026-05-16 22:29:25 +02:00
5 changed files with 59 additions and 1927 deletions
Showing only changes of commit 1874e823e3 - Show all commits
+14 -24
View File
@@ -12,19 +12,19 @@ vi.mock("@actions/core", () => ({
}));
import * as artifact from "@actions/artifact";
vi.mock("@actions/artifact", () => ({
DefaultArtifactClient: class {
uploadArtifact() {
return Promise.resolve({});
}
},
}));
vi.mock("@actions/artifact", () => {
const mockClient = {
uploadArtifact: vi.fn().mockResolvedValue({}),
};
return {
create: vi.fn(() => mockClient),
};
});
import * as core from "@actions/core";
import fs from "fs";
import os from "os";
import path from "path";
import { DefaultArtifactClient } from "@actions/artifact";
import {
isOfficialServer,
@@ -178,29 +178,22 @@ describe("uploadLogArtifacts", () => {
vi.clearAllMocks();
});
it("instantiates DefaultArtifactClient and calls uploadArtifact", async () => {
const spy = vi.spyOn(
artifact.DefaultArtifactClient.prototype,
"uploadArtifact",
);
it("instantiates client and calls uploadArtifact", async () => {
await uploadLogArtifacts(
["/path/to/shard0_console_log.txt"],
"custom-name",
);
expect(spy).toHaveBeenCalledWith(
expect(artifact.create().uploadArtifact).toHaveBeenCalledWith(
"custom-name",
["/path/to/shard0_console_log.txt"],
"/path/to",
{ continueOnError: true },
);
});
it("does nothing if filePaths is empty", async () => {
const spy = vi.spyOn(
artifact.DefaultArtifactClient.prototype,
"uploadArtifact",
);
await uploadLogArtifacts([]);
expect(spy).not.toHaveBeenCalled();
expect(artifact.create().uploadArtifact).not.toHaveBeenCalled();
});
});
@@ -622,22 +615,19 @@ describe("monitorConsole", () => {
}, 50);
// Verify uploadArtifact was called with two files
const spy = vi.spyOn(
artifact.DefaultArtifactClient.prototype,
"uploadArtifact",
);
await monitorConsole(api, {
...BASE_OPTS,
logToFile: true,
});
expect(spy).toHaveBeenCalledWith(
expect(artifact.create().uploadArtifact).toHaveBeenCalledWith(
"screeps-console-log",
expect.arrayContaining([
expect.stringContaining("shard0_console_log.txt"),
expect.stringContaining("shard1_console_log.txt"),
]),
expect.any(String),
{ continueOnError: true },
);
});
});
+11 -84
View File
File diff suppressed because one or more lines are too long
+5 -3
View File
@@ -1,5 +1,5 @@
import * as core from "@actions/core";
import { DefaultArtifactClient } from "@actions/artifact";
import { create } from "@actions/artifact";
import fs from "fs";
import path from "path";
import os from "os";
@@ -143,9 +143,11 @@ export async function uploadLogArtifacts(
) {
if (!filePaths || filePaths.length === 0) return;
try {
const client = new DefaultArtifactClient();
const client = create();
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}'.`);
} catch (err) {
core.warning(
+28 -1816
View File
File diff suppressed because it is too large Load Diff
+1
View File
@@ -10,6 +10,7 @@
"build": "ncc build index.js -o dist -m --external utf-8-validate --external bufferutil"
},
"dependencies": {
"@actions/artifact": "^1.1.2",
"@actions/core": "^3.0.0",
"glob": "^13.0.0",
"screeps-api": "^1.7.2"