[ci] Fetch all pages when evaluating jobs conclusions (#48315)

Use pagination to get all workflow jobs when evaluating the jobs conclusions
This commit is contained in:
Adrian Moldovan 2024-06-10 21:17:54 +03:00 committed by GitHub
parent b5992b3c9c
commit cd0884a294
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 26 additions and 11 deletions

View File

@ -16,23 +16,38 @@ const isJobRequired = ( job ) => {
};
const fetchJobs = async () => {
try {
const response = await fetch(
`https://api.github.com/repos/${ REPOSITORY }/actions/runs/${ RUN_ID }/jobs`,
{
let url = `https://api.github.com/repos/${ REPOSITORY }/actions/runs/${ RUN_ID }/jobs`;
const nextPattern = /(?<=<)([\S]*)(?=>; rel="Next")/i;
let pagesRemaining = true;
const jobs = [];
while ( pagesRemaining ) {
console.log( 'Fetching:', url );
try {
const response = await fetch( url, {
headers: {
'User-Agent': 'node.js',
Authorization: `Bearer ${ GITHUB_TOKEN }`,
},
} );
const data = await response.json();
jobs.push( ...data.jobs );
const linkHeader = response.headers.get( 'link' );
pagesRemaining =
linkHeader && linkHeader.includes( `rel=\"next\"` );
if ( pagesRemaining ) {
url = linkHeader.match( nextPattern )[ 0 ];
}
);
const data = await response.json();
return data.jobs;
} catch ( error ) {
console.error( 'Error:', error );
// We want to fail if there is an error getting the jobs conclusions
process.exit( 1 );
} catch ( error ) {
console.error( 'Error:', error );
// We want to fail if there is an error getting the jobs conclusions
process.exit( 1 );
}
}
return jobs;
};
const evaluateJobs = async () => {