Skip to content

feat: add ready_to_merge.yml workflow #11

feat: add ready_to_merge.yml workflow

feat: add ready_to_merge.yml workflow #11

Workflow file for this run

name: Ready to Merge
on:
pull_request:
types: [opened, synchronize, reopened]
# branches:
# - main
workflow_dispatch:
jobs:
check_commit_status:
runs-on: ubuntu-latest
steps:
- name: Confirm Check Runs
uses: actions/github-script@v7
with:
script: |
workflows_to_check = (
"analyze",
"format",
"GitGuardian Security Checks",
"check_changes",
"test",
"MegaLinter",
"drive_web",
"pgtap"
);
console.log("Sleeping 10s to give other runs a chance to start");
await sleep(10000);
const { owner, repo } = context.repo;
const commit_sha = context.payload.pull_request.head.sha; // Get the SHA of the head commit of the PR
const maxRetries = 15; // Maximum number of retries
const excludedCheckRunName = "check_commit_status"; // important you don't define name key for the job
let retryCount = 0;
async function fetchCheckRuns() {
const response = await github.rest.checks.listForRef({
owner,
repo,
ref: commit_sha,
// check_name: workflows_to_check,
per_page: 100,
});
return response.data.check_runs;
}
async function sleep(ms) {
return new Promise((resolve) => setTimeout(resolve, ms));
}
let checkRuns = await fetchCheckRuns();
let inProgressFound = false;
let failureFound = false;
do {
inProgressFound = false;
failureFound = false;
for (const checkRun of checkRuns) {
console.log("Looking at check run: " + checkRun.name);
// Exclude this job from the evaluation
if (
checkRun.name === excludedCheckRunName ||
!workflows_to_check.includes(checkRun.name)
) {
console.log("Skipping check run: " + checkRun.name);
continue;
}
if (checkRun.status === "completed") {
workflows_to_check.remove(checkRun.name);
console.log("Check run completed: " + checkRun.name);
}
if (checkRun.status === "in_progress") {
inProgressFound = true;
console.log("Check run in progress: " + checkRun.name);
}
if (checkRun.conclusion === "failure") {
failureFound = true;
console.log("Check run failed: " + checkRun.name);
// We could break here, but we want to wait for all checks to complete
}
}
if (inProgressFound) {
if (retryCount >= maxRetries) {
core.setFailed(
"Maximum retries reached with check runs still in progress."
);
break;
}
console.log("Waiting for 1 minute before rechecking...");
await sleep(60000);
checkRuns = await fetchCheckRuns();
retryCount++;
}
} while (inProgressFound);
if (failureFound) {
core.setFailed("There are failed check runs.");
}