Skip to content

Commit 6d6b0d0

Browse files
committed
THROW_EXECUTE_ERROR on CI
1 parent 03d3bd8 commit 6d6b0d0

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

src/constants.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,5 @@ export const GITHUB_ACTION_RUN_URL = IS_TRIGGERED_BY_GITHUB_ISSUE_COMMENT
2727
export const GITHUB_ACTION_JOB_URL = IS_TRIGGERED_BY_GITHUB_ISSUE_COMMENT
2828
? GITHUB_ACTION_RUN_URL
2929
: undefined;
30+
export const THROW_EXECUTE_ERROR =
31+
IS_CI && !IS_TRIGGERED_BY_GITHUB_ISSUE_COMMENT;

src/execute-command.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { installPrettier } from "./install-prettier.ts";
55
import { parseCommand } from "./parse-command.ts";
66
import { createTemporaryDirectory } from "./utilities.ts";
77
import { writeFile } from "./utilities.ts";
8-
import { reportsDirectory } from "./constants.ts";
8+
import { reportsDirectory, THROW_EXECUTE_ERROR } from "./constants.ts";
99
import path from "node:path";
1010

1111
export type ExecuteCommandResult = Awaited<ReturnType<typeof executeCommand>>;
@@ -43,9 +43,15 @@ export async function executeCommand(commandString: string) {
4343
}),
4444
);
4545

46-
const failedJobsCount = results.filter(
47-
(result) => result.status === "rejected",
48-
).length;
46+
const errors = results.filter((result) => result.status === "rejected");
47+
if (THROW_EXECUTE_ERROR) {
48+
throw new AggregateError(
49+
errors.map(({ reason }) => reason),
50+
"Command exclude failure.",
51+
);
52+
}
53+
54+
const failedJobsCount = errors.length;
4955
await logger.brief(
5056
`Job finished, succeed on ${results.length - failedJobsCount} repositories, fail on ${failedJobsCount} repositories.\n\nPreparing reports ...`,
5157
);

src/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as logger from "./logger.ts";
33
import { executeCommand } from "./execute-command.ts";
44
import { getIssueComment } from "./get-issue-comment.ts";
55
import { writeFile } from "./utilities.ts";
6-
import { reportsDirectory } from "./constants.ts";
6+
import { reportsDirectory, THROW_EXECUTE_ERROR } from "./constants.ts";
77
import path from "node:path";
88
import { reportOnGithubIssue } from "./report-on-github-issue.ts";
99
import { stringifyReport, getReport } from "./report.ts";
@@ -43,5 +43,9 @@ try {
4343
// eslint-disable-next-line @typescript-eslint/no-explicit-any
4444
error: any
4545
) {
46+
if (THROW_EXECUTE_ERROR) {
47+
throw error;
48+
}
49+
4650
await logger.error(error);
4751
}

0 commit comments

Comments
 (0)