|
| 1 | +name: Daily sync main -> develop (07:00/15:00/23:00 New York) |
| 2 | + |
| 3 | +on: |
| 4 | + # Run every hour, then gate by New York local time. |
| 5 | + schedule: |
| 6 | + - cron: "0 * * * *" # UTC hourly |
| 7 | + workflow_dispatch: {} |
| 8 | + |
| 9 | +permissions: |
| 10 | + contents: write |
| 11 | + pull-requests: write |
| 12 | + |
| 13 | +concurrency: |
| 14 | + group: sync-main-to-develop |
| 15 | + cancel-in-progress: false |
| 16 | + |
| 17 | +jobs: |
| 18 | + sync: |
| 19 | + runs-on: ubuntu-latest |
| 20 | + steps: |
| 21 | + - name: Gate by New York time (only 07:00/15:00/23:00 ET) |
| 22 | + id: gate |
| 23 | + shell: bash |
| 24 | + run: | |
| 25 | + set -e |
| 26 | + python3 - <<'PY' |
| 27 | + from datetime import datetime |
| 28 | + from zoneinfo import ZoneInfo |
| 29 | + import os |
| 30 | + now = datetime.now(ZoneInfo("America/New_York")) |
| 31 | + ok = (now.minute == 0) and (now.hour in (7, 15, 23)) |
| 32 | + print(f"NY now: {now.isoformat()} -> will_run={ok}") |
| 33 | + with open(os.environ["GITHUB_OUTPUT"], "a") as f: |
| 34 | + f.write(f"ok={'true' if ok else 'false'}\n") |
| 35 | + PY |
| 36 | +
|
| 37 | + - name: Quit early if not target window |
| 38 | + if: steps.gate.outputs.ok != 'true' |
| 39 | + run: echo "Not at 07:00/15:00/23:00 New York time. Skipping." |
| 40 | + |
| 41 | + - name: Checkout develop |
| 42 | + if: steps.gate.outputs.ok == 'true' |
| 43 | + uses: actions/checkout@v4 |
| 44 | + with: |
| 45 | + ref: develop |
| 46 | + fetch-depth: 0 |
| 47 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 48 | + |
| 49 | + - name: Configure Git |
| 50 | + if: steps.gate.outputs.ok == 'true' |
| 51 | + run: | |
| 52 | + git config user.name "github-actions[bot]" |
| 53 | + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" |
| 54 | +
|
| 55 | + - name: Fetch & reset local to remote |
| 56 | + if: steps.gate.outputs.ok == 'true' |
| 57 | + run: | |
| 58 | + git fetch origin main develop |
| 59 | + git checkout develop |
| 60 | + git reset --hard origin/develop |
| 61 | +
|
| 62 | + - name: Merge main into develop |
| 63 | + if: steps.gate.outputs.ok == 'true' |
| 64 | + id: do_merge |
| 65 | + shell: bash |
| 66 | + run: | |
| 67 | + set -e |
| 68 | + if git merge -m "chore: scheduled sync main -> develop" origin/main; then |
| 69 | + echo "conflicted=false" >> $GITHUB_OUTPUT |
| 70 | + else |
| 71 | + echo "conflicted=true" >> $GITHUB_OUTPUT |
| 72 | + git merge --abort || true |
| 73 | + fi |
| 74 | +
|
| 75 | + - name: Push to develop (direct) |
| 76 | + if: steps.gate.outputs.ok == 'true' && steps.do_merge.outputs.conflicted == 'false' |
| 77 | + run: git push origin HEAD:develop |
| 78 | + |
| 79 | + - name: Open PR main -> develop (on conflict) |
| 80 | + if: steps.gate.outputs.ok == 'true' && steps.do_merge.outputs.conflicted == 'true' |
| 81 | + uses: repo-sync/pull-request@v2 |
| 82 | + with: |
| 83 | + source_branch: "main" |
| 84 | + destination_branch: "develop" |
| 85 | + pr_title: "Scheduled sync: main → develop (conflicts need resolution)" |
| 86 | + pr_body: "Automated sync hit merge conflicts. Please resolve to bring `develop` up to date with `main`." |
| 87 | + github_token: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments