Skip to content

Update Safe Minor Updates #12

Update Safe Minor Updates

Update Safe Minor Updates #12

Workflow file for this run

name: Automerge Renovate PRs

Check failure on line 1 in .github/workflows/automerge.yml

View workflow run for this annotation

GitHub Actions / .github/workflows/automerge.yml

Invalid workflow file

(Line: 4, Col: 12): Unexpected value ''
on:
schedule:
# Disable AutoRun for now: Runs at 12:00 PM Pacific Time on Wednesdays.
# - cron: '0 19 * * 3'
workflow_dispatch: # Allows manual triggering
permissions:
contents: read
pull-requests: write
jobs:
automerge:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Automerge PRs
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const owner = context.repo.owner;
const repo = context.repo.repo;
const now = new Date();
async function processPRs(label, daysToWait, mergeMethod = 'squash') {
console.log(`\n--- Processing PRs with label: ${label}, waiting ${daysToWait} days ---`);
const { data: prs } = await github.rest.pulls.list({
owner,
repo,
state: 'open',
per_page: 10,
});
let foundPrsWithLabel = 0;
for (const pr of prs) {
if (!pr.labels.find(l => l.name === label)) {
continue;
}
foundPrsWithLabel++;
console.log(`\nProcessing PR #${pr.number} ('${pr.title}')`);
const createdAt = new Date(pr.created_at);
const ageInMilliseconds = now - createdAt;
const requiredAgeInMilliseconds = daysToWait * 24 * 60 * 60 * 1000;
if (ageInMilliseconds < requiredAgeInMilliseconds) {
const ageHours = Math.floor(ageInMilliseconds / (1000 * 60 * 60));
const requiredHours = daysToWait * 24;
console.log(` PR #${pr.number} is too new. Age: ${ageHours} hours. Required: ${requiredHours} hours (${daysToWait} days).`);
continue;
}
console.log(` PR #${pr.number} is old enough.`);
// Check CI status using combined status for the PR's head commit
const { data: status } = await github.rest.repos.getCombinedStatusForRef({
owner,
repo,
ref: pr.head.sha,
});
if (status.state !== 'success') {
console.log(` PR #${pr.number} CI status is '${status.state}' (not 'success'). Skipping merge.`);
continue;
}
console.log(` PR #${pr.number} CI status is 'success'.`);
// Attempt to merge
try {
console.log(` Attempting to merge PR #${pr.number} with method '${mergeMethod}'...`);
await github.rest.pulls.merge({
owner,
repo,
pull_number: pr.number,
merge_method: mergeMethod,
});
console.log(` Successfully merged PR #${pr.number}.`);
} catch (error) {
console.error(` Failed to merge PR #${pr.number}: ${error.message}`);
if (error.response && error.response.data) {
console.error(` Error details: ${JSON.stringify(error.response.data, null, 2)}`);
}
}
}
if (foundPrsWithLabel === 0) {
console.log(`No open PRs found with label '${label}'.`);
}
}
console.log("Starting automerge workflow...");
await processPRs("automerge-patch-candidate", 7, 'squash'); // Patches wait 7 days
await processPRs("automerge-minor-candidate", 14, 'squash'); // Minors wait 14 days
console.log("Automerge workflow finished.");