Skip to content

[GR-21590] Update imports #70

[GR-21590] Update imports

[GR-21590] Update imports #70

Workflow file for this run

name: Post Merge Actions
on:
pull_request:
types: [closed]
jobs:
check-ci-and-notify:
runs-on: ubuntu-latest
steps:
- name: Wait for CI
id: wait-for-ci
uses: actions/github-script@v8
with:
script: |
const GRAALVMBOT_LOGIN = "graalvmbot";
const pr = context.payload.pull_request;
if (!pr || !pr.number || pr.state !== "closed") {
console.log("Not a closed pull request event.");
return;
}
const sender = context.payload.sender;
const assignees = pr.assignees || [];
if (!sender || sender.login !== GRAALVMBOT_LOGIN) {
console.log(`PR closed by ${sender.login}, not ${GRAALVMBOT_LOGIN}. Skipping CI check.`);
return;
}
if (assignees.length !== 1) {
console.log(`Expected exactly 1 assignee, found ${assignees.length}. Skipping CI check.`);
return;
}
const sha = pr.head.sha;
// Wait for CI workflow to complete
const maxWaitMs = 4* 60 * 60 * 1000;
const intervalMs = 15 * 60 * 1000;
const startMs = Date.now();
let runsResp = null;
while (Date.now() - startMs < maxWaitMs) {
console.log(`Waiting for workflow with SHA ${sha} to complete...`);
try {
runsResp = await github.rest.actions.listWorkflowRunsForRepo({
owner: context.repo.owner,
repo: context.repo.repo,
head_sha: sha,
});
} catch (err) {
console.log(`warning: failed to fetch workflow runs: ${err}`);
await new Promise(r => setTimeout(r, intervalMs));
continue;
}
const hasCompleted = runsResp.data.workflow_runs.some(run => run.head_sha === sha && run.status === "completed");
if (hasCompleted) break;
const hasInProgress = runsResp.data.workflow_runs.some(run => run.head_sha === sha && run.status !== "completed");
if (!hasInProgress && runsResp.data.workflow_runs.length === 0) {
await new Promise(r => setTimeout(r, intervalMs));
continue;
}
await new Promise(r => setTimeout(r, intervalMs));
}
if (!runsResp) {
console.log("No workflow runs found for this SHA.");
return;
}
const failedRun = runsResp.data.workflow_runs.find(run =>
run.head_sha === sha &&
run.status === "completed" &&
run.conclusion !== "success"
);
if (!failedRun) {
console.log("No failed CI workflow found for the PR.");
return;
}
core.setOutput('assignee', assignees[0] ? assignees[0].login : '');
core.setOutput('failed_run_url', failedRun.html_url);
core.setOutput('failed_run_id', failedRun.id);
console.log(`Found failed CI workflow: ${failedRun.html_url}`);
- name: Download merged test report
if: ${{ steps.wait-for-ci.outputs.failed_run_url != '' }}
uses: actions/download-artifact@v5
with:
name: merged_test_reports
path: report
github-token: ${{ secrets.GITHUB_TOKEN }}
run-id: ${{ steps.wait-for-ci.outputs.failed_run_id }}
continue-on-error: true
- name: Post failure comment
if: ${{ steps.wait-for-ci.outputs.failed_run_url != '' }}
uses: actions/github-script@v8
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const fs = require('fs');
const assignee = '${{ steps.wait-for-ci.outputs.assignee }}';
const runUrl = '${{ steps.wait-for-ci.outputs.failed_run_url }}';
let body = `@${assignee} - CI workflow failed: [View workflow](${runUrl})`;
try {
const reportPath = 'report/merged_test_reports.json';
if (fs.existsSync(reportPath)) {
const data = JSON.parse(fs.readFileSync(reportPath, 'utf8'));
const failed = data.map(t => t.name);
if (failed.length) {
const list = failed.map(n => `- ${n}`).join('\n');
body = `@${assignee} - CI workflow failed: [View workflow](${runUrl})\nFailed tests:\n\n${list}`;
}
}
} catch (e) {
console.log(`Error parsing test report: ${e}`);
}
const pr = context.payload.pull_request;
await github.rest.issues.createComment({
issue_number: pr.number,
owner: context.repo.owner,
repo: context.repo.repo,
body,
});