Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dashboard/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ const REQUEST_TIMEOUT_MS = 17000
export interface ApiError extends Error {
detail?: unknown
}

export async function request<T>(path: string, options?: RequestInit, timeoutMs = REQUEST_TIMEOUT_MS): Promise<T> {
const controller = new AbortController()
const timeoutId = window.setTimeout(() => controller.abort(), timeoutMs)
Expand Down Expand Up @@ -1290,6 +1289,7 @@ export interface ReleaseTask {
checks_summary: string | null
can_create_pr: boolean
can_deploy_staging: boolean
can_deploy_production?: boolean; resolved_commit_sha?: string | null; staging_deployment_record_id?: number | null; environment_gate_summary?: string | null
blocked_reason: string | null
}
created_at: string | null
Expand Down
4 changes: 4 additions & 0 deletions dashboard/src/apiReleaseTasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,7 @@ export function getReleaseTasksPage(filters?: {
const q = params.toString() ? `?${params.toString()}` : ''
return request<ReleaseTaskPage>(`/releases/tasks/query${q}`)
}

export function deployReleaseTask(id: number, data?: { actor?: string; note?: string | null; confirm_phrase?: string | null }) {
return request<ReleaseTask>(`/releases/tasks/${id}/deploy`, { method: 'POST', body: JSON.stringify(data || {}) })
}
78 changes: 78 additions & 0 deletions dashboard/src/pages/ProductionDeployModal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import { ReleaseTask } from '../api'
import { FieldLabel, OverlayModal } from '../components/workbench'

export default function ProductionDeployModal({
task,
confirmPhrase,
busyAction,
onConfirmPhraseChange,
onClose,
onDeploy,
}: Readonly<{
task: ReleaseTask | null
confirmPhrase: string
busyAction: string | null
onConfirmPhraseChange: (value: string) => void
onClose: () => void
onDeploy: () => void
}>) {
const busyKey = task ? `release-task-${task.id}-deploy-production` : ''
return (
<OverlayModal
open={Boolean(task)}
eyebrow="Human Gate"
title="确认发布到 production"
description="生产发布会触发 GitHub Environment production 与 GCP WIF Cloud Run 工作流。不会自动 rollback。"
onClose={onClose}
>
{task ? (
<div className="space-y-5">
<div className="rounded-2xl border border-[color:var(--ops-state-blocked-border)] bg-[color:var(--ops-state-blocked-bg)] p-4 text-sm text-[color:var(--ops-state-blocked-text)]">
<div className="font-semibold">Production Human Gate</div>
<p className="mt-2">
请确认目标是 <span className="font-mono">synapse-network-prod</span>,分支为 <span className="font-mono">main</span>,
且同一 commit 已通过 staging。确认后仍需要 GitHub production environment reviewers 放行。
</p>
</div>
<div className="grid gap-3 md:grid-cols-2">
<InfoCard label="Project / Service" value={`${task.project_display_name || task.project_key} · ${task.service_key || '-'}`} />
<InfoCard label="GCP Project" value="synapse-network-prod" mono />
<InfoCard label="Main Commit" value={task.pr_gate?.resolved_commit_sha || '-'} mono />
<InfoCard label="Staging Evidence" value={`Deployment #${task.pr_gate?.staging_deployment_record_id || '-'}`} />
</div>
<label className="block space-y-2">
<FieldLabel>输入确认短语</FieldLabel>
<input
className="w-full rounded-2xl border border-[color:var(--ops-stroke-strong)] bg-[color:var(--ops-panel)] px-4 py-3 font-mono text-sm"
placeholder="DEPLOY_PRODUCTION"
value={confirmPhrase}
onChange={(event) => onConfirmPhraseChange(event.target.value)}
/>
</label>
<div className="flex justify-end gap-2">
<button type="button" className="rounded-xl border border-[color:var(--ops-stroke-strong)] px-4 py-2.5 text-sm" onClick={onClose}>
取消
</button>
<button
type="button"
className="rounded-xl border border-[color:var(--ops-state-blocked-border)] bg-[color:var(--ops-state-blocked-bg)] px-4 py-2.5 text-sm font-semibold text-[color:var(--ops-state-blocked-text)] disabled:opacity-50"
disabled={confirmPhrase !== 'DEPLOY_PRODUCTION' || Boolean(busyAction)}
onClick={onDeploy}
>
{busyAction === busyKey ? '发布中…' : '确认发布到 production'}
</button>
</div>
</div>
) : null}
</OverlayModal>
)
}

function InfoCard({ label, value, mono = false }: Readonly<{ label: string; value: string; mono?: boolean }>) {
return (
<div className="rounded-2xl border border-[color:var(--ops-stroke-soft)] bg-[color:var(--ops-panel-subtle)] p-4">
<div className="text-[10px] uppercase tracking-[0.18em] text-[color:var(--ops-text-caption)]">{label}</div>
<div className={`mt-2 text-sm ${mono ? 'font-mono' : 'font-semibold'}`}>{value}</div>
</div>
)
}
11 changes: 11 additions & 0 deletions dashboard/src/pages/ReleaseTaskDetailPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,17 @@ export function ReleaseTaskDetailModal({
export function ReleaseTaskPrGate({ task }: Readonly<{ task: ReleaseTask }>) {
const gate = task.pr_gate
if (!gate) return null
if (task.environment === 'production') {
const ready = Boolean(gate.can_deploy_production)
return (
<div className="mt-2 space-y-1">
<StateBadge tone={ready ? 'delivered' : 'blocked'}>Production Gate: {ready ? '已满足' : gate.blocked_reason || '待满足'}</StateBadge>
{gate.environment_gate_summary ? <div className="max-w-xs text-xs text-[color:var(--ops-text-caption)]">{gate.environment_gate_summary}</div> : null}
{gate.resolved_commit_sha ? <div className="max-w-xs font-mono text-xs text-[color:var(--ops-text-caption)]">main {gate.resolved_commit_sha.slice(0, 12)}</div> : null}
{gate.staging_deployment_record_id ? <div className="max-w-xs text-xs text-[color:var(--ops-text-caption)]">staging deployment #{gate.staging_deployment_record_id}</div> : null}
</div>
)
}
let label = gate.blocked_reason || 'PR gate 待同步'
let tone: 'ready' | 'running' | 'blocked' | 'muted' | 'delivered' = 'muted'
if (!gate.branch_exists) {
Expand Down
63 changes: 57 additions & 6 deletions dashboard/src/pages/ReleasesPage.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { useEffect, useMemo, useState } from 'react'
import { useNavigate, useSearchParams } from 'react-router-dom'
import { OnlineReleaseRecord, ProjectPolicy, ReleaseBranchOption, ReleaseCandidate, ReleaseTask, api } from '../api'
import { getReleaseTasksPage } from '../apiReleaseTasks'
import { deployReleaseTask, getReleaseTasksPage } from '../apiReleaseTasks'
import { EmptyPane, FieldLabel, OverlayModal, StateBadge, useToast } from '../components/workbench'
import { ReleaseTaskCompactFailure, ReleaseTaskDetailModal, ReleaseTaskFailureSnippet, ReleaseTaskPrGate, releaseTaskFailureSummary, shouldShowReleaseTaskFailure } from './ReleaseTaskDetailPanel'
import { STATUS_LABEL, releaseTone } from './releaseListUi'
import SdkPackagesPanel from './SdkPackagesPanel'
import ScheduledJobsPanel from './ScheduledJobsPanel'
import ProductionDeployModal from './ProductionDeployModal'

type ReleaseTab = 'candidates' | 'tasks' | 'scheduled-jobs' | 'sdk-packages' | 'online'
const RELEASE_TABS: ReleaseTab[] = ['candidates', 'tasks', 'scheduled-jobs', 'sdk-packages', 'online']
const RELEASE_TASK_PAGE_SIZE = 10

const SOURCE_LABEL: Record<string, string> = {
manual: '人工创建',
requirement_flow: '需求流转',
Expand Down Expand Up @@ -154,6 +154,8 @@ export default function ReleasesPage() {
const [onlineDetail, setOnlineDetail] = useState<OnlineReleaseRecord | null>(null)
const [taskDraft, setTaskDraft] = useState(defaultTaskDraft([]))
const [taskBusy, setTaskBusy] = useState(false)
const [productionDeployTask, setProductionDeployTask] = useState<ReleaseTask | null>(null)
const [productionConfirmPhrase, setProductionConfirmPhrase] = useState('')
const [branchOptions, setBranchOptions] = useState<ReleaseBranchOption[]>([])
const [branchQuery, setBranchQuery] = useState('')
const [branchLoading, setBranchLoading] = useState(false)
Expand Down Expand Up @@ -381,6 +383,28 @@ export default function ReleasesPage() {
}
}

const deployTaskToProduction = async () => {
if (!productionDeployTask || busyAction) return
const busyKey = `release-task-${productionDeployTask.id}-deploy-production`
setBusyAction(busyKey)
try {
await deployReleaseTask(productionDeployTask.id, {
actor: 'operator',
note: productionDeployTask.note,
confirm_phrase: productionConfirmPhrase,
})
toast.success('Production 发布已触发')
setProductionDeployTask(null)
setProductionConfirmPhrase('')
await load()
} catch (error) {
const message = error instanceof Error ? error.message : '触发 production 发布失败'
toast.error(message)
} finally {
setBusyAction(null)
}
}

const createTaskPr = async (task: ReleaseTask) => {
const busyKey = `release-task-${task.id}-create-pr`
if (busyAction) return
Expand Down Expand Up @@ -552,6 +576,10 @@ export default function ReleasesPage() {
onUpdateStatus={updateTaskStatus}
onCreatePr={createTaskPr}
onDeployStaging={deployTaskToStaging}
onDeployProduction={(task) => {
setProductionConfirmPhrase('')
setProductionDeployTask(task)
}}
onRefresh={() => load().catch(() => {})}
onOpenDetails={(task) => {
setTaskModalOpen(false)
Expand All @@ -571,6 +599,18 @@ export default function ReleasesPage() {
/>
)}

<ProductionDeployModal
task={productionDeployTask}
confirmPhrase={productionConfirmPhrase}
busyAction={busyAction}
onConfirmPhraseChange={setProductionConfirmPhrase}
onClose={() => {
setProductionDeployTask(null)
setProductionConfirmPhrase('')
}}
onDeploy={deployTaskToProduction}
/>

<OverlayModal
open={taskModalOpen}
eyebrow="Release Task"
Expand Down Expand Up @@ -827,6 +867,7 @@ function ReleaseTasksTable({
onUpdateStatus,
onCreatePr,
onDeployStaging,
onDeployProduction,
onRefresh,
onOpenDetails,
onPage,
Expand All @@ -840,6 +881,7 @@ function ReleaseTasksTable({
onUpdateStatus: (task: ReleaseTask, status: 'completed' | 'failed' | 'cancelled') => void
onCreatePr: (task: ReleaseTask) => void
onDeployStaging: (task: ReleaseTask) => void
onDeployProduction: (task: ReleaseTask) => void
onRefresh: () => void
onOpenDetails: (task: ReleaseTask) => void
onPage: (offset: number) => void
Expand Down Expand Up @@ -892,7 +934,7 @@ function ReleaseTasksTable({
<ReleaseTaskCompactFailure value={task.deployment_failure_summary} />
) : null}
<ReleaseTaskFailureSnippet task={task} />
{task.environment === 'staging' ? <ReleaseTaskPrGate task={task} /> : null}
{task.environment === 'staging' || task.environment === 'production' ? <ReleaseTaskPrGate task={task} /> : null}
</td>
<td className="px-4 py-4 text-sm text-[color:var(--ops-text-muted)]">
<div>创建:{task.actor || '-'}</div>
Expand Down Expand Up @@ -967,9 +1009,18 @@ function ReleaseTasksTable({
发布到 staging
</button>
) : null}
{task.environment === 'production' ? (
<span className="rounded-lg border border-[color:var(--ops-state-blocked-border)] px-3 py-2 text-sm text-[color:var(--ops-state-blocked-text)]">
Production 需 Human Gate
{task.environment === 'production' && task.pr_gate?.can_deploy_production && !task.deployment_record_id ? (
<button
type="button"
className="rounded-lg border border-[color:var(--ops-state-blocked-border)] bg-[color:var(--ops-state-blocked-bg)] px-3 py-2 text-sm font-semibold text-[color:var(--ops-state-blocked-text)] disabled:opacity-50"
disabled={Boolean(busyAction)}
onClick={() => onDeployProduction(task)}
>
{busyAction === `release-task-${task.id}-deploy-production` ? '发布中…' : '发布到 production'}
</button>
) : task.environment === 'production' ? (
<span className="rounded-lg border border-[color:var(--ops-state-blocked-border)] px-3 py-2 text-sm text-[color:var(--ops-state-blocked-text)]" title={task.pr_gate?.blocked_reason || undefined}>
{task.pr_gate?.blocked_reason || 'Production 需 Human Gate'}
</span>
) : null}
<button
Expand Down
6 changes: 3 additions & 3 deletions docs/design-docs/current-feature-inventory.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,11 @@
5. PR / release 只信任 workflow evidence、verification verdict 和 human gate decision。
6. Drop Goal 不会自动 rollback;下线已发布功能必须创建 decommission requirement。
7. `release_pr_status_sweep` 会只读同步 GitHub PR 状态:merged PR 更新为 `merged`,closed / missing PR 收敛为 `pr_closed / abandoned`,但不会自动 deploy 或 rollback。
8. `/releases` 的 `发布管理` 分面使用独立 Release Task 记录手动和需求流转发布意图;Release Task 不等于 Deployment Record。任务创建不会自动部署,分支选择从目标 GitHub 仓库 branch list 读取;`main` 分支可由 Operator 直接点击 `发布到 staging`,其它分支没有 open/merged PR 时只能提交 PR,PR checks 通过后才允许触发白名单发布 runner,production 仍必须 Human Gate。当前一等发布目标包含 `Synapse-Network` 的 gateway / gateway-admin / admin-front / user-front / docs-front,以及 `Synapse-Network-Provider` 的 provider-service。`Synapse-Network` staging dispatch 按 runtime family 选择 workflow:gateway -> `deploy-staging-gateway.yml`,gateway-admin/admin-front -> `deploy-staging-admin.yml`,user-front/docs-front -> `deploy-staging-frontends.yml`;目标仓库的 `deploy-staging.yml` 只作为 reusable core / compatibility runner。
8. `/releases` 的 `发布管理` 分面使用独立 Release Task 记录手动和需求流转发布意图;Release Task 不等于 Deployment Record。任务创建不会自动部署,分支选择从目标 GitHub 仓库 branch list 读取;`main` 分支可由 Operator 直接点击 `发布到 staging`,其它分支没有 open/merged PR 时只能提交 PR,PR checks 通过后才允许触发白名单发布 runner。Production 发布已接入 Human-Gated Release Task:只允许 `main`,必须同一 project / service / commit 已有 staging success,并要求 operator 输入 `DEPLOY_PRODUCTION` 后 dispatch `deploy-production.yml`。当前一等发布目标包含 `Synapse-Network` 的 gateway / gateway-admin / admin-front / user-front / docs-front,以及 `Synapse-Network-Provider` 的 provider-service。`Synapse-Network` staging dispatch 按 runtime family 选择 workflow:gateway -> `deploy-staging-gateway.yml`,gateway-admin/admin-front -> `deploy-staging-admin.yml`,user-front/docs-front -> `deploy-staging-frontends.yml`;目标仓库的 `deploy-staging.yml` 只作为 reusable core / compatibility runner。Production dispatch 使用目标仓库 `deploy-production.yml`,通过 GCP WIF 部署到 `synapse-network-prod`。
9. Release Task detail modal 展示 PR gate、DeploymentRecord、GitHub Actions run link、health check、failure summary 和 deployment metadata;Synapse-Network 与 Synapse-Network-Provider staging runner 都使用 GCP Workload Identity Federation + Cloud Build + Cloud Run,不使用长生命周期 GCP service account JSON key 或 SSH deploy secrets;Provider DeploymentRecord 标记 `deploy_strategy=github_actions_wif_cloudrun`。
10. `/releases` 的 `上线记录` 分面只读展示成功的 `DeploymentRecord(status=succeeded)`,不混入 pending / failed / cancelled Release Task。手动标记 Release Task 已完成时,后端会创建或绑定一条 `manual_completion` 成功 DeploymentRecord 后再进入上线记录。上线记录用于确认 GitHub Actions、Cloud Run revision / image / manifest、health check 和 rollback target。
10. `/releases` 的 `上线记录` 分面只读展示成功的 `DeploymentRecord(status=succeeded)`,不混入 pending / failed / cancelled Release Task。手动标记 Release Task 已完成时,后端会创建或绑定一条 `manual_completion` 成功 DeploymentRecord 后再进入上线记录。上线记录用于确认 GitHub Actions、Cloud Run revision / image / manifest、health check 和 rollback target,并可按 `staging` / `production` 过滤。
11. 没有 webhook callback 的本地发起 staging 部署,由全局 `release_deployment_status_sweep` 定时拉取 GitHub Actions run 结果,也可通过 `/releases` 的 `同步状态` 人工触发同一幂等同步函数;同步只处理未终态 DeploymentRecord,只读吸收外部事实,不触发 deploy / merge / rollback。点击 `发布到 staging` 后 Release Task 进入 `deploying / 自动检查中`,健康检查事实由 GitHub Actions runner 内的 Cloud Run smoke check 负责,Ops Console 只同步 Actions success/failure 和 smoke metadata。人工 completed / failed / cancelled 终态优先,不会被后台同步回滚。
12. Staging 发布分两类:`main` 分支可直接由 Operator 点击 `发布到 staging`;非 main 分支不要求先合并 `main`,但必须存在 PR 且 PR checks 通过。Production 默认只允许从 `main` / tag / verified staging manifest 推进,并必须 Human Gate。
12. Staging 发布分两类:`main` 分支可直接由 Operator 点击 `发布到 staging`;非 main 分支不要求先合并 `main`,但必须存在 PR 且 PR checks 通过。Production v1 只允许从 `main` 的 verified staging commit 推进,并必须经过 Growing Human Gate 与 GitHub Environment `production` 双门禁。
13. Rollback 不由 Drop Goal、普通 Release Task PATCH 或 staging 快捷按钮触发。Runtime rollback 以历史成功上线记录的 commit / image / manifest 为 target 并进入 Human Gate;代码级 revert 必须走新分支、PR、checks、merge 和正常发布链路。
14. `/releases` 的 `定时任务发布` 分面管理 Synapse-Network 部署在 Google 上的 Cloud Run Jobs:gateway 周期任务 `deposit-indexer`、`provider-withdraw-reaper`、`consumer-withdraw-processor`、`notification-outbox-drain`、`in-app-cleanup`,以及 gateway / gateway-admin migration jobs。Operator 先通过 `创建定时任务发布` 选择 staging 环境、GitHub 分支和具体 job 名称,系统只创建 `scheduled_job_release_tasks(status=requested)`,不会 dispatch;只有在列表中点击 `发布到 staging` 才创建 `DeploymentRecord(trigger_source=scheduled_job_release)` 并 dispatch `deploy-staging-jobs.yml`。
15. 定时任务发布状态以 `scheduled_job_release_tasks` 为 UI source of truth;物理执行结果来自关联 DeploymentRecord、GitHub Actions callback / sync 和 `jobsManifest`。全局 `release_deployment_status_sweep` 与手动 `同步状态` 都会同步普通 Release Task 和定时任务发布任务。Google 写操作、单 job image 更新、可选 smoke / migration execution 全部在 GitHub Actions + WIF 中完成,本机 API 不调用 `gcloud`。Scheduler freshness 是健康信号,不等同发布失败;migration jobs 是发布时手动/受控执行任务,不做 freshness 警报。
Expand Down
Loading
Loading