Create Pull Request from Fork #6
Workflow file for this run
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: "Create Pull Request from Fork" | |
| on: | |
| repository_dispatch: | |
| types: [sync-from-fork] | |
| workflow_dispatch: | |
| jobs: | |
| create-pr: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout main repository | |
| uses: actions/checkout@v4 | |
| with: | |
| path: my-repo | |
| fetch-depth: 0 | |
| - name: Checkout friend's fork | |
| uses: actions/checkout@v4 | |
| with: | |
| repository: electrolysis743/tuweb | |
| ref: main | |
| path: friend-repo | |
| fetch-depth: 0 | |
| - name: Prepare branch name and check existence | |
| id: prep | |
| run: | | |
| cd my-repo | |
| BRANCH_NAME="auto-sync-$(date +%Y%m%d-%H%M%S)-$RANDOM" | |
| echo "branch=$BRANCH_NAME" >> $GITHUB_OUTPUT | |
| git fetch origin | |
| if git rev-parse --quiet --verify "origin/$BRANCH_NAME" >/dev/null; then | |
| echo "skip=true" >> $GITHUB_OUTPUT | |
| else | |
| echo "skip=false" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Create sync branch and merge friend's changes | |
| if: steps.prep.outputs.skip == 'false' | |
| run: | | |
| cd my-repo | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git checkout -b "${{ steps.prep.outputs.branch }}" | |
| git remote add friend ../friend-repo || true | |
| git fetch friend main | |
| if ! git merge friend/main --no-edit --allow-unrelated-histories; then | |
| echo "❌ 合并冲突,请手动处理" | |
| exit 1 | |
| fi | |
| git push origin "${{ steps.prep.outputs.branch }}" | |
| - name: Create Pull Request | |
| if: steps.prep.outputs.skip == 'false' | |
| run: | | |
| cd my-repo | |
| gh pr create \ | |
| --title "更新" \ | |
| --body "此 PR 由 GitHub Actions 自动创建。" \ | |
| --base main \ | |
| --head "${{ steps.prep.outputs.branch }}" \ | |
| --assignee "tiao2" \ | |
| --reviewer "tiao2" | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |