Sync Upstream and Merge PRs #38
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Sync Upstream and Merge PRs | |
| on: | |
| schedule: | |
| - cron: '30 0 * * *' | |
| workflow_dispatch: | |
| jobs: | |
| sync-and-merge: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| steps: | |
| - name: Checkout your fork | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| # ⭐ مهم: تنظیم هویت گیت | |
| - name: Configure Git identity | |
| run: | | |
| git config --global user.name "PouyaFakhari" | |
| git config --global user.email "pouyafakhari@users.noreply.github.com" | |
| - name: Add upstream remote | |
| run: git remote add upstream https://github.com/xiaoY233/Chat2API.git | |
| - name: Fetch all upstream branches and PRs | |
| run: git fetch upstream | |
| - name: Merge upstream/main into your main branch | |
| run: | | |
| git checkout main | |
| git merge upstream/main --no-edit | |
| - name: Get list of open PRs from upstream | |
| run: | | |
| gh pr list --state open --repo xiaoY233/Chat2API --limit 100 --json number --jq '.[].number' > pr-list.txt | |
| cat pr-list.txt | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Merge each PR one by one | |
| run: | | |
| while read pr_number; do | |
| echo "Trying to merge PR #$pr_number" | |
| git fetch upstream pull/$pr_number/head:pr-$pr_number | |
| if git merge --no-ff pr-$pr_number -m "Merge PR #$pr_number from upstream"; then | |
| echo "✅ PR #$pr_number merged." | |
| else | |
| echo "❌ Conflict in PR #$pr_number. Skipping..." | |
| git merge --abort | |
| fi | |
| done < pr-list.txt | |
| - name: Push changes to your fork | |
| run: git push origin main |