| name: Sync main into earlgrey-hwe |
| |
| on: |
| schedule: |
| # Runs every day at 15:00 UTC (8:00 AM PDT / 7:00 AM PST) |
| - cron: '0 15 * * *' |
| workflow_dispatch: # Allows you to trigger it manually from the Actions tab |
| |
| jobs: |
| create-pull-request: |
| runs-on: ubuntu-latest |
| steps: |
| - name: Generate GitHub App Token |
| id: generate-token |
| uses: actions/create-github-app-token@v3 |
| with: |
| app-id: ${{ secrets.SYNCHRONIZE_BOT_APP_ID }} |
| private-key: ${{ secrets.SYNCHRONIZE_BOT_PRIVATE_KEY }} |
| |
| - name: Checkout the main branch |
| uses: actions/checkout@v6 |
| with: |
| ref: main |
| fetch-depth: 0 # Fetches all history so branches can be compared |
| token: ${{ steps.generate-token.outputs.token }} |
| |
| - name: Create and push sync branch |
| run: | |
| git config --global user.name "synchronize-bot[bot]" |
| git config --global user.email "synchronize-bot[bot]@users.noreply.github.com" |
| |
| # Create and switch to the staging branch |
| git checkout -b sync/main-to-earlgrey-hwe |
| |
| # Push the sync branch to the repo. |
| git push origin sync/main-to-earlgrey-hwe --force |
| |
| - name: Create Pull Request |
| env: |
| GITHUB_TOKEN: ${{ steps.generate-token.outputs.token }} |
| run: | |
| PR_EXISTS=$(gh pr list --base earlgrey-hwe --head sync/main-to-earlgrey-hwe --state open --json number | jq '.[].number') |
| |
| if [ -z "$PR_EXISTS" ]; then |
| echo "No active PR found. Generating a new sync PR..." |
| gh pr create \ |
| --base earlgrey-hwe \ |
| --head sync/main-to-earlgrey-hwe \ |
| --title "chore: sync main into earlgrey-hwe" \ |
| --label "automated-pr,sync" \ |
| --reviewer "cfrantz,moidx" \ |
| --body $'Automated daily sync from `main` to `earlgrey-hwe`.\n\n⚠️ If conflicts exist, click the "Resolve conflicts" button below to fix them in your browser.' |
| else |
| echo "A Pull Request already exists (PR #$PR_EXISTS). Updates pushed to branch automatically." |
| fi |