|
| 1 | +name: Scheduled Merge |
| 2 | + |
| 3 | +# Enables scheduling a PR merge by adding `/schedule YYYY-MM-DD` to the PR body. |
| 4 | +# The PR must already be approved; this workflow only enables auto-merge, which |
| 5 | +# then goes through the normal merge queue like any other PR. |
| 6 | +# |
| 7 | +# Usage: add this line anywhere in the PR description: |
| 8 | +# /schedule 2026-05-15 |
| 9 | +# |
| 10 | +# Runs daily at 9–10am Eastern (10am EDT / 9am EST). Use workflow_dispatch to trigger immediately. |
| 11 | + |
| 12 | +on: |
| 13 | + schedule: |
| 14 | + - cron: '0 14 * * *' # 10am EDT / 9am EST |
| 15 | + workflow_dispatch: |
| 16 | + |
| 17 | +permissions: |
| 18 | + contents: write |
| 19 | + pull-requests: write |
| 20 | + |
| 21 | +jobs: |
| 22 | + merge-scheduled-prs: |
| 23 | + runs-on: ubuntu-latest |
| 24 | + steps: |
| 25 | + - name: Merge scheduled PRs |
| 26 | + env: |
| 27 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 28 | + REPO: ${{ github.repository }} |
| 29 | + run: | |
| 30 | + set -euo pipefail |
| 31 | + TODAY=$(TZ='America/New_York' date +%Y-%m-%d) |
| 32 | + echo "Today (Eastern): $TODAY" |
| 33 | +
|
| 34 | + pr_numbers=$( |
| 35 | + gh pr list --repo "$REPO" --state open --json number,body \ |
| 36 | + --jq '[.[] | select(.body | test("/schedule [0-9]{4}-[0-9]{2}-[0-9]{2}"))] | .[].number' |
| 37 | + ) |
| 38 | +
|
| 39 | + if [[ -z "$pr_numbers" ]]; then |
| 40 | + echo "No scheduled PRs found." |
| 41 | + exit 0 |
| 42 | + fi |
| 43 | +
|
| 44 | + for pr in $pr_numbers; do |
| 45 | + body=$(gh pr view "$pr" --repo "$REPO" --json body --jq '.body') |
| 46 | + scheduled=$(printf '%s' "$body" | grep -oP '(?<=/schedule )[0-9]{4}-[0-9]{2}-[0-9]{2}' | head -1) |
| 47 | +
|
| 48 | + [[ -z "$scheduled" ]] && continue |
| 49 | +
|
| 50 | + echo "PR #$pr is scheduled for $scheduled" |
| 51 | +
|
| 52 | + if [[ "$scheduled" > "$TODAY" ]]; then |
| 53 | + echo " Not yet due, skipping." |
| 54 | + continue |
| 55 | + fi |
| 56 | +
|
| 57 | + echo " Enabling auto-merge..." |
| 58 | + if gh pr merge "$pr" --repo "$REPO" --auto --squash; then |
| 59 | + echo " Done." |
| 60 | + gh pr comment "$pr" --repo "$REPO" \ |
| 61 | + --body "Scheduled merge for \`$scheduled\` — added to the merge queue." |
| 62 | + else |
| 63 | + echo " Warning: could not enable auto-merge." |
| 64 | + gh pr comment "$pr" --repo "$REPO" \ |
| 65 | + --body ":warning: Scheduled merge for \`$scheduled\` could not be enabled. Please check that the PR has the required approvals." |
| 66 | + fi |
| 67 | + done |
0 commit comments