Explorar el Código

ci: 添加检查ci文件

XingHeYuZhuan hace 1 mes
padre
commit
9bda2b9a1a
Se han modificado 2 ficheros con 47 adiciones y 0 borrados
  1. 13 0
      .github/PULL_REQUEST_TEMPLATE.md
  2. 34 0
      .github/workflows/check-pr-source.yml

+ 13 - 0
.github/PULL_REQUEST_TEMPLATE.md

@@ -0,0 +1,13 @@
+## 目标分支确认清单 (Target Branch Checklist)  
+
+### 本仓库已经开启main分支保护请不要提交pr到main  
+
+请在提交 PR 前,请完成以下表格:(方括号内填 "x" 以选中)
+* [x] 文件已经上传,到对应的学校资源文件
+* [ ] **确认目标分支是 `pending`。** (请勿直接合并到 `main` 或其他发布分支。)  
+
+
+## PR 描述 (Description)
+
+本次 PR 解决了什么问题?/ 引入了哪些新功能?(可以不填写)  
+[在此处填写详细描述]

+ 34 - 0
.github/workflows/check-pr-source.yml

@@ -0,0 +1,34 @@
+name: 检查main分支pr来源
+
+on:
+  pull_request:
+    branches:
+      - main 
+
+jobs:
+  check_branch_and_repo:
+    runs-on: ubuntu-latest
+    
+    steps:
+      - name: 检查仓库来源 (阻止 Fork PR)
+        if: github.event.pull_request.head.repo.full_name != github.repository
+        run: |
+          TARGET_REPO="${{ github.repository }}"
+          SOURCE_REPO="${{ github.event.pull_request.head.repo.full_name }}"
+          echo "::error file=check-pr-source.yml::[错误] main 分支只接受来自【本仓库】的合并请求。来源仓库 ($SOURCE_REPO) 与目标仓库 ($TARGET_REPO) 不一致。"
+          exit 1 
+
+      - name: 检查来源分支名称
+        if: github.head_ref != 'pending'
+        run: |
+          REQUIRED_BRANCH="pending"
+          SOURCE_BRANCH="${{ github.head_ref }}"
+
+          echo "::error file=check-pr-source.yml::[错误] main 分支只允许接受来自 '$REQUIRED_BRANCH' 分支的合并请求。当前来源分支为 '$SOURCE_BRANCH'。"
+          exit 1 # 步骤失败,Job 失败,阻止 PR 合并
+
+      # 3. 检查通过
+      - name: ✅ 检查通过
+        run: |
+          REQUIRED_BRANCH="pending"
+          echo "[通过] 检查成功:PR 满足合并条件。"