Skip to content
Open
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
7 changes: 7 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,13 @@ INBOUND_EMAIL_SECRET=
JOB_STALL_MINUTES=30
# Maximum jobs running at once across all repositories.
PLATFORM_MAX_ACTIVE_JOBS=2
# Superadmin one-click release: a repo-scoped token with Actions: write. Leave
# empty to disable the action; the token is read only on the server and is never
# rendered or logged.
RELEASE_DISPATCH_TOKEN=
RELEASE_DISPATCH_REPO=HugoXK/fledge
RELEASE_DISPATCH_WORKFLOW=daily-release.yml
RELEASE_DISPATCH_REF=main
# A linked work item below this review score cannot auto-merge. A manual
# maintainer merge can override; the override is audited.
AUTO_MERGE_MIN_REVIEW_SCORE=80
Expand Down
1 change: 1 addition & 0 deletions changelog.d/897-one-click-release.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
A superadmin can now create the next mechanical release pull request from the Admin page. The action shows the current main commit, the latest release tag, the commits/fixes/features/fragments since that tag, the computed next version, the `ci-ok` result and the reason it is blocked, then dispatches the existing `daily-release` workflow after a typed confirmation and a recent GitHub re-authentication. It creates no tag, merge or deploy by itself; the normal release PR, gates, auto-merge, tag and publish chain still run. The dispatch token is server-side, repo-scoped and never rendered or logged.
13 changes: 13 additions & 0 deletions docs/architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -823,6 +823,19 @@ path. The page owns the Users section at `/admin#users`; `/admin/users` is an
admin-only redirect to that section for older links and bookmarks, while
`/admin/users/:id` remains the read-only support view.

For a superadmin, the Release card also carries the one-click preview
(`src/lib/releaseDispatch.ts`): the current `main`, latest tag, commit/fix/
feature/fragment counts, computed next version, `ci-ok`, any open release PR and
the exact reason the action is blocked. `POST /admin/release` requires superadmin,
CSRF, a recent GitHub re-authentication, the destructive rate-limit class and an
audit row; it re-reads the preview and then dispatches the existing
`daily-release.yml` with `dry_run=false`. It never creates a tag, merges a pull
request or deploys a host. The server-side `RELEASE_DISPATCH_TOKEN` is repo-scoped
and never rendered or logged; an empty value disables the action instead of
failing the page. Release remains separate from deploy: production may already
run `main`, and the next infra update installs the version-bump commit after the
release PR merges.

The admin page is a hub, not an approvals-only page. Its primary sections are
Pending, Users, Jobs, Audit, Release and Backups; Product metrics, Webhook
deliveries, Deployments, Audit and jobs search and Preview trials are module
Expand Down
24 changes: 24 additions & 0 deletions docs/deploy.md
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,30 @@ status and how many reads were made, and a tip that never concludes ends the slo
with `none` and that run id in the reason. A dry run never waits: it reports what
a real run would have done.

#### Superadmin one-click release (#897)

The Admin page has a superadmin-only release action. It reads the live GitHub
state and shows the current `main`, latest tag, commits/fixes/features/fragments
since that tag, the computed next version, `ci-ok` and the exact reason a release
is blocked. The action is enabled only when the normal rule is met, no release
PR/branch/tag is in flight and `ci-ok` is green.

The submit button requires `RELEASE <version>` to be typed, a CSRF token, a
recent GitHub re-authentication, the destructive rate-limit class and an audit
row. It dispatches the existing `daily-release.yml` with `dry_run=false`; it
never creates a tag, merges a pull request or deploys a host. The existing
release PR, `ci-ok`, `review-gate`, auto-merge, tag job and `release.yml` publish
chain stay in charge.

The dispatch credential is `RELEASE_DISPATCH_TOKEN` in the server `.env`, scoped
to the Fledge repository with only `Actions: write`; prefer a fine-grained token.
An empty value disables the action instead of failing the Admin page. The token
is never rendered, logged or returned by the route.

A release is not a deploy. Production may already run `main` ahead of the latest
tag; the next infra `service-update-fledge.sh` run installs the version-bump
commit after the release PR merges. A separate operator action owns any restart.

#### Reliable slot trigger

GitHub's `schedule` event is best-effort: on 2026-11-14 the then-`14:30Z` slot
Expand Down
1 change: 1 addition & 0 deletions docs/secrets.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ predates this inventory — it is not a value.
| `GITHUB_APP_WEBHOOK_SECRET` | verifies App webhooks | production `.env` | random 32 bytes | owner | unknown | `openssl rand -hex 32` in both the App and `.env` | redeliver one webhook and confirm it is accepted | unknown |
| `INBOUND_EMAIL_SECRET` | shared secret with the inbound Email Worker | production `.env` and the worker | random 32 bytes | owner | unknown | `openssl rand -hex 32` in both places | reply to one digest mail and confirm it lands | unknown |
| `METRICS_TOKEN` | `/metrics` outside loopback | production `.env` | random 32 bytes | owner | unknown | `openssl rand -hex 32` then restart | `curl -H "Authorization: Bearer …" /metrics` returns 200 | unknown |
| `RELEASE_DISPATCH_TOKEN` | superadmin one-click release workflow dispatch | production `.env` | repo-scoped token with `Actions: write` on `HugoXK/fledge` only; fine-grained preferred, and no contents/PR write is needed | owner | unknown | mint a repo-scoped token, replace it in the server `.env`, restart Fledge | the release preview is `ready` and a `workflow_dispatch` run appears on `main` | unknown |
| `NOTIFY_WEBHOOK_SECRET` | outbound notification webhook | production `.env` | random 32 bytes | owner | unknown | `openssl rand -hex 32` in both places | one event delivers with a valid signature | unknown |

## What is deliberately not in this table
Expand Down
68 changes: 68 additions & 0 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ import { scanUntrusted, UNTRUSTED_EVENT_KIND } from './lib/firewall.js'
import { VERSION } from './version.js'
import { clearGauge, incCounter, observeHistogram, renderMetrics, setGauge } from './lib/metrics.js'
import { readReleaseStatus } from './lib/releaseStatus.js'
import { previewRelease, previewAndDispatch, type ReleaseDispatchPreview } from './lib/releaseDispatch.js'
import {
deploymentFromRow,
deploymentHealth,
Expand Down Expand Up @@ -5377,6 +5378,21 @@ export async function buildApp(options: BuildOptions): Promise<BuiltApp> {
const auditPages = Math.max(1, Math.ceil(auditTotal / perPage))
const jobsPage = Math.min(pageNumber('jobsPage'), jobsPages)
const auditPage = Math.min(pageNumber('auditPage'), auditPages)
let releaseDispatch: ReleaseDispatchPreview | null = null
let releaseDispatchError = ''
if (superadmin && config.release.dispatchToken !== '') {
try {
releaseDispatch = await previewRelease({
fetch: globalThis.fetch,
token: config.release.dispatchToken,
repo: config.release.repo,
workflow: config.release.workflow,
ref: config.release.ref,
})
} catch (error) {
releaseDispatchError = `GitHub preview failed: ${String(error instanceof Error ? error.message : error).slice(0, 200)}`
}
}
return reply.type('text/html').send(
adminPage({
config,
Expand All @@ -5402,10 +5418,62 @@ export async function buildApp(options: BuildOptions): Promise<BuiltApp> {
// Read from the data directory; a missing or unreadable snapshot renders
// as "not recorded" rather than failing the page.
releaseStatus: readReleaseStatus(config.dataDir),
releaseDispatch,
releaseDispatchError,
}),
)
})

// #897: the superadmin one-click release action. It dispatches the existing
// release workflow after a typed confirmation; it never tags, merges or
// deploys. The POST re-reads the live preview so a stale form cannot dispatch
// a release that is no longer eligible.
app.post('/admin/release', { config: { rateLimit: destructiveClassLimit } }, async (request, reply) => {
const t = translator(request.locale ?? 'zh')
const viewer = requireSuperAdmin(request)
if (viewer.preview === true) return reply.redirect('/console')
if (!sessions.verifyCsrf(request, viewer)) throw httpError(403, '表单已过期,请刷新页面后重试。', 'CSRF_FAILED')
if (requireRecentAuth(request, reply, viewer, 'admin.release')) return reply
if (config.release.dispatchToken === '') {
return reply.redirect('/admin?error=' + encodeURIComponent(t('一键发布未配置 RELEASE_DISPATCH_TOKEN。', 'One-click release is not configured: set RELEASE_DISPATCH_TOKEN.')))
}
let preview: ReleaseDispatchPreview
try {
preview = await previewRelease({
fetch: globalThis.fetch,
token: config.release.dispatchToken,
repo: config.release.repo,
workflow: config.release.workflow,
ref: config.release.ref,
})
} catch (error) {
store.audit(viewer.user.id, 'release.dispatch_failed', String(error instanceof Error ? error.message : error).slice(0, 300))
return reply.redirect('/admin?error=' + encodeURIComponent(t(`读取发布状态失败:${String(error instanceof Error ? error.message : error).slice(0, 200)}`, `Could not read the release state: ${String(error instanceof Error ? error.message : error).slice(0, 200)}`)))
}
if (!preview.eligible) {
return reply.redirect('/admin?error=' + encodeURIComponent(t(`一键发布不可用:${preview.reason}`, `One-click release is unavailable: ${preview.reason}`)))
}
const confirm = String((request.body as Record<string, unknown> | undefined)?.confirm ?? '').trim()
if (confirm !== `RELEASE ${preview.nextVersion}`) {
return reply.redirect('/admin?error=' + encodeURIComponent(t(`请准确输入 RELEASE ${preview.nextVersion} 以确认。`, `Type RELEASE ${preview.nextVersion} to confirm.`)))
}
store.audit(viewer.user.id, 'release.requested', `${preview.repo} v${preview.nextVersion} ${preview.mainSha}`)
try {
const { result } = await previewAndDispatch({
fetch: globalThis.fetch,
token: config.release.dispatchToken,
repo: config.release.repo,
workflow: config.release.workflow,
ref: config.release.ref,
})
store.audit(viewer.user.id, 'release.dispatched', `${preview.repo} v${preview.nextVersion} ${result.runUrl}`)
return reply.redirect('/admin?notice=' + encodeURIComponent(t(`已启动 v${preview.nextVersion} 发布流程:${result.runUrl}`, `Started the v${preview.nextVersion} release: ${result.runUrl}`)) + '#release')
} catch (error) {
store.audit(viewer.user.id, 'release.dispatch_failed', String(error instanceof Error ? error.message : error).slice(0, 300))
return reply.redirect('/admin?error=' + encodeURIComponent(t(`发布启动失败:${String(error instanceof Error ? error.message : error).slice(0, 200)}`, `Could not start the release: ${String(error instanceof Error ? error.message : error).slice(0, 200)}`)) + '#release')
}
})

// #395: the deployment read model. The latest release comes from the
// `verify-release.mjs` snapshot this instance already reads on /admin, and the
// running side is the recorded deployment row. Fledge never probes a host or
Expand Down
15 changes: 15 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ export interface Config {
}
// How long a GitHub re-authentication stays "recent" for destructive actions.
recentAuthMinutes: number
// #897: the superadmin release action dispatches the existing release
// workflow. The token only needs Actions: write on the Fledge repository; it
// is a server secret and is never rendered or logged.
release: {
dispatchToken: string
repo: string
workflow: string
ref: string
}
// #690: how long after its `trial.expired` row a never-used rejected account is
// erased. The sweep's purge phase reads this; 72 hours is the host-side cron it
// replaces.
Expand Down Expand Up @@ -307,6 +316,12 @@ export function loadConfig(overrides: Partial<Config> = {}): Config {
instancesGlobal: Math.max(0, number('LIMIT_INSTANCES_GLOBAL', 0)),
},
recentAuthMinutes: Math.max(1, number('RECENT_AUTH_MINUTES', 15)),
release: {
dispatchToken: text('RELEASE_DISPATCH_TOKEN'),
repo: text('RELEASE_DISPATCH_REPO', 'HugoXK/fledge'),
workflow: text('RELEASE_DISPATCH_WORKFLOW', 'daily-release.yml'),
ref: text('RELEASE_DISPATCH_REF', 'main'),
},
trialPurgeGraceHours: Math.max(1, number('TRIAL_PURGE_GRACE_HOURS', 72)),
autoPromoteDiscovery: bool('AUTO_PROMOTE_DISCOVERY', false),
autoPromoteDiscoveryDailyCap: Math.max(0, number('AUTO_PROMOTE_DISCOVERY_DAILY_CAP', 3)),
Expand Down
Loading
Loading