From 80c2d36fd287044fd8343ecc7b9d71b2ddd8a3a7 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 25 Nov 2026 19:34:46 +0800 Subject: [PATCH] ci: run the full release checks once, automatically after each staging deploy (BUG-2390) Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01DbBXoyn7Hj3LCW3BUs5bZ8 --- .gitea/workflows/deploy-staging.yml | 21 ++++++++++ .gitea/workflows/release-quality-gate.yml | 41 ++++++++++++++++++- deploy/README.md | 2 +- deploy/resolve-release-revision.sh | 5 ++- docs/BUG_HISTORY.md | 11 +++++ .../tests/staging-backend-workflows.test.ts | 14 ++++++- 6 files changed, 88 insertions(+), 6 deletions(-) diff --git a/.gitea/workflows/deploy-staging.yml b/.gitea/workflows/deploy-staging.yml index bb9421594..8c1b576c6 100644 --- a/.gitea/workflows/deploy-staging.yml +++ b/.gitea/workflows/deploy-staging.yml @@ -390,3 +390,24 @@ jobs: printf '%s' "$REGISTRY_PASSWORD" | ssh "${ssh_options[@]}" "$remote" "sudo -n docker --config '$incoming/.docker' login '$REGISTRY_HOST' --username '$REGISTRY_USERNAME' --password-stdin" ssh "${ssh_options[@]}" "$remote" "sudo -n env INCOMING_PATH='$incoming' DEPLOY_PATH='$DEPLOY_PATH' API_IMAGE='$API_IMAGE' WEB_IMAGE='$WEB_IMAGE' DEPLOY_SHA='$DEPLOY_SHA' EXPECTED_PREVIOUS_SHA='$previous_sha' ALLOW_ROLLBACK='$ALLOW_ROLLBACK' FORWARD_REVISION_VERIFIED='$forward_verified' DOCKER_CONFIG='$incoming/.docker' DOCKER_BIN='docker' STAGING_URL='$STAGING_URL' bash '$incoming/deploy/run-staging-deploy.sh'" require_current_staging_head + + # BUG-2390 (owner 2026-11-25): queue the full release checks for exactly this SHA now, + # so the production release does not rerun them later. Staging itself never waits on + # it or fails because of it; a newer staging deploy cancels an older queued run. + - name: Queue the full release checks for this SHA + if: steps.revision.outputs.allow_rollback != 'true' + env: + DEPLOY_SHA: ${{ steps.revision.outputs.sha }} + run: | + set -uo pipefail + payload='{"ref":"refs/heads/staging"}' + if curl --fail --silent --show-error --connect-timeout 15 --max-time 60 --retry 3 --retry-all-errors \ + --request POST \ + --header "Authorization: token $GITEA_TOKEN" \ + --header "Content-Type: application/json" \ + --data "$payload" \ + "$GITEA_API_URL/repos/$GITEA_REPOSITORY/actions/workflows/release-quality-gate.yml/dispatches" >/dev/null; then + echo "queued the full release checks for $DEPLOY_SHA" + else + echo "::warning::could not queue the full release checks for $DEPLOY_SHA; dispatch Jyotish Release Quality Gate from main before releasing" + fi diff --git a/.gitea/workflows/release-quality-gate.yml b/.gitea/workflows/release-quality-gate.yml index 30b32b965..465e788e1 100644 --- a/.gitea/workflows/release-quality-gate.yml +++ b/.gitea/workflows/release-quality-gate.yml @@ -1,8 +1,18 @@ -name: Jyotish Release Quality Gate (manual only) +name: Jyotish Release Quality Gate (after staging deploy, or manual) +# BUG-2390 (owner 2026-11-25): the full release checks run once per SHA. Deploy staging +# dispatches this workflow on refs/heads/staging right after a successful deploy, so the +# result already exists when the owner approves the release; production workflows accept +# that run for the exact SHA. A manual dispatch from main stays as the fallback (for +# example when a newer staging push cancelled the automatic run). on: workflow_dispatch: +# A newer staging deploy supersedes an older automatic run; manual runs from main use their own group. +concurrency: + group: release-quality-${{ gitea.ref }} + cancel-in-progress: true + jobs: release-quality-gate: runs-on: xiaoxin @@ -21,20 +31,47 @@ jobs: git remote add origin https://git.copse.top/root/Jyotisha.git git fetch --no-tags origin "$GITEA_SHA" git checkout --detach --force "$GITEA_SHA" - - name: Record whether main is docs-only ahead of the last staging gate + - name: Record which revision this run attests env: GITEA_API_URL: ${{ gitea.api_url }} GITEA_REPOSITORY: ${{ gitea.repository }} GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }} + GITEA_REF: ${{ gitea.ref }} RESOLVE_MODE: discover run: | set -euo pipefail + if [[ "$GITEA_REF" == refs/heads/staging ]]; then + # BUG-2390: automatic run after a staging deploy. It attests exactly the SHA that + # passed the staging gate and is the current staging head; a superseded SHA stops here. + api() { + curl --fail --silent --show-error --connect-timeout 15 --max-time 60 --retry 3 --retry-all-errors \ + --header "Authorization: token $GITEA_TOKEN" "$GITEA_API_URL/repos/$GITEA_REPOSITORY/$1" + } + staging_head="$(api git/refs/heads/staging | jq -er 'select(type == "array" and length == 1) | .[0] | + select(.ref == "refs/heads/staging") | .object.sha | select(test("^[0-9a-f]{40}$"))')" + if [[ "$staging_head" != "$GITEA_SHA" ]] && ! bash deploy/is-docs-only-range.sh --api "$GITEA_SHA" "$staging_head"; then + echo "staging moved on to $staging_head; this automatic release gate is superseded" >&2 + exit 1 + fi + api "actions/runs?head_sha=$GITEA_SHA&branch=staging&event=push&status=success&limit=100" | jq -e --arg sha "$GITEA_SHA" ' + any(.workflow_runs[]?; + (.path | split("@")[0] | endswith("backend-quality-gate.yml")) and + .head_sha == $sha and .head_branch == "staging" and .event == "push" and .conclusion == "success") + ' >/dev/null || { echo "no successful staging quality gate for $GITEA_SHA" >&2; exit 1; } + { + echo "### Release revision" + echo "- trigger: automatic, after the staging deploy" + echo "- release_sha: ${GITEA_SHA}" + } >>"$GITHUB_STEP_SUMMARY" + exit 0 + fi bash deploy/resolve-release-revision.sh | tee "$RUNNER_TEMP/release-revision.env" release_sha="$(awk -F= '$1 == "release_sha" { print $2 }' "$RUNNER_TEMP/release-revision.env")" head_sha="$(awk -F= '$1 == "head_sha" { print $2 }' "$RUNNER_TEMP/release-revision.env")" [[ "$GITEA_SHA" == "$head_sha" ]] || { echo "dispatch the release gate from current main" >&2; exit 1; } { echo "### Release revision" + echo "- trigger: manual, from main" echo "- head_sha: ${head_sha}" echo "- release_sha: ${release_sha}" echo "- H relative to R is docs-only (is-docs-only-range.sh exited 0)" diff --git a/deploy/README.md b/deploy/README.md index 4b4ef8734..13031a1a0 100644 --- a/deploy/README.md +++ b/deploy/README.md @@ -144,7 +144,7 @@ It fails while `frontend/src/lib/legal-entity.ts` still holds placeholder operat ## Manual production deployment with Gitea Actions -GitHub production deployment is retired. Production changes are released only by manually dispatching `.gitea/workflows/deploy-production.yml`. `main` must be a fast-forward to the current staging head `H`. The deployed SHA is `R`, the latest successful staging push of `backend-quality-gate`, and `deploy/is-docs-only-range.sh R H` must exit 0 (exit 1 or 2 both refuse). Controller artifacts and image digests come from `R`. Public staging health must report `R`. The manual release gate may record `H` when `H` is docs-only ahead of `R`. Rollback still requires an explicit confirmation, a gate run, and ancestry inside reviewed `main` history. The workflow deploys immutable registry digests and never builds application images on the production host. +GitHub production deployment is retired. Production changes are released only by manually dispatching `.gitea/workflows/deploy-production.yml`. `main` must be a fast-forward to the current staging head `H`. The deployed SHA is `R`, the latest successful staging push of `backend-quality-gate`, and `deploy/is-docs-only-range.sh R H` must exit 0 (exit 1 or 2 both refuse). Controller artifacts and image digests come from `R`. Public staging health must report `R`. The full release gate (`release-quality-gate.yml`) must have succeeded for `R` or `H`. Since BUG-2390 (owner 2026-11-25) Deploy staging queues it automatically on `refs/heads/staging` after every successful staging deploy, so it normally exists before the owner approves a release and is not rerun from `main`; a newer staging deploy cancels an older queued run. If that run was cancelled or failed for an environment reason, dispatch the workflow manually from `main` (it may record `H` when `H` is docs-only ahead of `R`). Rollback still requires an explicit confirmation, a gate run, and ancestry inside reviewed `main` history. The workflow deploys immutable registry digests and never builds application images on the production host. The `internal` verification mode is for pre-DNS checks on the new host. The `public` mode is for the same SHA after authoritative DNS and Caddy TLS converge. Neither mode imports data, applies pending migrations, or changes DNS. diff --git a/deploy/resolve-release-revision.sh b/deploy/resolve-release-revision.sh index e915320bc..fdcf48dc1 100755 --- a/deploy/resolve-release-revision.sh +++ b/deploy/resolve-release-revision.sh @@ -7,7 +7,8 @@ # Discover mode (RESOLVE_MODE=discover): R is the newest such push whose range # to H is docs-only. # CHECK_RELEASE_GATE=true also requires a successful release-quality-gate -# dispatch whose head is R or H. +# dispatch whose head is R or H: the automatic run Deploy staging queues after +# each staging deploy, or a manual run from main (BUG-2390). # # stdout is three KEY=VALUE lines: release_sha, gate_run_id, head_sha. # Exit 0 accepted, 1 refused, 2 when the Gitea API cannot be read. @@ -191,7 +192,7 @@ PY fi done if [ "$found" != true ]; then - echo "no successful manual release quality gate found for the release SHA or current main" >&2 + echo "no successful full release quality gate found for the release SHA or current main (it runs after each staging deploy; dispatch it from main if that run was cancelled)" >&2 exit 1 fi } diff --git a/docs/BUG_HISTORY.md b/docs/BUG_HISTORY.md index 54e25616b..dfcc77cf0 100644 --- a/docs/BUG_HISTORY.md +++ b/docs/BUG_HISTORY.md @@ -32455,4 +32455,15 @@ - **防复发**:`test_yoga_instances_gana_2075` 参与星规则计数 32 → 36(原值/新值/原因已注);新测试锁住 Raja 成立与修正句、月亮落陷缓解不被排除、只有月亮自参照才算恒真、互换按两宫召回且同一互换只算一份、示意图标注。 - **未做(如实)**:其余约 140 条自定义规则仍没有 `participants_expr`,它们的图继续按句子推断并标「示意」;报告端(jyotisha-10)未读 `formation_note_zh`,需要报告窗口决定是否展示。 - **关联记录**:BUG-2387、BUG-2388、BUG-2353/2354(第九项,问答窗口)、BUG-2027、BUG-2301。 + +## BUG-2390 | 发布前在同一个 SHA 上把完整检查再跑一遍,正式发布多等约 25 分钟 + +- **状态**:resolved(分支 `claude/ci-speed-2390`,待推) +- **现象**:staging 每次推送只跑快速检查;正式发布前还要从 main 手动触发 Release Quality Gate,在同一个 SHA 上跑完整 release 档 + run_all(约 29 分钟,单台 runner),正式发布总共约 45 分钟。 +- **触发条件**:每一次正式发布。 +- **根因**:完整检查只能在批准发布之后、从 main 手动触发;而 staging 部署成功时那个 SHA 已经确定,可以提前跑。 +- **修复**:Deploy staging 成功(非回滚)后自动在 `refs/heads/staging` 上触发 `release-quality-gate.yml`,不阻塞 staging、触发失败只记 warning。发布检查的自动运行只认当前 staging 头(或纯文档前进)且该 SHA 的 staging 门禁已成功,否则以「superseded」退出;`concurrency: release-quality-${{ gitea.ref }}` + `cancel-in-progress` 让新的 staging 部署取消旧的排队运行。生产四个工作流沿用 `CHECK_RELEASE_GATE=true`:按 `head_sha` 找成功的 release-quality-gate 运行,自动运行与手动运行都算;从 main 手动触发保留为兜底。其余安全条件(main == staging、公网 staging 报同一 SHA、只用门禁产物里的镜像摘要)不变。 +- **验证**:staging-backend-workflows 合同测试按原值/新值/原因更新(本机 43 过,3 条因缺 yaml 模块 / rsync 失败,与改动前相同);所有工作流 YAML 用 venv 里的 PyYAML 解析通过;tests/test_resolve_release_revision.py、tests/test_beta_safety_net.py 通过。 +- **防复发**:合同测试钉住自动触发步骤、并发组、superseded 检查和 staging 门禁校验。 +- **关联记录**:BUG-2000、BUG-1998(发布检查内容)、AGENTS.md §0 第 6 条。 - **修复版本**:1.5(待发)。 diff --git a/frontend/tests/staging-backend-workflows.test.ts b/frontend/tests/staging-backend-workflows.test.ts index 79ae69ba5..055f6352f 100644 --- a/frontend/tests/staging-backend-workflows.test.ts +++ b/frontend/tests/staging-backend-workflows.test.ts @@ -1137,7 +1137,7 @@ test("manual migration uses only PostgreSQL and the digest-pinned migrator", () assert.doesNotMatch(runner, /\bup\b[^\n]*(?:api|web|caddy)/); }); -test("manual release gate runs where Docker Compose v2 is available", () => { +test("release gate (automatic after staging deploy, or manual) runs where Docker Compose v2 is available", () => { const workflow = read(giteaReleaseQualityWorkflow); assert.match(workflow, /^on:\n\s+workflow_dispatch:/m); @@ -1149,6 +1149,18 @@ test("manual release gate runs where Docker Compose v2 is available", () => { assert.match(workflow, /RESOLVE_MODE: discover/); assert.match(workflow, /bash deploy\/resolve-release-revision\.sh/); assert.match(workflow, /H relative to R is docs-only/); + // 原值: 只能从 main 手动触发,发布前在同一个 SHA 上再跑一遍完整检查(约 29 分钟) + // 新值: Deploy staging 成功后自动在 refs/heads/staging 上触发一次;自动运行只认当前 staging 头(或纯文档前进)且该 SHA 的 staging 门禁成功;新的 staging 部署取消旧的排队运行;从 main 手动触发仍可用作兜底 + // 原因: BUG-2390,产品负责人 2026-11-25:同一个 SHA 的完整检查只跑一次,发布不再多等约 25 分钟 + assert.match(workflow, /group: release-quality-\$\{\{ gitea\.ref \}\}\n\s+cancel-in-progress: true/); + assert.match(workflow, /GITEA_REF" == refs\/heads\/staging/); + assert.match(workflow, /this automatic release gate is superseded/); + assert.match(workflow, /bash deploy\/is-docs-only-range\.sh --api "\$GITEA_SHA" "\$staging_head"/); + assert.match(workflow, /endswith\("backend-quality-gate\.yml"\)\) and[\s\S]*?\.head_sha == \$sha and \.head_branch == "staging" and \.event == "push" and \.conclusion == "success"/); + const stagingDeploy = read(new URL("../../.gitea/workflows/deploy-staging.yml", import.meta.url)); + assert.match(stagingDeploy, /Queue the full release checks for this SHA[\s\S]*?if: steps\.revision\.outputs\.allow_rollback != 'true'[\s\S]*?actions\/workflows\/release-quality-gate\.yml\/dispatches/); + assert.match(stagingDeploy, /payload='\{"ref":"refs\/heads\/staging"\}'/); + assert.match(stagingDeploy, /::warning::could not queue the full release checks/); assert.match(workflow, /PIP_INDEX_URL: https:\/\/mirrors\.aliyun\.com\/pypi\/simple\//); assert.match(workflow, /NPM_CONFIG_REGISTRY: https:\/\/registry\.npmmirror\.com/); // 原值: 发布检查在前端安装之后跑 JYOTISHA_REQUIRE_LEGAL_ENTITY=1 的协议测试(#119 第 9 项)