fix: 分离小程序构建状态与发布状态
This commit is contained in:
1 parent
998e32e49c
commit
8e90b8ca09
7 files changed
+41
-57
No files matched your search
@@ -90,7 +90,7 @@ export function PublicationPage({ canManageTemplate }: { canManageTemplate: bool
|
||||
});
|
||||
}, [miniAppSettings.data, miniAppSettingsForm]);
|
||||
useEffect(() => {
|
||||
const building = miniAppReleases.data?.find((task) => task.status === "building");
|
||||
const building = miniAppReleases.data?.find((task) => task.buildStatus === "building");
|
||||
if (!building) return;
|
||||
const timer = setInterval(() => void miniAppReleases.refetch(), 1500);
|
||||
return () => clearInterval(timer);
|
||||
@@ -538,9 +538,9 @@ export function PublicationPage({ canManageTemplate }: { canManageTemplate: bool
|
||||
color={
|
||||
task.status === "published"
|
||||
? "green"
|
||||
: task.status === "failed" || task.status === "build_failed"
|
||||
: task.status === "failed" || task.buildStatus === "failed"
|
||||
? "red"
|
||||
: task.status === "building"
|
||||
: task.buildStatus === "building"
|
||||
? "orange"
|
||||
: "blue"
|
||||
}
|
||||
@@ -553,10 +553,10 @@ export function PublicationPage({ canManageTemplate }: { canManageTemplate: bool
|
||||
</Typography.Text>
|
||||
)}
|
||||
{task.error && <Typography.Text type="danger">{task.error}</Typography.Text>}
|
||||
{task.status === "building" && (
|
||||
{task.buildStatus === "building" && (
|
||||
<Typography.Text type="secondary">正在构建微信小程序...</Typography.Text>
|
||||
)}
|
||||
{task.status === "build_failed" && (
|
||||
{task.buildStatus === "failed" && (
|
||||
<Typography.Text type="secondary">微信小程序构建失败</Typography.Text>
|
||||
)}
|
||||
{task.buildLogs?.length ? (
|
||||
@@ -573,7 +573,7 @@ export function PublicationPage({ canManageTemplate }: { canManageTemplate: bool
|
||||
))}
|
||||
</Space>
|
||||
) : null}
|
||||
{(task.status === "built" || task.status === "build_failed") && (
|
||||
{(task.status === "built" || task.buildStatus === "failed") && (
|
||||
<Button
|
||||
size="small"
|
||||
loading={uploadMiniAppRelease.isPending}
|
||||
|
||||
+2
-2
@@ -1,3 +1,3 @@
|
||||
ALTER TYPE "MiniAppReleaseStatus" ADD VALUE 'building' AFTER 'built';
|
||||
ALTER TYPE "MiniAppReleaseStatus" ADD VALUE 'build_failed' AFTER 'building';
|
||||
ALTER TABLE "MiniAppReleaseTask" ADD COLUMN "buildLogs" JSONB;
|
||||
CREATE TYPE "MiniAppBuildStatus" AS ENUM ('idle', 'building', 'success', 'failed');
|
||||
ALTER TABLE "MiniAppReleaseTask" ADD COLUMN "buildStatus" "MiniAppBuildStatus" NOT NULL DEFAULT 'idle';
|
||||
@@ -102,8 +102,6 @@ model CapabilityInstallation {
|
||||
|
||||
enum MiniAppReleaseStatus {
|
||||
built
|
||||
building
|
||||
build_failed
|
||||
uploaded
|
||||
under_review
|
||||
rejected
|
||||
@@ -122,6 +120,7 @@ model MiniAppReleaseTask {
|
||||
status MiniAppReleaseStatus @default(built)
|
||||
artifactPath String?
|
||||
buildLogs Json?
|
||||
buildStatus MiniAppBuildStatus @default(idle)
|
||||
actorId String
|
||||
error String?
|
||||
weappUploadId String?
|
||||
@@ -133,6 +132,13 @@ model MiniAppReleaseTask {
|
||||
@@index([brandId, createdAt])
|
||||
}
|
||||
|
||||
enum MiniAppBuildStatus {
|
||||
idle
|
||||
building
|
||||
success
|
||||
failed
|
||||
}
|
||||
|
||||
model CapabilityAuditLog {
|
||||
id String @id @default(uuid())
|
||||
brandId String
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import {
|
||||
BadRequestException,
|
||||
Body,
|
||||
ConflictException,
|
||||
Controller,
|
||||
Get,
|
||||
Param,
|
||||
@@ -168,6 +169,8 @@ export class AdminMiniAppReleaseController {
|
||||
if (!task) throw new BadRequestException("小程序发布任务不存在");
|
||||
if (task.status !== "built" && task.status !== "failed")
|
||||
throw new BadRequestException("当前小程序发布任务不能重复上传");
|
||||
if (task.buildStatus === "building")
|
||||
throw new ConflictException("小程序构建正在进行中,请稍后");
|
||||
const brand = await this.prisma.brandProfile.findUniqueOrThrow({
|
||||
where: { id: identity.brandId },
|
||||
select: { miniAppSettings: true, templateKey: true },
|
||||
@@ -191,13 +194,18 @@ export class AdminMiniAppReleaseController {
|
||||
},
|
||||
];
|
||||
await this.releases.updateStatus(identity.brandId, identity.subject, taskId, {
|
||||
status: "building",
|
||||
status: task.status,
|
||||
buildLogs,
|
||||
buildStatus: "building",
|
||||
});
|
||||
const result = await this.buildWeApp(templateKey, (message, stream) => {
|
||||
buildLogs.push({ at: new Date().toISOString(), message, stream });
|
||||
void this.releases
|
||||
.updateStatus(identity.brandId, identity.subject, taskId, { status: "building", buildLogs })
|
||||
.updateStatus(identity.brandId, identity.subject, taskId, {
|
||||
status: task.status,
|
||||
buildLogs,
|
||||
buildStatus: "building",
|
||||
})
|
||||
.catch(() => undefined);
|
||||
});
|
||||
if (result.exitCode !== 0) {
|
||||
@@ -207,9 +215,10 @@ export class AdminMiniAppReleaseController {
|
||||
stream: "stderr",
|
||||
});
|
||||
await this.releases.updateStatus(identity.brandId, identity.subject, taskId, {
|
||||
status: "build_failed",
|
||||
status: task.status,
|
||||
error: `小程序构建失败,请查看构建日志`,
|
||||
buildLogs,
|
||||
buildStatus: "failed",
|
||||
});
|
||||
throw new BadRequestException("小程序构建失败,请查看构建日志");
|
||||
}
|
||||
@@ -220,9 +229,10 @@ export class AdminMiniAppReleaseController {
|
||||
stream: "stderr",
|
||||
});
|
||||
await this.releases.updateStatus(identity.brandId, identity.subject, taskId, {
|
||||
status: "build_failed",
|
||||
status: task.status,
|
||||
error: "小程序构建产物缺少 app.json",
|
||||
buildLogs,
|
||||
buildStatus: "failed",
|
||||
});
|
||||
throw new BadRequestException("小程序构建产物缺少 app.json");
|
||||
}
|
||||
@@ -232,8 +242,9 @@ export class AdminMiniAppReleaseController {
|
||||
stream: "stdout",
|
||||
});
|
||||
await this.releases.updateStatus(identity.brandId, identity.subject, taskId, {
|
||||
status: "built",
|
||||
status: task.status,
|
||||
buildLogs,
|
||||
buildStatus: "success",
|
||||
});
|
||||
const ci = (await import("miniprogram-ci")) as unknown as MiniprogramCi;
|
||||
const project = new ci.Project({
|
||||
@@ -253,6 +264,7 @@ export class AdminMiniAppReleaseController {
|
||||
return this.releases.updateStatus(identity.brandId, identity.subject, taskId, {
|
||||
status: "uploaded",
|
||||
buildLogs,
|
||||
buildStatus: "success",
|
||||
weappUploadId:
|
||||
typeof uploadResult.strUint64Version === "string"
|
||||
? uploadResult.strUint64Version
|
||||
@@ -262,6 +274,7 @@ export class AdminMiniAppReleaseController {
|
||||
await this.releases.updateStatus(identity.brandId, identity.subject, taskId, {
|
||||
status: "failed",
|
||||
buildLogs,
|
||||
buildStatus: "failed",
|
||||
error: error instanceof Error ? error.message : "微信代码上传失败",
|
||||
});
|
||||
throw error;
|
||||
|
||||
@@ -8,27 +8,8 @@ export class CreateMiniAppReleaseDto {
|
||||
}
|
||||
|
||||
export class UpdateMiniAppReleaseStatusDto {
|
||||
@IsIn([
|
||||
"uploaded",
|
||||
"under_review",
|
||||
"approved",
|
||||
"rejected",
|
||||
"failed",
|
||||
"built",
|
||||
"building",
|
||||
"build_failed",
|
||||
"published",
|
||||
])
|
||||
status!:
|
||||
| "uploaded"
|
||||
| "under_review"
|
||||
| "approved"
|
||||
| "rejected"
|
||||
| "failed"
|
||||
| "built"
|
||||
| "building"
|
||||
| "build_failed"
|
||||
| "published";
|
||||
@IsIn(["uploaded", "under_review", "approved", "rejected", "failed", "built", "published"])
|
||||
status!: "uploaded" | "under_review" | "approved" | "rejected" | "failed" | "built" | "published";
|
||||
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
|
||||
@@ -9,8 +9,6 @@ import { PrismaService } from "../../prisma.service.js";
|
||||
|
||||
const transitions: Record<string, string[]> = {
|
||||
built: ["uploaded", "under_review", "failed"],
|
||||
building: ["built", "build_failed"],
|
||||
build_failed: ["built"],
|
||||
uploaded: ["under_review", "failed"],
|
||||
under_review: ["approved", "rejected", "failed"],
|
||||
approved: ["published", "failed"],
|
||||
@@ -66,15 +64,8 @@ export class AdminMiniAppReleaseService {
|
||||
taskId: string,
|
||||
input: {
|
||||
status:
|
||||
| "uploaded"
|
||||
| "under_review"
|
||||
| "approved"
|
||||
| "rejected"
|
||||
| "failed"
|
||||
| "built"
|
||||
| "building"
|
||||
| "build_failed"
|
||||
| "published";
|
||||
"uploaded" | "under_review" | "approved" | "rejected" | "failed" | "built" | "published";
|
||||
buildStatus?: "building" | "success" | "failed";
|
||||
error?: string;
|
||||
weappUploadId?: string;
|
||||
buildLogs?: unknown;
|
||||
@@ -103,6 +94,7 @@ export class AdminMiniAppReleaseService {
|
||||
...(input.buildLogs !== undefined
|
||||
? { buildLogs: input.buildLogs as Prisma.InputJsonValue }
|
||||
: {}),
|
||||
...(input.buildStatus ? { buildStatus: input.buildStatus } : {}),
|
||||
audit,
|
||||
},
|
||||
});
|
||||
|
||||
@@ -51,18 +51,10 @@ export interface BrandReleaseSummary {
|
||||
export interface MiniAppReleaseTask {
|
||||
id: string;
|
||||
version: number;
|
||||
status:
|
||||
| "built"
|
||||
| "building"
|
||||
| "build_failed"
|
||||
| "uploaded"
|
||||
| "under_review"
|
||||
| "rejected"
|
||||
| "approved"
|
||||
| "published"
|
||||
| "failed";
|
||||
status: "built" | "uploaded" | "under_review" | "rejected" | "approved" | "published" | "failed";
|
||||
artifactPath?: string | null;
|
||||
buildLogs?: Array<{ at: string; message: string; stream: "stdout" | "stderr" }> | null;
|
||||
buildStatus?: "idle" | "building" | "success" | "failed";
|
||||
error?: string | null;
|
||||
weappUploadId?: string | null;
|
||||
createdAt: string;
|
||||
|
||||
Reference in new issue
Block a user