Skip to content

Report IB Build Failures #135

Report IB Build Failures

Report IB Build Failures #135

name: Report IB Build Failures
on:
schedule:
- cron: '0 0 * * *'
workflow_dispatch:
permissions:
issues: write
contents: read
actions: read
jobs:
report-failures:
runs-on: ubuntu-latest
steps:
- name: Get the last two runs of "Image Creation Run" workflow
id: get_runs
uses: actions/github-script@v7
with:
script: |
const workflowName = 'Image Creation Run';
const owner = context.repo.owner;
const repo = context.repo.repo;
// Get the workflows in the repo
const workflows = await github.rest.actions.listRepoWorkflows({
owner,
repo,
});
// Find the workflow ID for "Image Creation Run"
const workflow = workflows.data.workflows.find(
(wf) => wf.name === workflowName
);
if (!workflow) {
core.setFailed(`Workflow "${workflowName}" not found.`);
return;
}
const workflow_id = workflow.id;
// Get the last two workflow runs
const runsResponse = await github.rest.actions.listWorkflowRuns({
owner,
repo,
workflow_id,
per_page: 2,
});
const runs = runsResponse.data.workflow_runs;
if (runs.length < 2) {
core.setFailed('Not enough workflow runs found.');
return;
}
// Output the run IDs
core.setOutput('run_id1', runs[0].id.toString());
core.setOutput('run_id2', runs[1].id.toString());
- name: Get failed jobs from the last two runs with suffix "-ib"
id: get_failed_jobs
uses: actions/github-script@v7
env:
RUN_ID1: ${{ steps.get_runs.outputs.run_id1 }}
RUN_ID2: ${{ steps.get_runs.outputs.run_id2 }}
with:
script: |
const owner = context.repo.owner;
const repo = context.repo.repo;
// Function to get all jobs with pagination
async function getAllJobs(run_id) {
let jobs = [];
let page = 1;
let moreJobs = true;
while (moreJobs) {
const response = await github.rest.actions.listJobsForWorkflowRun({
owner,
repo,
run_id: run_id,
per_page: 100,
page: page,
});
if (response.data.jobs.length > 0) {
jobs = jobs.concat(response.data.jobs);
page++;
} else {
moreJobs = false;
}
}
return jobs;
}
// Function to get failed jobs ending with "-ib"
async function getFailedJobs(run_id) {
const jobs = await getAllJobs(run_id);
const failedJobs = jobs.filter((job) => {
return job.conclusion === 'failure' && job.name.endsWith('-ib');
});
return failedJobs.map((job) => job.name);
}
const run_id1 = process.env.RUN_ID1;
const run_id2 = process.env.RUN_ID2;
const failedJobs1 = await getFailedJobs(run_id1);
const failedJobs2 = await getFailedJobs(run_id2);
// Find jobs that failed in both runs
const failedInBoth = failedJobs1.filter((job) => failedJobs2.includes(job));
// Log the results for debugging
console.log(`Failed Jobs in Run 1: ${failedJobs1}`);
console.log(`Failed Jobs in Run 2: ${failedJobs2}`);
console.log(`Failed in Both Runs: ${failedInBoth}`);
core.setOutput('failed_jobs', failedInBoth.join(','));
- name: Report jobs failed in last two runs
if: steps.get_failed_jobs.outputs.failed_jobs != ''
run: |
echo "Images failed in both of the last two runs: ${{ steps.get_failed_jobs.outputs.failed_jobs }}"