check-pr-source.yml 1.2 KB

12345678910111213141516171819202122232425262728293031323334
  1. name: 检查main分支pr来源
  2. on:
  3. pull_request:
  4. branches:
  5. - main
  6. jobs:
  7. check_branch_and_repo:
  8. runs-on: ubuntu-latest
  9. steps:
  10. - name: 检查仓库来源 (阻止 Fork PR)
  11. if: github.event.pull_request.head.repo.full_name != github.repository
  12. run: |
  13. TARGET_REPO="${{ github.repository }}"
  14. SOURCE_REPO="${{ github.event.pull_request.head.repo.full_name }}"
  15. echo "::error file=check-pr-source.yml::[错误] main 分支只接受来自【本仓库】的合并请求。来源仓库 ($SOURCE_REPO) 与目标仓库 ($TARGET_REPO) 不一致。"
  16. exit 1
  17. - name: 检查来源分支名称
  18. if: github.head_ref != 'pending'
  19. run: |
  20. REQUIRED_BRANCH="pending"
  21. SOURCE_BRANCH="${{ github.head_ref }}"
  22. echo "::error file=check-pr-source.yml::[错误] main 分支只允许接受来自 '$REQUIRED_BRANCH' 分支的合并请求。当前来源分支为 '$SOURCE_BRANCH'。"
  23. exit 1 # 步骤失败,Job 失败,阻止 PR 合并
  24. # 3. 检查通过
  25. - name: ✅ 检查通过
  26. run: |
  27. REQUIRED_BRANCH="pending"
  28. echo "[通过] 检查成功:PR 满足合并条件。"