From 2724f09a5b0a92b4d9e196dbbdf17b681eea7526 Mon Sep 17 00:00:00 2001 From: abearxiong Date: Mon, 5 Jan 2026 10:50:37 +0800 Subject: [PATCH] update --- .cnb.yml | 49 ++++++++-------- pnpm-lock.yaml | 135 ++++----------------------------------------- src/build/index.ts | 52 +++++++++++++++++ src/cnb-core.ts | 3 + src/index.ts | 14 ++++- test/build.ts | 18 ++++++ 6 files changed, 121 insertions(+), 150 deletions(-) create mode 100644 src/build/index.ts create mode 100644 test/build.ts diff --git a/.cnb.yml b/.cnb.yml index 1023e92..9ffcb88 100644 --- a/.cnb.yml +++ b/.cnb.yml @@ -12,16 +12,14 @@ $: # - name: pnpm install # script: pnpm install - -main: - web_trigger_sync_to_gitea: - - services: - - docker - imports: - - https://cnb.cool/kevisual/env/-/blob/main/env.yml - stages: - - name: 'show username' - script: echo "GITEA_USERNAME is ${GITEA_USERNAME} and GITEA_PASSWORD is ${GITEA_PASSWORD}" +_common: &common_sync_to_gitea + services: + - docker + imports: + - https://cnb.cool/kevisual/env/-/blob/main/env.yml + stages: + - name: 'show username' + script: echo "GITEA_USERNAME is ${GITEA_USERNAME} and GITEA_PASSWORD is ${GITEA_PASSWORD}" - name: sync to gitea image: tencentcom/git-sync settings: @@ -33,21 +31,26 @@ main: git_email: "xiongxiao@xiongxiao.me" sync_mode: rebase branch: main +_common: &common_sync_from_gitea + services: + - docker + imports: + - https://cnb.cool/kevisual/env/-/blob/main/env.yml + stages: + - name: '添加 gitea的origin' + script: | + git remote remove gitea 2>/dev/null || true + git remote add gitea https://oauth2:${GITEA_TOKEN}@git.xiongxiao.me/kevisual/cnb.git + - name: '同步gitea代码到当前仓库' + script: git pull gitea main + - name: '提交到原本的origin' + script: git push origin main +main: + web_trigger_sync_to_gitea: + - <<: *common_sync_to_gitea web_trigger_sync_from_gitea: - - services: - - docker - imports: - - https://cnb.cool/kevisual/env/-/blob/main/env.yml - stages: - - name: '添加 gitea的origin' - script: | - git remote remove gitea 2>/dev/null || true - git remote add gitea https://oauth2:${GITEA_TOKEN}@git.xiongxiao.me/kevisual/cnb.git - - name: '同步gitea代码到当前仓库' - script: git pull gitea main - - name: '提交到原本的origin' - script: git push origin main + - <<: *common_sync_from_gitea api_trigger_test: - stages: - name: test diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 6fbae85..bc5e986 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -18,25 +18,6 @@ importers: specifier: ^17.2.3 version: 17.2.3 - bun-test: - dependencies: - '@rollup/plugin-node-resolve': - specifier: ^16.0.3 - version: 16.0.3(rollup@4.54.0) - esbuild: - specifier: ^0.27.2 - version: 0.27.2 - lodash-es: - specifier: ^4.17.22 - version: 4.17.22 - rollup: - specifier: ^4.54.0 - version: 4.54.0 - devDependencies: - '@types/bun': - specifier: ^1.3.4 - version: 1.3.4 - web: devDependencies: '@kevisual/types': @@ -207,24 +188,6 @@ packages: '@kevisual/types@0.0.10': resolution: {integrity: sha512-Q73uzzjk9UidumnmCvOpgzqDDvQxsblz22bIFuoiioUFJWwaparx8bpd8ArRyFojicYL1YJoFDzDZ9j9NN8grA==} - '@rollup/plugin-node-resolve@16.0.3': - resolution: {integrity: sha512-lUYM3UBGuM93CnMPG1YocWu7X802BrNF3jW2zny5gQyLQgRFJhV1Sq0Zi74+dh/6NBx1DxFC4b4GXg9wUCG5Qg==} - engines: {node: '>=14.0.0'} - peerDependencies: - rollup: ^2.78.0||^3.0.0||^4.0.0 - peerDependenciesMeta: - rollup: - optional: true - - '@rollup/pluginutils@5.3.0': - resolution: {integrity: sha512-5EdhGZtnu3V88ces7s53hhfK5KSASnJZv8Lulpc04cWO3REESroJXg73DFsOmgbU2BhwV0E20bu2IDZb3VKW4Q==} - engines: {node: '>=14.0.0'} - peerDependencies: - rollup: ^1.20.0||^2.0.0||^3.0.0||^4.0.0 - peerDependenciesMeta: - rollup: - optional: true - '@rollup/rollup-android-arm-eabi@4.54.0': resolution: {integrity: sha512-OywsdRHrFvCdvsewAInDKCNyR3laPA2mc9bRYJ6LBp5IyvF3fvXbbNR0bSzHlZVFtn6E0xw2oZlyjg4rKCVcng==} cpu: [arm] @@ -259,56 +222,67 @@ packages: resolution: {integrity: sha512-EHMUcDwhtdRGlXZsGSIuXSYwD5kOT9NVnx9sqzYiwAc91wfYOE1g1djOEDseZJKKqtHAHGwnGPQu3kytmfaXLQ==} cpu: [arm] os: [linux] + libc: [glibc] '@rollup/rollup-linux-arm-musleabihf@4.54.0': resolution: {integrity: sha512-+pBrqEjaakN2ySv5RVrj/qLytYhPKEUwk+e3SFU5jTLHIcAtqh2rLrd/OkbNuHJpsBgxsD8ccJt5ga/SeG0JmA==} cpu: [arm] os: [linux] + libc: [musl] '@rollup/rollup-linux-arm64-gnu@4.54.0': resolution: {integrity: sha512-NSqc7rE9wuUaRBsBp5ckQ5CVz5aIRKCwsoa6WMF7G01sX3/qHUw/z4pv+D+ahL1EIKy6Enpcnz1RY8pf7bjwng==} cpu: [arm64] os: [linux] + libc: [glibc] '@rollup/rollup-linux-arm64-musl@4.54.0': resolution: {integrity: sha512-gr5vDbg3Bakga5kbdpqx81m2n9IX8M6gIMlQQIXiLTNeQW6CucvuInJ91EuCJ/JYvc+rcLLsDFcfAD1K7fMofg==} cpu: [arm64] os: [linux] + libc: [musl] '@rollup/rollup-linux-loong64-gnu@4.54.0': resolution: {integrity: sha512-gsrtB1NA3ZYj2vq0Rzkylo9ylCtW/PhpLEivlgWe0bpgtX5+9j9EZa0wtZiCjgu6zmSeZWyI/e2YRX1URozpIw==} cpu: [loong64] os: [linux] + libc: [glibc] '@rollup/rollup-linux-ppc64-gnu@4.54.0': resolution: {integrity: sha512-y3qNOfTBStmFNq+t4s7Tmc9hW2ENtPg8FeUD/VShI7rKxNW7O4fFeaYbMsd3tpFlIg1Q8IapFgy7Q9i2BqeBvA==} cpu: [ppc64] os: [linux] + libc: [glibc] '@rollup/rollup-linux-riscv64-gnu@4.54.0': resolution: {integrity: sha512-89sepv7h2lIVPsFma8iwmccN7Yjjtgz0Rj/Ou6fEqg3HDhpCa+Et+YSufy27i6b0Wav69Qv4WBNl3Rs6pwhebQ==} cpu: [riscv64] os: [linux] + libc: [glibc] '@rollup/rollup-linux-riscv64-musl@4.54.0': resolution: {integrity: sha512-ZcU77ieh0M2Q8Ur7D5X7KvK+UxbXeDHwiOt/CPSBTI1fBmeDMivW0dPkdqkT4rOgDjrDDBUed9x4EgraIKoR2A==} cpu: [riscv64] os: [linux] + libc: [musl] '@rollup/rollup-linux-s390x-gnu@4.54.0': resolution: {integrity: sha512-2AdWy5RdDF5+4YfG/YesGDDtbyJlC9LHmL6rZw6FurBJ5n4vFGupsOBGfwMRjBYH7qRQowT8D/U4LoSvVwOhSQ==} cpu: [s390x] os: [linux] + libc: [glibc] '@rollup/rollup-linux-x64-gnu@4.54.0': resolution: {integrity: sha512-WGt5J8Ij/rvyqpFexxk3ffKqqbLf9AqrTBbWDk7ApGUzaIs6V+s2s84kAxklFwmMF/vBNGrVdYgbblCOFFezMQ==} cpu: [x64] os: [linux] + libc: [glibc] '@rollup/rollup-linux-x64-musl@4.54.0': resolution: {integrity: sha512-JzQmb38ATzHjxlPHuTH6tE7ojnMKM2kYNzt44LO/jJi8BpceEC8QuXYA908n8r3CNuG/B3BV8VR3Hi1rYtmPiw==} cpu: [x64] os: [linux] + libc: [musl] '@rollup/rollup-openharmony-arm64@4.54.0': resolution: {integrity: sha512-huT3fd0iC7jigGh7n3q/+lfPcXxBi+om/Rs3yiFxjvSxbSB6aohDFXbWvlspaqjeOh+hx7DDHS+5Es5qRkWkZg==} @@ -344,16 +318,9 @@ packages: '@types/node@25.0.2': resolution: {integrity: sha512-gWEkeiyYE4vqjON/+Obqcoeffmk0NF15WSBwSs7zwVA2bAbTaE0SJ7P0WNGoJn8uE7fiaV5a7dKYIJriEqOrmA==} - '@types/resolve@1.20.2': - resolution: {integrity: sha512-60BCwRFOZCQhDncwQdxxeOEEkbc5dIMccYLwbxsS4TUNeVECQ/pBJ0j09mrHOl/JJvpRPGwO9SvE4nR2Nb/a4Q==} - bun-types@1.3.4: resolution: {integrity: sha512-5ua817+BZPZOlNaRgGBpZJOSAQ9RQ17pkwPD0yR7CfJg+r8DgIILByFifDTa+IPDDxzf5VNhtNlcKqFzDgJvlQ==} - deepmerge@4.3.1: - resolution: {integrity: sha512-3sUqbMEc77XqpdNO7FRyRog+eW3ph+GYCbj+rK+uYyRMuwsVy0rMiVtPn+QJlKFvWP/1PYpapqYn0Me2knFn+A==} - engines: {node: '>=0.10.0'} - dotenv@17.2.3: resolution: {integrity: sha512-JVUnt+DUIzu87TABbhPmNfVdBDt18BLOWjMUFJMSi/Qqg7NTYtabbvSNJGOJ7afbRuv9D/lngizHtP7QyLQ+9w==} engines: {node: '>=12'} @@ -363,9 +330,6 @@ packages: engines: {node: '>=18'} hasBin: true - estree-walker@2.0.2: - resolution: {integrity: sha512-Rfkk/Mp/DL7JVje3u18FxFujQlTNR2q6QfMSMB7AvCBx91NGj/ba3kCfza0f6dVDbw7YlRf/nDrn7pQrCCyQ/w==} - fdir@6.5.0: resolution: {integrity: sha512-tIbYtZbucOs0BRGqPJkshJUYdL+SDH7dVM8gjy+ERp3WAUjLEFJE+02kanyHtwjWOnwrKYBiwAmM0p4kLJAnXg==} engines: {node: '>=12.0.0'} @@ -380,31 +344,11 @@ packages: engines: {node: ^8.16.0 || ^10.6.0 || >=11.0.0} os: [darwin] - function-bind@1.1.2: - resolution: {integrity: sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==} - - hasown@2.0.2: - resolution: {integrity: sha512-0hJU9SCPvmMzIBdZFqNPXWa6dqh7WdH0cII9y+CyS8rG3nL48Bclra9HmKhVVUHyPWNH5Y7xDwAB7bfgSjkUMQ==} - engines: {node: '>= 0.4'} - - is-core-module@2.16.1: - resolution: {integrity: sha512-UfoeMA6fIJ8wTYFEUjelnaGI67v6+N7qXJEvQuIGa99l4xsCruSYOVSQ0uPANn4dAzm8lkYPaKLrrijLq7x23w==} - engines: {node: '>= 0.4'} - - is-module@1.0.0: - resolution: {integrity: sha512-51ypPSPCoTEIN9dy5Oy+h4pShgJmPCygKfyRCISBI+JoWT/2oJvK8QPxmwv7b/p239jXrm9M1mlQbyKJ5A152g==} - - lodash-es@4.17.22: - resolution: {integrity: sha512-XEawp1t0gxSi9x01glktRZ5HDy0HXqrM0x5pXQM98EaI0NxO6jVM7omDOxsuEo5UIASAnm2bRp1Jt/e0a2XU8Q==} - nanoid@3.3.11: resolution: {integrity: sha512-N8SpfPUnUp1bK+PMYW8qSWdl9U+wwNWI4QKxOYDy9JAro3WMX7p2OeVRF9v+347pnakNevPmiHhNmZ2HbFA76w==} engines: {node: ^10 || ^12 || ^13.7 || ^14 || >=15.0.1} hasBin: true - path-parse@1.0.7: - resolution: {integrity: sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==} - picocolors@1.1.1: resolution: {integrity: sha512-xceH2snhtb5M9liqDsmEw56le376mTZkEX/jEb/RxNFyegNul7eNslCXP9FDj/Lcu0X8KEyMceP2ntpaHrDEVA==} @@ -416,11 +360,6 @@ packages: resolution: {integrity: sha512-3Ybi1tAuwAP9s0r1UQ2J4n5Y0G05bJkpUIO0/bI9MhwmD70S5aTWbXGBwxHrelT+XM1k6dM0pk+SwNkpTRN7Pg==} engines: {node: ^10 || ^12 || >=14} - resolve@1.22.11: - resolution: {integrity: sha512-RfqAvLnMl313r7c9oclB1HhUEAezcpLjz95wFH4LVuhk9JF/r22qmVP9AMmOU4vMX7Q8pN8jwNg/CSpdFnMjTQ==} - engines: {node: '>= 0.4'} - hasBin: true - rollup@4.54.0: resolution: {integrity: sha512-3nk8Y3a9Ea8szgKhinMlGMhGMw89mqule3KWczxhIzqudyHdCIOHw8WJlj/r329fACjKLEh13ZSk7oE22kyeIw==} engines: {node: '>=18.0.0', npm: '>=8.0.0'} @@ -430,10 +369,6 @@ packages: resolution: {integrity: sha512-UXWMKhLOwVKb728IUtQPXxfYU+usdybtUrK/8uGE8CQMvrhOpwvzDBwj0QhSL7MQc7vIsISBG8VQ8+IDQxpfQA==} engines: {node: '>=0.10.0'} - supports-preserve-symlinks-flag@1.0.0: - resolution: {integrity: sha512-ot0WnXS9fgdkgIcePe6RHNk1WA8+muPa6cSjeR3V8K27q9BB1rTE3R1p7Hv0z1ZyAc8s6Vvv8DIyWf681MAt0w==} - engines: {node: '>= 0.4'} - tinyglobby@0.2.15: resolution: {integrity: sha512-j2Zq4NyQYG5XMST4cbs02Ak8iJUdxRM0XI5QyxXuZOzKOINmWurp3smXu3y5wDcJrptwpSjgXHzIQxR0omXljQ==} engines: {node: '>=12.0.0'} @@ -563,24 +498,6 @@ snapshots: '@kevisual/types@0.0.10': {} - '@rollup/plugin-node-resolve@16.0.3(rollup@4.54.0)': - dependencies: - '@rollup/pluginutils': 5.3.0(rollup@4.54.0) - '@types/resolve': 1.20.2 - deepmerge: 4.3.1 - is-module: 1.0.0 - resolve: 1.22.11 - optionalDependencies: - rollup: 4.54.0 - - '@rollup/pluginutils@5.3.0(rollup@4.54.0)': - dependencies: - '@types/estree': 1.0.8 - estree-walker: 2.0.2 - picomatch: 4.0.3 - optionalDependencies: - rollup: 4.54.0 - '@rollup/rollup-android-arm-eabi@4.54.0': optional: true @@ -657,14 +574,10 @@ snapshots: dependencies: undici-types: 7.16.0 - '@types/resolve@1.20.2': {} - bun-types@1.3.4: dependencies: '@types/node': 25.0.2 - deepmerge@4.3.1: {} - dotenv@17.2.3: {} esbuild@0.27.2: @@ -696,8 +609,6 @@ snapshots: '@esbuild/win32-ia32': 0.27.2 '@esbuild/win32-x64': 0.27.2 - estree-walker@2.0.2: {} - fdir@6.5.0(picomatch@4.0.3): optionalDependencies: picomatch: 4.0.3 @@ -705,24 +616,8 @@ snapshots: fsevents@2.3.3: optional: true - function-bind@1.1.2: {} - - hasown@2.0.2: - dependencies: - function-bind: 1.1.2 - - is-core-module@2.16.1: - dependencies: - hasown: 2.0.2 - - is-module@1.0.0: {} - - lodash-es@4.17.22: {} - nanoid@3.3.11: {} - path-parse@1.0.7: {} - picocolors@1.1.1: {} picomatch@4.0.3: {} @@ -733,12 +628,6 @@ snapshots: picocolors: 1.1.1 source-map-js: 1.2.1 - resolve@1.22.11: - dependencies: - is-core-module: 2.16.1 - path-parse: 1.0.7 - supports-preserve-symlinks-flag: 1.0.0 - rollup@4.54.0: dependencies: '@types/estree': 1.0.8 @@ -769,8 +658,6 @@ snapshots: source-map-js@1.2.1: {} - supports-preserve-symlinks-flag@1.0.0: {} - tinyglobby@0.2.15: dependencies: fdir: 6.5.0(picomatch@4.0.3) diff --git a/src/build/index.ts b/src/build/index.ts new file mode 100644 index 0000000..f60455f --- /dev/null +++ b/src/build/index.ts @@ -0,0 +1,52 @@ +import { CNBCore, CNBCoreOptions, RequestOptions, Result } from "../cnb-core.ts"; + +type Options = CNBCoreOptions<{ + group?: string; +}> +export class Build extends CNBCore { + group: string; + constructor(options: Options) { + super({ token: options.token, cookie: options.cookie }); + this.group = options.group || ''; + } + startBuild(repo: string, data: StartBuildData): Promise { + const group = this.group || ''; + const url = `/${group}/${repo}/-/build/start`; + let postData: StartBuildData = { + ...data, + branch: data.branch || 'main', + }; + return this.post({ url, data: postData }); + } +} + +type StartBuildData = { + /** + * 触发分支,默认为主分支 + */ + branch?: string; + /** + * 指定配置文件内容,yaml 格式 + */ + config?: string; + /** + * 环境变量,对象格式 + */ + env?: Record; + /** + * 事件名,必须是 api_trigger 或以 api_trigger_ 开头,默认为 api_trigger + */ + event?: string; + /** + * commit id ,优先级比 tag 高,默认为分支最新提交记录 + */ + sha?: string; + /** + * 是否等待构建正式触发,为false时会立刻返回 sn 和 buildLogUrl + */ + sync?: string; + /** + * 触发 tag,优先级比 branch 高 + */ + tag?: string; +} \ No newline at end of file diff --git a/src/cnb-core.ts b/src/cnb-core.ts index c947e7a..7cfc497 100644 --- a/src/cnb-core.ts +++ b/src/cnb-core.ts @@ -1,5 +1,8 @@ export type CNBCoreOptions = { token: string; + /** + * 对 cnb 界面操作定制模块功能时需要传入 cookie + */ cookie?: string; } & T; diff --git a/src/index.ts b/src/index.ts index 810dc53..93c30aa 100644 --- a/src/index.ts +++ b/src/index.ts @@ -3,23 +3,29 @@ import { Workspace } from "./workspace.ts"; import { KnowledgeBase } from "./knowledge/index.ts"; import { Repo } from "./repo/index.ts"; import { User } from "./user/index.ts"; +import { Build } from "./build/index.ts"; -type CNBOptions = CNBCoreOptions<{}>; +type CNBOptions = CNBCoreOptions<{ + group?: string; +}>; export class CNB extends CNBCore { workspace!: Workspace; knowledgeBase!: KnowledgeBase; repo!: Repo; user!: User; + build!: Build; constructor(options: CNBOptions) { super({ token: options.token, cookie: options.cookie }); this.init(options); } init(options: CNBOptions) { this.workspace = new Workspace(options.token); - this.knowledgeBase = new KnowledgeBase({ token: options.token, cookie: options.cookie }); - this.repo = new Repo({ token: options.token, cookie: options.cookie }); + const group = options.group || ''; + this.knowledgeBase = new KnowledgeBase({ group: group, token: options.token, cookie: options.cookie }); + this.repo = new Repo({ group: group, token: options.token, cookie: options.cookie }); this.user = new User({ token: options.token, cookie: options.cookie }); + this.build = new Build({ group: group, token: options.token, cookie: options.cookie }); } } @@ -27,3 +33,5 @@ export * from './workspace.ts' export * from './cnb-core.ts' export * from './knowledge/index.ts' export * from './repo/index.ts' +export * from './user/index.ts' +export * from './build/index.ts' \ No newline at end of file diff --git a/test/build.ts b/test/build.ts new file mode 100644 index 0000000..6f051e4 --- /dev/null +++ b/test/build.ts @@ -0,0 +1,18 @@ +import { Build } from "../src/index.ts"; + +import { token, showMore, cookie } from "./common.ts"; + +const repo = new Build({ group: "kevisual", token: token, cookie: cookie }); + +const main = async () => { + const build = await repo.startBuild('cnb', { + branch: 'main', + env: { + }, + event: 'api_trigger_test', + config: ``, + }); + console.log("build", build); +} + +main() \ No newline at end of file