Skip to content

Commit 8a5d027

Browse files
committed
Download jobLog
1 parent d84cac6 commit 8a5d027

File tree

5 files changed

+39
-69
lines changed

5 files changed

+39
-69
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ jobs:
5050
with:
5151
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5252
PRIVATE_KEY: ${{ secrets.PRIVATE_KEY }}
53-
ARTIFACT_REGEX: compilation_(?<runId>\d+)_(?<jobId>\d+)_log
53+
RUN_ID: ${{ github.run_id }}
5454
STEP_REGEX: build-.*
5555
JOB_REGEX: compile \((?<osName>.+?), (?<osVersion>.+?), (?<config>.+?), (?<cppVersion>.+?), (?<vendorName>.+?), (?<vendorVersion>.+?)\)
5656
ROW_HEADERS: '["osName","osVersion","vendorName","vendorVersion","config"]'

action.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ inputs:
1111
required: true
1212
STEP_REGEX:
1313
required: true
14-
ARTIFACT_REGEX:
15-
required: true
14+
RUN_ID:
15+
requird: true
1616
ROW_HEADERS:
1717
required: true
1818
COLUMN_HEADER:

dist/index.js

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

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.ts

Lines changed: 18 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { readdirSync, readFileSync } from "fs";
21
import { App } from "octokit";
32

43
if (!process.env.GITHUB_REF?.startsWith("refs/pull/")) {
@@ -15,10 +14,11 @@ function requireEnv(name: string): string {
1514
const githubRepository = requireEnv("GITHUB_REPOSITORY");
1615
const githubRef = requireEnv("GITHUB_REF");
1716

17+
const run_id = parseInt(requireEnv("INPUT_RUN_ID"));
18+
1819
const [owner, repo] = githubRepository.split("/");
1920
const pull_request_number = parseInt(githubRef.split("/")[2]);
2021

21-
const artifact_regex = requireEnv("INPUT_ARTIFACT_REGEX");
2222
const job_regex = requireEnv("INPUT_JOB_REGEX");
2323
const step_regex = requireEnv("INPUT_STEP_REGEX");
2424

@@ -31,16 +31,6 @@ const octokit = await app.getInstallationOctokit(installation.id);
3131

3232
let body: string | null = null;
3333

34-
const readdirRecursively = (dir: string): string[] => {
35-
const files: string[] = [];
36-
for (const dirent of readdirSync(dir, { withFileTypes: true })) {
37-
const path = `${dir}/${dirent.name}`;
38-
if (dirent.isDirectory()) files.push(...readdirRecursively(path));
39-
else if (dirent.isFile()) files.push(path);
40-
}
41-
return files;
42-
};
43-
4434
interface Row {
4535
url: string;
4636
status: string;
@@ -49,31 +39,32 @@ interface Row {
4939

5040
const rows: Row[] = [];
5141

52-
for (const file of readdirRecursively(".")) {
53-
console.log("looking", file, "deciding whether skip or not...");
54-
55-
const artifactMatch = file.match(artifact_regex);
42+
const { data: jobList } = await octokit.rest.actions.listJobsForWorkflowRun({
43+
owner,
44+
repo,
45+
run_id
46+
});
5647

57-
if (artifactMatch === null) {
58-
continue;
59-
}
48+
for (const job of jobList.jobs) {
6049

61-
if (!artifactMatch.groups?.runId || !artifactMatch.groups?.jobId) {
62-
console.log("artifact regex matched but missing runId/jobId named groups, skipping", file);
63-
continue;
64-
}
65-
const { runId, jobId } = artifactMatch.groups;
50+
const job_id = job.id;
6651

67-
console.log("found", file, "detecting warnings...");
52+
const { data: redirectUrl } = await octokit.rest.actions.downloadJobLogsForWorkflowRun({
53+
owner,
54+
repo,
55+
job_id,
56+
});
6857

69-
const compilationOutput = readFileSync(file).toString();
58+
const response = await fetch(redirectUrl as string);
59+
const result = await response.body?.getReader().read();
60+
const jobLog = result?.value as string;
7061

7162
const warningRegex = /warning( .\d+)?:/;
7263
const errorRegex = /error( .\d+)?:/;
7364

7465
let compileResult = "✅success";
7566
let firstIssueLine = 1;
76-
const lines = compilationOutput.split("\n");
67+
const lines = jobLog.split("\n");
7768
console.log(`total lines: ${lines.length}`);
7869
const warningIdx = lines.findIndex((line) => line.match(warningRegex));
7970
console.log(`warningIdx: ${warningIdx}`);
@@ -95,12 +86,6 @@ for (const file of readdirRecursively(".")) {
9586
firstIssueLine += GITHUB_ACTIONS_LOG_OFFSET;
9687
console.log(`compileResult: ${compileResult}, firstIssueLine: ${firstIssueLine} (includes offset ${GITHUB_ACTIONS_LOG_OFFSET})`);
9788

98-
const { data: job } = await octokit.rest.actions.getJobForWorkflowRun({
99-
owner,
100-
repo,
101-
job_id: parseInt(jobId),
102-
});
103-
10489
const steps = job.steps ?? [];
10590
const stepIndex = steps.findIndex(
10691
(step) =>

0 commit comments

Comments
 (0)