Răsfoiți Sursa

【新增,CI】合并请求触发构建冒烟验证

docker-build.yml 增加 pull_request: branches:[master] 触发;build job 以 if: github.event_name != 'pull_request' 限定只在 push/dispatch 推送镜像,PR 仅跑 verify 作合并门禁。README 双语与 DESIGN.md 同步。

合并后需维护者在分支保护中把 verify 勾为必需检查,才能实际阻挡不合规合并。
xidongbot 2 luni în urmă
părinte
comite
34bf7356b2
4 a modificat fișierele cu 25 adăugiri și 9 ștergeri
  1. 21 7
      .github/workflows/docker-build.yml
  2. 2 2
      DESIGN.md
  3. 1 0
      README.md
  4. 1 0
      README.zh.md

+ 21 - 7
.github/workflows/docker-build.yml

@@ -1,12 +1,17 @@
-# 自动构建并推送 GHCR:push master 或手动/workflow_dispatch 触发
+# 自动构建并推送 GHCR:push master、pull_request 或手动/workflow_dispatch 触发
 # 镜像 tag:latest + 日期时间 - 提交哈希(如 20260815T0054-a1b2c3d)
+# PR 只跑 verify(构建 + 冒烟),不推送镜像:fork PR 的 GITHUB_TOKEN 无 GHCR 写权限,
+# 且未合并的代码不应发布。verify 作为合并门禁,挡住不合规提交(需配合分支保护的必需检查)。
 # workflow_dispatch 提供两种钩入方式:
 #   - 手动:Actions 页面点「Run workflow」或 gh workflow run docker-build.yml
 #   - 被钩:upstream-check 自动升级推送后显式触发——bot 用 GITHUB_TOKEN 推送的提交不会触发
 #           push 事件(GitHub 递归保护),而 workflow_dispatch 是 GITHUB_TOKEN 的例外,总是创建 run
 #
-# Auto-build and push to GHCR: triggered on push to master or manual/API dispatch
+# Auto-build and push to GHCR: triggered on push to master, pull_request, or manual/API dispatch
 # Image tags: latest + datetime-commit-hash (e.g. 20260815T0054-a1b2c3d)
+# PRs run verify only (build + smoke) and never push images: a fork PR's GITHUB_TOKEN cannot
+# write GHCR, and unmerged code must not be published. verify acts as a merge gate against
+# non-compliant submissions (pair it with branch protection's required checks).
 # workflow_dispatch offers two hook-in paths:
 #   - Manual: click "Run workflow" in the Actions tab or gh workflow run docker-build.yml
 #   - Hooked: upstream-check dispatches explicitly after an auto-upgrade push—commits pushed by
@@ -17,18 +22,21 @@ name: build-push-ghcr
 on:
   push:
     branches: [master]
+  pull_request:
+    branches: [master]
   workflow_dispatch:
 
 env:
   IMAGE: ghcr.io/xidong-ai/deepseek-harness-web-docker
 
 jobs:
-  # 推送前冒烟:构建镜像并跑端到端检查(basic auth / 特权 API fence / 双进程 / trustedHosts 注入),失败则不推送
-  # 手动 push 的代码不再未经验证直接发布
+  # 推送前冒烟:构建镜像并跑端到端检查(鉴权 token/cookie 或 basic auth / 特权 API fence / 双进程 / trustedHosts 注入),失败则不推送
+  # push 与 PR 共用同一套检查:push 失败阻断发布,PR 失败阻断合并(需分支保护勾选该检查为必需)
   #
-  # Pre-push smoke test: build the image and run end-to-end checks (basic auth / privileged-API fence /
-  # both processes / trustedHosts injection); a failure blocks the push, so manually pushed code
-  # is no longer published unverified
+  # Pre-push smoke test: build the image and run end-to-end checks (token/cookie or basic auth /
+  # privileged-API fence / both processes / trustedHosts injection); a failure blocks the push.
+  # push and PR share the same checks: a push failure blocks release, a PR failure blocks merge
+  # (requires the check to be marked required in branch protection)
   verify:
     runs-on: ubuntu-latest
     permissions:
@@ -47,6 +55,12 @@ jobs:
 
   build:
     needs: verify
+    # PR 只做验证,不发布镜像(fork PR 的 GITHUB_TOKEN 无 packages:write,且未合并代码不应发布);
+    # 仅 push master / 手动 dispatch 推送 GHCR
+    #
+    # PRs verify only and never publish images (a fork PR's GITHUB_TOKEN has no packages:write,
+    # and unmerged code must not be released); GHCR is pushed only on push to master / manual dispatch
+    if: github.event_name != 'pull_request'
     runs-on: ubuntu-latest
     permissions:
       contents: read

+ 2 - 2
DESIGN.md

@@ -72,7 +72,7 @@ DSH v0.1 无内置认证,且特权 API(`settings.*`/`credentials.*`,`PRIVI
 | 13 | 与现有部署关系 | 独立通用项目,推送给用户;本机测试用另一端口,不影响现有 pm2 部署 |
 | 14 | 分发 | 源码(Dockerfile + compose)+ CI 自动构建推 GHCR |
 | 15 | GHCR 路径 | `ghcr.io/xidong-ai/deepseek-harness-web-docker` |
-| 16 | CI 触发/tag | push master 触发;镜像 tag = 日期时间 + 提交哈希(另推 `latest` 便于 compose 默认引用) |
+| 16 | CI 触发/tag | push master、pull_request 触发;PR 仅跑 verify(不推镜像,作合并门禁);镜像 tag = 日期时间 + 提交哈希(另推 `latest` 便于 compose 默认引用) |
 
 ## 4. 文件清单
 
@@ -143,7 +143,7 @@ deepseek-harness-web-docker/
     config:
       trustedHosts: []
   ```
-- **.github/workflows/docker-build.yml**:`on: push: branches: [master]`;buildx(`linux/amd64`,可选 `linux/arm64` 多架构)→ tag `latest` + `${日期时间}-${sha7}`(如 `20260815T0054-a1b2c3d`)→ push `ghcr.io/xidong-ai/deepseek-harness-web-docker`(用 `GITHUB_TOKEN`,组织级包权限需在仓库设置开启)
+- **.github/workflows/docker-build.yml**:`on: push: branches: [master]` + `pull_request: branches: [master]`;push/PR 均先跑 `verify`(构建 + 冒烟),PR 仅此一步、不推镜像;push 通过后 buildx(`linux/amd64`,可选 `linux/arm64` 多架构)→ tag `latest` + `${日期时间}-${sha7}`(如 `20260815T0054-a1b2c3d`)→ push `ghcr.io/xidong-ai/deepseek-harness-web-docker`(用 `GITHUB_TOKEN`,组织级包权限需在仓库设置开启)
 
 ## 5. 环境变量参考(.env.example)
 

+ 1 - 0
README.md

@@ -15,6 +15,7 @@ Containerized deployment of the [DeepSeek Harness](https://github.com/deepseek-a
 - Built-in health check: `docker compose ps` shows the real service health (`starting`/`healthy`/`unhealthy`), exchanging the one-time token for a cookie and probing dsh
 - Pinnable image version: build argument `DSH_VERSION`
 - CI automatically builds and pushes `ghcr.io/xidong-ai/deepseek-harness-web-docker` (latest + date-time-hash tags)
+- Every pull request runs the same build + smoke test as a merge gate (PRs never push images); publishing happens only on push to master or manual dispatch
 - A scheduled CI job checks the dsh upstream daily: on a new version it bumps `DSH_VERSION`, builds and smoke-tests the image, pushes to master on success, or opens an Issue on failure (a failed version is not retried automatically while its Issue is open; manual dispatch bypasses the gate)
 - The GHCR release can be triggered manually (Actions tab → "Run workflow") or is hooked automatically after an upstream auto-upgrade (`workflow_dispatch`)
 

+ 1 - 0
README.zh.md

@@ -15,6 +15,7 @@
 - 内置健康检查:`docker compose ps` 直接可见服务真实健康状态(抓 dsh 一次性 token 换 cookie 后探测 dsh 响应,`starting`/`healthy`/`unhealthy`)
 - 镜像版本可 pin:构建参数 `DSH_VERSION`
 - CI 自动构建并推送 `ghcr.io/xidong-ai/deepseek-harness-web-docker`(latest + 日期时间 - 哈希 tag)
+- 每个合并请求都会运行与发布前相同的构建 + 冒烟测试作为合并门禁(PR 不推送镜像);仅 push master 或手动触发才发布
 - 定时任务每日检查 dsh 上游:有新版本自动提升 `DSH_VERSION`、构建并冒烟测试,通过则推送 master 并钩住触发 GHCR 发布,失败则创建 Issue(存在同版本未关闭 Issue 时不再自动重试,可手动触发强制重试)
 - GHCR 发布可手动触发(Actions 页「Run workflow」)或由上游升级自动钩住触发(`workflow_dispatch`)