Skip to content

Commit 2d08c40

Browse files
committed
Merge branch 'feature/onclick-deploy'
2 parents 529e904 + 9adf26d commit 2d08c40

File tree

2 files changed

+67
-36
lines changed

2 files changed

+67
-36
lines changed

packages/framework-core/src/sam/api.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,19 @@ export class SamApi {
2626
ExtensionIds: ids,
2727
});
2828
}
29+
30+
/**
31+
* 上报部署状态
32+
*/
33+
reportCloudBaseCIResultCallback(
34+
ciId: string,
35+
traceId: string,
36+
extensionId: string
37+
) {
38+
return CloudApi.tcbService.request("CloudBaseCIResultCallback", {
39+
CIID: ciId,
40+
TraceId: traceId,
41+
ExtensionID: extensionId,
42+
});
43+
}
2944
}

packages/framework-core/src/sam/index.ts

Lines changed: 52 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -76,49 +76,65 @@ export class SamManager {
7676
}
7777
}
7878

79-
const bar = new ProgressBar("正在部署[:bar] :percent :elapsed s", {
80-
complete: "░",
81-
incomplete: " ",
82-
width: 40,
83-
total: 100,
84-
});
85-
let percent = 0;
86-
87-
await this.waitUntil(async () => {
88-
const statusRes = await this.samApi.fetchExtensionTaskStatus([
89-
extensionId,
90-
]);
91-
92-
const taskInfos = statusRes.ExtensionTaskInfo;
93-
94-
const taskInfo = taskInfos[0];
95-
96-
if (taskInfo) {
97-
const delta = (taskInfo.Percent || 0) - percent;
98-
percent = taskInfo.Percent || 0;
99-
bar.tick(delta);
100-
101-
if (taskInfo.Status === "running") {
102-
return true;
103-
} else if (taskInfo.Detail) {
104-
throw new Error(
105-
`
106-
部署失败,错误信息:${taskInfo.Detail}, 请求RequestId:${statusRes.RequestId}`
107-
);
108-
}
109-
}
110-
111-
return taskInfos.filter((item: any) =>
112-
["running"].includes(item.Status)
113-
).length;
114-
});
79+
// 云端一键部署时不轮询查询结果
80+
if (process.env.CLOUDBASE_CIID) {
81+
await this.samApi.reportCloudBaseCIResultCallback(
82+
process.env.CLOUDBASE_CIID,
83+
process.env.CLOUDBASE_TRACEID || "",
84+
extensionId
85+
);
86+
} else {
87+
await this.checkStatus(extensionId);
88+
}
11589
} catch (e) {
11690
this.clear();
11791
throw e;
11892
}
11993
this.clear();
12094
}
12195

96+
/**
97+
* 轮询状态
98+
* @param extensionId
99+
*/
100+
async checkStatus(extensionId: string) {
101+
const bar = new ProgressBar("正在部署[:bar] :percent :elapsed s", {
102+
complete: "░",
103+
incomplete: " ",
104+
width: 40,
105+
total: 100,
106+
});
107+
let percent = 0;
108+
109+
await this.waitUntil(async () => {
110+
const statusRes = await this.samApi.fetchExtensionTaskStatus([
111+
extensionId,
112+
]);
113+
114+
const taskInfos = statusRes.ExtensionTaskInfo;
115+
116+
const taskInfo = taskInfos[0];
117+
118+
if (taskInfo) {
119+
const delta = (taskInfo.Percent || 0) - percent;
120+
percent = taskInfo.Percent || 0;
121+
bar.tick(delta);
122+
123+
if (taskInfo.Status === "running") {
124+
return true;
125+
} else if (taskInfo.Detail) {
126+
throw new Error(
127+
`
128+
部署失败,错误信息:${taskInfo.Detail}, 请求RequestId:${statusRes.RequestId}`
129+
);
130+
}
131+
}
132+
133+
return taskInfos.filter((item: any) => ["running"].includes(item.Status))
134+
.length;
135+
});
136+
}
137+
122138
clear() {
123139
fs.unlinkSync(path.join(this.projectPath, "TCBSAM.yaml"));
124140
}

0 commit comments

Comments
 (0)