1- import { readdirSync , readFileSync } from "fs" ;
21import { App } from "octokit" ;
32
43if ( ! process . env . GITHUB_REF ?. startsWith ( "refs/pull/" ) ) {
@@ -15,10 +14,11 @@ function requireEnv(name: string): string {
1514const githubRepository = requireEnv ( "GITHUB_REPOSITORY" ) ;
1615const githubRef = requireEnv ( "GITHUB_REF" ) ;
1716
17+ const run_id = parseInt ( requireEnv ( "INPUT_RUN_ID" ) ) ;
18+
1819const [ owner , repo ] = githubRepository . split ( "/" ) ;
1920const pull_request_number = parseInt ( githubRef . split ( "/" ) [ 2 ] ) ;
2021
21- const artifact_regex = requireEnv ( "INPUT_ARTIFACT_REGEX" ) ;
2222const job_regex = requireEnv ( "INPUT_JOB_REGEX" ) ;
2323const step_regex = requireEnv ( "INPUT_STEP_REGEX" ) ;
2424
@@ -31,16 +31,6 @@ const octokit = await app.getInstallationOctokit(installation.id);
3131
3232let 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-
4434interface Row {
4535 url : string ;
4636 status : string ;
@@ -49,31 +39,32 @@ interface Row {
4939
5040const 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 = / w a r n i n g ( .\d + ) ? : / ;
7263 const errorRegex = / e r r o r ( .\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