[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:
parent
b5992b3c9c
commit
cd0884a294
|
@ -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 () => {
|
||||
|
|
Loading…
Reference in New Issue