Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: support groups in interleaved parallel job outputs #62

Merged
merged 4 commits into from
Dec 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
bin/
node_modules/
coverage/
build/
build/
.idea/
10 changes: 5 additions & 5 deletions src/output-parser/output-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ export class OutputParser {
// keep track of groups for the current step of a job
private groupMatrix: Record<string, Group[]>;

private isPartOfGroup: boolean;
private isPartOfGroup: Record<string, boolean>;

constructor(output: string) {
this.output = output;
this.stepMatrix = {};
this.outputMatrix = {};
this.groupMatrix = {};
this.isPartOfGroup = false;
this.isPartOfGroup = {};
}

/**
Expand Down Expand Up @@ -140,7 +140,7 @@ export class OutputParser {
// if the line is an output line
if (stepOutputMatcherResult !== null) {
// if output is part of some group then update it
if (this.isPartOfGroup) {
if (this.isPartOfGroup[stepOutputMatcherResult[1]]) {
const length = this.groupMatrix[stepOutputMatcherResult[1]].length;
this.groupMatrix[stepOutputMatcherResult[1]][length - 1].output +=
stepOutputMatcherResult[2] + "\n";
Expand All @@ -167,7 +167,7 @@ export class OutputParser {
name: startGroupMatcherResult[2],
output: "",
});
this.isPartOfGroup = true;
this.isPartOfGroup[startGroupMatcherResult[1]] = true;
}
}

Expand All @@ -187,7 +187,7 @@ export class OutputParser {
const length = this.groupMatrix[endGroupMatcherResult[1]].length;
this.groupMatrix[endGroupMatcherResult[1]][length - 1].output =
this.groupMatrix[endGroupMatcherResult[1]][length - 1].output.trim();
this.isPartOfGroup = false;
this.isPartOfGroup[endGroupMatcherResult[1]] = false;
}
}

Expand Down
111 changes: 111 additions & 0 deletions test/unit/output-parser/output-parser.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
import { OutputParser } from "@aj/output-parser/output-parser";
import path from "path";
import fs from "fs";

describe("parseOutput", () => {
const resources = path.resolve(process.cwd(), "test", "unit", "resources", "output-parser");

describe("groups", () => {
test("some groups", async () => {
const output = fs.readFileSync(path.join(resources, "act-groups-sorted.log")).toString();
const parser = new OutputParser(output);

const result = parser.parseOutput();

expect(result).toStrictEqual([
{
"groups": [
{
"name": "Unit Tests",
"output": "1231 tests executed."
},
{
"name": "Integration Tests",
"output": "32 tests executed."
}
],
"name": "Main Testing",
"output": "1231 tests executed.\n32 tests executed.",
"status": 0
},
{
"groups": [
{
"name": "Lint",
"output": "No linting errors found."
}
],
"name": "Main Lint",
"output": "No linting errors found.",
"status": 0
}
]);
});

test("interleaved groups", async () => {
const output = fs.readFileSync(path.join(resources, "act-groups-interleaved.log")).toString();
const parser = new OutputParser(output);

const result = parser.parseOutput();

expect(result).toStrictEqual([
{
"groups": [
{
"name": "Unit Tests",
"output": "1231 tests executed."
},
{
"name": "Integration Tests",
"output": "32 tests executed."
}
],
"name": "Main Testing",
"output": "1231 tests executed.\n32 tests executed.",
"status": 0
},
{
"groups": [
{
"name": "Lint",
"output": "No linting errors found."
}
],
"name": "Main Lint",
"output": "No linting errors found.",
"status": 0
}
]);
});

test("mixed groups", async () => {
const output = fs.readFileSync(path.join(resources, "act-groups-mixed.log")).toString();
const parser = new OutputParser(output);

const result = parser.parseOutput();

expect(result).toStrictEqual([
{
"groups": [
{
"name": "Unit Tests",
"output": "1231 tests executed."
},
{
"name": "Integration Tests",
"output": "32 tests executed."
}
],
"name": "Main Testing",
"output": "1231 tests executed.\n32 tests executed.",
"status": 0
},
{
"name": "Main Lint",
"output": "No problems found.",
"status": 0
}
]);
});
});
});
13 changes: 13 additions & 0 deletions test/unit/resources/output-parser/act-groups-interleaved.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[Build/Tests ] ⭐ Run Main Testing
[Build/Tests ] ❓ ::group::Unit Tests
[Build/Tests ] | 1231 tests executed.
[Build/Static Analysis ] ⭐ Run Main Lint
[Build/Static Analysis ] ❓ ::group::Lint
[Build/Tests ] ❓ ::endgroup::
[Build/Static Analysis ] | No linting errors found.
[Build/Tests ] ❓ ::group::Integration Tests
[Build/Tests ] | 32 tests executed.
[Build/Tests ] ❓ ::endgroup::
[Build/Tests ] ✅ Success - Main Testing
[Build/Static Analysis ] ❓ ::endgroup::
[Build/Static Analysis ] ✅ Success - Main Lint
11 changes: 11 additions & 0 deletions test/unit/resources/output-parser/act-groups-mixed.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[Build/Tests ] ⭐ Run Main Testing
[Build/Tests ] ❓ ::group::Unit Tests
[Build/Static Analysis ] ⭐ Run Main Lint
[Build/Static Analysis ] | No problems found.
[Build/Tests ] | 1231 tests executed.
[Build/Tests ] ❓ ::endgroup::
[Build/Tests ] ❓ ::group::Integration Tests
[Build/Tests ] | 32 tests executed.
[Build/Tests ] ❓ ::endgroup::
[Build/Static Analysis ] ✅ Success - Main Lint
[Build/Tests ] ✅ Success - Main Testing
13 changes: 13 additions & 0 deletions test/unit/resources/output-parser/act-groups-sorted.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[Build/Tests ] ⭐ Run Main Testing
[Build/Tests ] ❓ ::group::Unit Tests
[Build/Tests ] | 1231 tests executed.
[Build/Tests ] ❓ ::endgroup::
[Build/Tests ] ❓ ::group::Integration Tests
[Build/Tests ] | 32 tests executed.
[Build/Tests ] ❓ ::endgroup::
[Build/Tests ] ✅ Success - Main Testing
[Build/Static Analysis ] ⭐ Run Main Lint
[Build/Static Analysis ] ❓ ::group::Lint
[Build/Static Analysis ] | No linting errors found.
[Build/Static Analysis ] ❓ ::endgroup::
[Build/Static Analysis ] ✅ Success - Main Lint