feat(release): add emergency app rollback

This commit is contained in:
t8y2 committed 2026-07-23 11:22:28 +08:00
1 parent 5fb4b7307e
commit a21cfa0d40
5 files changed
+287 -3

No files matched your search

+6
View File
@@ -6,6 +6,11 @@ on:
tag: tag:
description: "Release tag (e.g. v0.3.10)" description: "Release tag (e.g. v0.3.10)"
required: true required: true
notify:
description: "Send release notification"
required: false
default: true
type: boolean
permissions: permissions:
contents: write contents: write
@@ -400,6 +405,7 @@ jobs:
notify-qq: notify-qq:
name: QQ Notify name: QQ Notify
needs: [promote-release] needs: [promote-release]
if: ${{ inputs.notify }}
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Build message - name: Build message
@@ -0,0 +1,61 @@
name: Rollback Docker Latest
on:
workflow_dispatch:
inputs:
tag:
description: "Published app release tag to promote as Docker latest"
required: true
type: string
permissions:
contents: read
env:
CNB_REPOSITORY: "dbxio.com/dbx"
CNB_REGISTRY: "docker.cnb.cool"
jobs:
rollback-docker-latest:
runs-on: ubuntu-latest
steps:
- name: Validate version tag
id: version
shell: bash
run: |
set -euo pipefail
tag="${{ inputs.tag }}"
if [[ ! "$tag" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "::error::Tag '$tag' must use stable vX.Y.Z format."
exit 1
fi
echo "version=${tag#v}" >> "$GITHUB_OUTPUT"
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Login to CNB Registry
uses: docker/login-action@v3
with:
registry: ${{ env.CNB_REGISTRY }}
username: cnb
password: ${{ secrets.CNB_TOKEN }}
- name: Point latest tags to rollback version
env:
VERSION: ${{ steps.version.outputs.version }}
DOCKERHUB_REPOSITORY: ${{ secrets.DOCKERHUB_USERNAME }}/dbx
CNB_IMAGE: ${{ env.CNB_REGISTRY }}/${{ env.CNB_REPOSITORY }}
run: |
set -euo pipefail
# Reuse immutable version manifests; an emergency rollback must not rebuild source.
docker buildx imagetools inspect "${DOCKERHUB_REPOSITORY}:${VERSION}" >/dev/null
docker buildx imagetools inspect "${CNB_IMAGE}:${VERSION}" >/dev/null
docker buildx imagetools create -t "${DOCKERHUB_REPOSITORY}:latest" "${DOCKERHUB_REPOSITORY}:${VERSION}"
docker buildx imagetools create -t "${CNB_IMAGE}:latest" "${CNB_IMAGE}:${VERSION}"
+1
View File
@@ -21,6 +21,7 @@
"release:agents": "node scripts/release.mjs agents", "release:agents": "node scripts/release.mjs agents",
"release:app": "node scripts/release.mjs app", "release:app": "node scripts/release.mjs app",
"release:packages": "node scripts/release.mjs packages", "release:packages": "node scripts/release.mjs packages",
"test:release": "node --test scripts/release.test.mjs",
"build:knowledge-base": "node scripts/build-knowledge-base.mjs", "build:knowledge-base": "node scripts/build-knowledge-base.mjs",
"typecheck": "vue-tsc --noEmit --project apps/desktop/tsconfig.json", "typecheck": "vue-tsc --noEmit --project apps/desktop/tsconfig.json",
"build": "vite build --config apps/desktop/vite.config.ts", "build": "vite build --config apps/desktop/vite.config.ts",
+115 -3
View File
@@ -7,6 +7,8 @@ import { evaluateAgentVersionBump, getAgentVersionChanges, isAgentPublishRelevan
const REPO = "t8y2/dbx"; const REPO = "t8y2/dbx";
const PACKAGES_WORKFLOW = "mcp-release.yml"; const PACKAGES_WORKFLOW = "mcp-release.yml";
const APP_PUBLISH_WORKFLOW = "publish-packages.yml"; const APP_PUBLISH_WORKFLOW = "publish-packages.yml";
const APP_CNB_SYNC_WORKFLOW = "sync-cnb-release-assets.yml";
const APP_DOCKER_ROLLBACK_WORKFLOW = "rollback-docker-latest.yml";
const PACKAGE_TAG_PREFIX = "packages-v"; const PACKAGE_TAG_PREFIX = "packages-v";
const AGENT_TAG_PREFIX = "agents-v"; const AGENT_TAG_PREFIX = "agents-v";
const APP_TAG_PREFIX = "v"; const APP_TAG_PREFIX = "v";
@@ -117,7 +119,7 @@ if (!skipFetch) {
if (!target) { if (!target) {
if (!process.stdin.isTTY) { if (!process.stdin.isTTY) {
fail("Release target is required in a non-interactive shell. Use packages, agents, or app."); fail("Release target is required in a non-interactive shell. Use packages, agents, app, or rollback.");
} }
target = await promptTarget(); target = await promptTarget();
} }
@@ -128,6 +130,8 @@ if (target === "packages") {
await releaseAgents(requestedBump ?? "patch"); await releaseAgents(requestedBump ?? "patch");
} else if (target === "app") { } else if (target === "app") {
await publishApp(requestedBump); await publishApp(requestedBump);
} else if (target === "rollback") {
await rollbackApp(requestedBump);
} else { } else {
fail(`Unknown release target: ${target}`); fail(`Unknown release target: ${target}`);
} }
@@ -222,6 +226,40 @@ async function publishApp(tagInput) {
console.log(green(`Triggered Publish Packages for ${releaseTag}.`)); console.log(green(`Triggered Publish Packages for ${releaseTag}.`));
} }
async function rollbackApp(tagInput) {
const releaseTag = resolveRollbackTag(tagInput ?? (await promptRollbackTag()));
const publishArgs = ["workflow", "run", APP_PUBLISH_WORKFLOW, "--repo", REPO, "-f", `tag=${releaseTag}`, "-f", "notify=false"];
const cnbArgs = ["workflow", "run", APP_CNB_SYNC_WORKFLOW, "--repo", REPO, "-f", `tag=${releaseTag}`];
const dockerArgs = ["workflow", "run", APP_DOCKER_ROLLBACK_WORKFLOW, "--repo", REPO, "-f", `tag=${releaseTag}`];
console.log(kv("Release target", "Emergency app rollback", bold));
console.log(kv("Rollback tag", releaseTag, yellow));
console.log(yellow("This stops further rollout but does not downgrade clients that already installed a newer version."));
console.log(kv("GitHub / R2 / Homebrew / Scoop", `gh ${publishArgs.join(" ")}`, dim));
console.log(kv("CNB release assets", `gh ${cnbArgs.join(" ")}`, dim));
console.log(kv("Docker latest", `gh ${dockerArgs.join(" ")}`, dim));
if (dryRun) {
console.log(dim("Dry run only; rollback workflows were not triggered and release metadata was not changed."));
return;
}
ensureGhWorkflowsReady([APP_PUBLISH_WORKFLOW, APP_CNB_SYNC_WORKFLOW, APP_DOCKER_ROLLBACK_WORKFLOW]);
const latestRelease = getGithubRelease();
const rollbackRelease = getGithubRelease(releaseTag);
validateRollbackRelease(rollbackRelease, latestRelease);
console.log(kv("Current latest release", latestRelease.tagName, red));
console.log(kv("Rollback release", rollbackRelease.tagName, green));
await confirmRollbackOrExit(releaseTag);
// Dispatch existing credential-owning workflows instead of handling release secrets locally.
run("gh", publishArgs, { stdio: "inherit" });
run("gh", cnbArgs, { stdio: "inherit" });
run("gh", dockerArgs, { stdio: "inherit" });
console.log(green(`Triggered emergency rollback to ${releaseTag}. Monitor all three workflows before announcing completion.`));
}
async function promptTarget() { async function promptTarget() {
const packageStatus = getPackageReleaseStatus(); const packageStatus = getPackageReleaseStatus();
const agentStatus = getAgentReleaseStatus(getLatestAgentTag()); const agentStatus = getAgentReleaseStatus(getLatestAgentTag());
@@ -229,15 +267,24 @@ async function promptTarget() {
${cyan("1")}. Node packages / MCP (${formatStatusSummary(packageStatus)}) ${cyan("1")}. Node packages / MCP (${formatStatusSummary(packageStatus)})
${cyan("2")}. Agents (${formatStatusSummary(agentStatus)}) ${cyan("2")}. Agents (${formatStatusSummary(agentStatus)})
${cyan("3")}. App distribution ${cyan("3")}. App distribution
${cyan("4")}. Emergency app rollback
${dim("Choice")} [1]: `); ${dim("Choice")} [1]: `);
const normalized = answer.trim().toLowerCase(); const normalized = answer.trim().toLowerCase();
if (!normalized || normalized === "1" || normalized === "packages" || normalized === "mcp") return "packages"; if (!normalized || normalized === "1" || normalized === "packages" || normalized === "mcp") return "packages";
if (normalized === "2" || normalized === "agents" || normalized === "agent") return "agents"; if (normalized === "2" || normalized === "agents" || normalized === "agent") return "agents";
if (normalized === "3" || normalized === "app" || normalized === "desktop" || normalized === "publish") return "app"; if (normalized === "3" || normalized === "app" || normalized === "desktop" || normalized === "publish") return "app";
if (normalized === "4" || normalized === "rollback" || normalized === "revert") return "rollback";
fail(`Unknown release target: ${answer}`); fail(`Unknown release target: ${answer}`);
} }
async function promptRollbackTag() {
if (!process.stdin.isTTY) {
fail("Rollback tag is required in a non-interactive shell. Use rollback vX.Y.Z.");
}
return ask(`Rollback to published app tag ${dim("(for example v0.5.63)")}: `);
}
async function confirmOrExit(message) { async function confirmOrExit(message) {
if (yes) return; if (yes) return;
if (!process.stdin.isTTY) { if (!process.stdin.isTTY) {
@@ -251,6 +298,20 @@ async function confirmOrExit(message) {
} }
} }
async function confirmRollbackOrExit(releaseTag) {
if (yes) return;
if (!process.stdin.isTTY) {
fail("Refusing to trigger rollback without confirmation in a non-interactive shell. Re-run with --yes if this is intentional.");
}
// A typed tag makes accidental selection of this destructive menu action much less likely.
const answer = await ask(`Type ${bold(releaseTag)} to confirm the emergency rollback: `);
if (answer.trim() !== releaseTag) {
console.log(dim("Cancelled."));
process.exit(0);
}
}
async function ask(question) { async function ask(question) {
const rl = createInterface({ input, output }); const rl = createInterface({ input, output });
const answer = await rl.question(question); const answer = await rl.question(question);
@@ -262,9 +323,51 @@ function normalizeTarget(value) {
if (["package", "packages", "node-packages", "node", "mcp"].includes(value)) return "packages"; if (["package", "packages", "node-packages", "node", "mcp"].includes(value)) return "packages";
if (["agent", "agents"].includes(value)) return "agents"; if (["agent", "agents"].includes(value)) return "agents";
if (["app", "desktop", "publish", "publish-packages", "distribution"].includes(value)) return "app"; if (["app", "desktop", "publish", "publish-packages", "distribution"].includes(value)) return "app";
if (["rollback", "revert", "emergency-rollback"].includes(value)) return "rollback";
return null; return null;
} }
function resolveRollbackTag(value) {
const releaseTag = resolveAppTag(value);
if (!/^v\d+\.\d+\.\d+$/.test(releaseTag)) {
fail("Emergency rollback only supports stable vX.Y.Z app releases.");
}
return releaseTag;
}
function getGithubRelease(tag) {
const releaseArgs = ["release", "view"];
if (tag) releaseArgs.push(tag);
releaseArgs.push("--repo", REPO, "--json", "tagName,isDraft,isPrerelease,publishedAt,assets");
return JSON.parse(run("gh", releaseArgs).stdout);
}
function validateRollbackRelease(rollbackRelease, latestRelease) {
if (rollbackRelease.isDraft || rollbackRelease.isPrerelease || !rollbackRelease.publishedAt) {
fail(`Rollback target ${rollbackRelease.tagName} must be a published stable release.`);
}
const rollbackVersion = parseVersion(rollbackRelease.tagName.replace(/^v/, ""));
const latestVersion = parseVersion(latestRelease.tagName.replace(/^v/, ""));
if (!rollbackVersion || !latestVersion || compareVersions(rollbackVersion, latestVersion) >= 0) {
fail(`Rollback target ${rollbackRelease.tagName} must be older than the current latest release ${latestRelease.tagName}.`);
}
const version = formatVersion(rollbackVersion);
const requiredAssets = [
"latest.json",
`DBX_${version}_aarch64.dmg`,
`DBX_${version}_x64.dmg`,
`DBX_${version}_x64-setup.exe`,
`DBX_${version}_arm64-setup.exe`,
];
const assetNames = new Set(rollbackRelease.assets.map((asset) => asset.name));
const missingAssets = requiredAssets.filter((asset) => !assetNames.has(asset));
if (missingAssets.length > 0) {
fail(`Rollback target ${rollbackRelease.tagName} is missing required distribution assets: ${missingAssets.join(", ")}`);
}
}
function getLatestPackageVersion() { function getLatestPackageVersion() {
const tag = getLatestSemverTag(PACKAGE_TAG_PREFIX); const tag = getLatestSemverTag(PACKAGE_TAG_PREFIX);
if (tag) return tag.versionText; if (tag) return tag.versionText;
@@ -530,6 +633,13 @@ function ensureGhReady(workflow) {
run("gh", ["workflow", "view", workflow, "--repo", REPO], { stdio: "inherit" }); run("gh", ["workflow", "view", workflow, "--repo", REPO], { stdio: "inherit" });
} }
function ensureGhWorkflowsReady(workflows) {
run("gh", ["auth", "status", "--hostname", "github.com"], { stdio: "inherit" });
for (const workflow of workflows) {
run("gh", ["workflow", "view", workflow, "--repo", REPO], { stdio: "inherit" });
}
}
function fetchReleaseTags() { function fetchReleaseTags() {
run("git", [ run("git", [
"fetch", "fetch",
@@ -571,14 +681,15 @@ function fail(message) {
} }
function printHelp() { function printHelp() {
console.log(`Usage: node scripts/release.mjs [packages|agents|app] [patch|minor|major|version] [options] console.log(`Usage: node scripts/release.mjs [packages|agents|app|rollback] [patch|minor|major|version] [options]
Unified release trigger for DBX packages, agents, and app distribution. Unified release and emergency rollback trigger for DBX packages, agents, and app distribution.
Targets: Targets:
packages Trigger Node Packages Release via gh workflow run packages Trigger Node Packages Release via gh workflow run
agents Create and push an agents-v* tag agents Create and push an agents-v* tag
app Trigger Publish Packages for an existing v* app release tag app Trigger Publish Packages for an existing v* app release tag
rollback Roll app distribution channels back to an older published v* tag
Arguments: Arguments:
patch Bump the latest target tag by one patch version (default) patch Bump the latest target tag by one patch version (default)
@@ -588,6 +699,7 @@ Arguments:
packages-v0.4.14 Explicit package tag style, for packages packages-v0.4.14 Explicit package tag style, for packages
agents-v0.4.14 Explicit agent tag style, for agents agents-v0.4.14 Explicit agent tag style, for agents
v0.5.38 Existing app release tag, for app v0.5.38 Existing app release tag, for app
rollback v0.5.63 Emergency rollback target tag
Options: Options:
--dry-run Print the release command without triggering it --dry-run Print the release command without triggering it
+104
View File
@@ -0,0 +1,104 @@
import assert from "node:assert/strict";
import { chmodSync, mkdtempSync, readFileSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { spawnSync } from "node:child_process";
import test from "node:test";
const repoRoot = new URL("..", import.meta.url).pathname;
const releaseScript = join(repoRoot, "scripts/release.mjs");
function runRelease(args, env = {}) {
return spawnSync(process.execPath, [releaseScript, ...args], {
cwd: repoRoot,
encoding: "utf8",
env: { ...process.env, NO_COLOR: "1", ...env },
});
}
function createMockGh() {
const directory = mkdtempSync(join(tmpdir(), "dbx-release-test-"));
const ghPath = join(directory, "gh");
writeFileSync(
ghPath,
[
"#!/usr/bin/env node",
'import { appendFileSync } from "node:fs";',
"",
"const args = process.argv.slice(2);",
'if (args[0] === "auth" || (args[0] === "workflow" && args[1] === "view")) process.exit(0);',
'if (args[0] === "workflow" && args[1] === "run") {',
' appendFileSync(process.env.GH_LOG, args.join(" ") + "\\n");',
" process.exit(0);",
"}",
'if (args[0] === "release" && args[1] === "view") {',
' const explicitTag = args[2]?.startsWith("v") ? args[2] : null;',
" const tagName = explicitTag ?? process.env.MOCK_LATEST_TAG;",
" const version = tagName.slice(1);",
" const assets = [",
' "latest.json",',
' "DBX_" + version + "_aarch64.dmg",',
' "DBX_" + version + "_x64.dmg",',
' "DBX_" + version + "_x64-setup.exe",',
' "DBX_" + version + "_arm64-setup.exe",',
" ].map((name) => ({ name }));",
' process.stdout.write(JSON.stringify({ tagName, isDraft: false, isPrerelease: false, publishedAt: "2026-07-21T00:00:00Z", assets }));',
" process.exit(0);",
"}",
'process.stderr.write("Unexpected gh command: " + args.join(" "));',
"process.exit(1);",
"",
].join("\n"),
);
chmodSync(ghPath, 0o755);
return directory;
}
test("rollback dry-run prints all affected channels without invoking GitHub", () => {
const result = runRelease(["rollback", "v0.5.63", "--dry-run", "--skip-fetch"]);
assert.equal(result.status, 0, result.stderr);
assert.match(result.stdout, /Emergency app rollback/);
assert.match(result.stdout, /publish-packages\.yml.*notify=false/);
assert.match(result.stdout, /sync-cnb-release-assets\.yml/);
assert.match(result.stdout, /rollback-docker-latest\.yml/);
assert.match(result.stdout, /does not downgrade clients/);
});
test("rollback dispatches each distribution workflow after validation", () => {
const mockBin = createMockGh();
const logPath = join(mockBin, "gh.log");
const result = runRelease(["rollback", "v0.5.63", "--yes", "--skip-fetch"], {
PATH: `${mockBin}:${process.env.PATH}`,
GH_LOG: logPath,
MOCK_LATEST_TAG: "v0.5.64",
});
assert.equal(result.status, 0, result.stderr);
const commands = readFileSync(logPath, "utf8").trim().split("\n");
assert.deepEqual(commands, [
"workflow run publish-packages.yml --repo t8y2/dbx -f tag=v0.5.63 -f notify=false",
"workflow run sync-cnb-release-assets.yml --repo t8y2/dbx -f tag=v0.5.63",
"workflow run rollback-docker-latest.yml --repo t8y2/dbx -f tag=v0.5.63",
]);
});
test("rollback rejects a target that is not older than latest", () => {
const mockBin = createMockGh();
const logPath = join(mockBin, "gh.log");
const result = runRelease(["rollback", "v0.5.64", "--yes", "--skip-fetch"], {
PATH: `${mockBin}:${process.env.PATH}`,
GH_LOG: logPath,
MOCK_LATEST_TAG: "v0.5.64",
});
assert.equal(result.status, 1);
assert.match(result.stderr, /must be older than the current latest release v0\.5\.64/);
});
test("rollback rejects prerelease tag syntax", () => {
const result = runRelease(["rollback", "v0.5.63-rc.1", "--dry-run", "--skip-fetch"]);
assert.equal(result.status, 1);
assert.match(result.stderr, /only supports stable vX\.Y\.Z app releases/);
});