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