feat: 添加云端构建功能,支持参数配置和环境变量

This commit is contained in:
2026-03-10 01:18:27 +08:00
parent 7d227d3913
commit d08345d81c
6 changed files with 281 additions and 22 deletions

View File

@@ -0,0 +1,43 @@
import { createSkill, tool } from '@kevisual/router';
import { app, cnbManager, notCNBCheck } from '../../app.ts';
// 启动工作空间
app.route({
path: 'cnb',
key: 'cloud-build',
description: '云端构建,参数 event, repo, branch, ref, config, env',
middleware: ['auth'],
metadata: {
tags: ['opencode'],
...createSkill({
skill: 'cloud-build',
title: '云端构建',
summary: '在云端构建代码仓库,参数包括 event, repo, branch, ref, config, env',
args: {
env: tool.schema.any().optional().describe('构建环境变量,格式为 { "KEY": "VALUE" }'),
event: tool.schema.string().optional().describe('触发事件类型,例如 api_trigger_event'),
branch: tool.schema.string().optional().describe('分支名称,默认主分支'),
config: tool.schema.string().describe('构建config文件内容例如 cloudbuild.yaml对应的yml的内容'),
repo: tool.schema.string().describe('代码仓库路径,例如 user/repo'),
},
})
}
}).define(async (ctx) => {
const cnb = await cnbManager.getContext(ctx);
const repo = ctx.query?.repo;
const branch = ctx.query?.branch || 'main';
const config = ctx.query?.config;
const event = ctx.query?.event || 'api_trigger_event';
const env = ctx.query?.env ?? {};
if (!repo) {
ctx.throw(400, '缺少参数 repo');
}
const res = await cnb.build.startBuild(repo, {
branch,
config,
event,
env,
});
ctx.forward(res);
}).addTo(app);

View File

@@ -3,6 +3,7 @@ import { app, cnbManager, notCNBCheck } from '../../app.ts';
import z from 'zod';
import './skills.ts';
import './keep.ts';
import './build.ts';
// 启动工作空间
app.route({
@@ -67,7 +68,7 @@ app.route({
page: page ?? 1,
pageSize: pageSize ?? 100,
});
ctx.forward({ code: 200, message: 'success', data: res });
ctx.forward(res);
}).addTo(app);
// 获取工作空间详情
@@ -99,7 +100,7 @@ app.route({
ctx.throw(400, '缺少参数 sn');
}
const res = await cnb.workspace.getDetail(repo, sn);
ctx.forward({ code: 200, message: 'success', data: res });
ctx.forward(res);
}).addTo(app);
// 删除工作空间
@@ -161,7 +162,6 @@ app.route({
})
}
}).define(async (ctx) => {
if (notCNBCheck(ctx)) { return; }
const cnb = await cnbManager.getContext(ctx);
const pipelineId = ctx.query?.pipelineId;
const sn = ctx.query?.sn;
@@ -169,6 +169,7 @@ app.route({
ctx.throw(400, 'pipelineId 和 sn 必须提供其中一个');
}
const res = await cnb.workspace.stopWorkspace({ pipelineId, sn });
ctx.forward({ code: 200, message: 'success', data: res });
ctx.forward(res);
}).addTo(app);