From 13ddc979ec7953e3db8db76dd23fd85a3b3c7997 Mon Sep 17 00:00:00 2001 From: xiaojunnuo Date: Mon, 29 Dec 2025 14:21:25 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E4=BC=98=E5=8C=96=E6=BA=90=E7=A0=81?= =?UTF-8?q?=E6=96=B9=E5=BC=8F=E9=83=A8=E7=BD=B2=EF=BC=8C=E5=89=8D=E7=AB=AF?= =?UTF-8?q?=E6=97=A0=E9=9C=80=E7=BC=96=E8=AF=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/publish-atom.yaml | 56 ++++++ .github/workflows/release-image.yml | 2 +- .npmrc | 2 +- package.json | 8 +- .../src/locales/langs/zh-CN/vip.ts | 2 +- deploy.js => scripts/deploy.js | 2 +- scripts/publish-atomgit.js | 181 ++++++++++++++++++ publish-check.js => scripts/publish-check.js | 0 scripts/version.js | 3 + start.sh | 32 +++- trigger/publish.trigger | 1 + 11 files changed, 273 insertions(+), 16 deletions(-) create mode 100644 .github/workflows/publish-atom.yaml rename deploy.js => scripts/deploy.js (96%) create mode 100644 scripts/publish-atomgit.js rename publish-check.js => scripts/publish-check.js (100%) create mode 100644 scripts/version.js create mode 100644 trigger/publish.trigger diff --git a/.github/workflows/publish-atom.yaml b/.github/workflows/publish-atom.yaml new file mode 100644 index 000000000..4e3100982 --- /dev/null +++ b/.github/workflows/publish-atom.yaml @@ -0,0 +1,56 @@ +name: publish-atomgit +on: + push: + branches: ['v2-dev'] + paths: + - "trigger/publish.trigger" +# workflow_run: +# workflows: [ "deploy-demo" ] +# types: +# - completed + +# schedule: +# - # 国际时间 19:17 执行,北京时间3:17 ↙↙↙ 改成你想要每天自动执行的时间 +# - cron: '17 19 * * *' +permissions: + contents: read + packages: write + +jobs: + publish-atomgit: + runs-on: ubuntu-latest + steps: + - name: Checkout Code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + lfs: true + + - name: get_certd_version + id: get_certd_version + uses: actions/github-script@v6 + with: + result-encoding: string + script: | + const fs = require('fs'); + const path = require('path'); + const pnpmWorkspace = "./pnpm-workspace.yaml"; + fs.unlinkSync(pnpmWorkspace) + const jsonFilePath = "./packages/ui/certd-server/package.json"; + const jsonContent = fs.readFileSync(jsonFilePath, 'utf-8'); + const pkg = JSON.parse(jsonContent) + console.log("certd_version:",pkg.version); + return pkg.version + + - name: zip_front + id: zip_front + run: | + rm -rf ./packages/ui/certd-client/dist/**/*.gz + zip -r ui.zip ./packages/ui/certd-client/dist + + - name: publish_to_atomgit + id: publish_to_atomgit + run: | + export ATOMGIT_TOKEN=${{ secrets.ATOMGIT_TOKEN }} + npm run publish_to_atomgit + working-directory: ./ \ No newline at end of file diff --git a/.github/workflows/release-image.yml b/.github/workflows/release-image.yml index 7cc8ef9ed..8921ae33f 100644 --- a/.github/workflows/release-image.yml +++ b/.github/workflows/release-image.yml @@ -130,4 +130,4 @@ jobs: headers: | Content-Type: application/json retry-count: 3 - retry-delay: 5000 + retry-delay: 5000 \ No newline at end of file diff --git a/.npmrc b/.npmrc index f8f4e0af2..f1333798d 100644 --- a/.npmrc +++ b/.npmrc @@ -3,4 +3,4 @@ prefer-workspace-packages=true better_sqlite3_binary_host=https://registry.npmmirror.com/-/binary/better-sqlite3 better_sqlite3_binary_host_mirror=https://registry.npmmirror.com/-/binary/better-sqlite3 better-sqlite3_binary_host=https://registry.npmmirror.com/-/binary/better-sqlite3 -better-sqlite3_binary_host_mirror=https://registry.npmmirror.com/-/binary/better-sqlite3 +better-sqlite3_binary_host_mirror=https://registry.npmmirror.com/-/binary/better-sqlite3 \ No newline at end of file diff --git a/package.json b/package.json index eb4a5bbd5..744cd5095 100644 --- a/package.json +++ b/package.json @@ -27,8 +27,8 @@ "prepublishOnly1": "npm run check && lerna run build ", "prepublishOnly2": "npm run check && npm run before-build && lerna run build ", "before-build": "npm run transform-sql && cd ./packages/core/basic && time /t >build.md && git add ./build.md && git commit -m \"build: prepare to build\"", - "deploy1": "node --experimental-json-modules deploy.js ", - "check": "node --experimental-json-modules publish-check.js", + "deploy1": "node --experimental-json-modules ./scripts/deploy.js ", + "check": "node --experimental-json-modules ./scripts/publish-check.js", "init": "lerna run build", "init:dev": "lerna run build", "docs:dev": "vitepress dev docs", @@ -36,7 +36,9 @@ "docs:preview": "vitepress preview docs", "pub": "echo 1", "dev": "pnpm run -r --parallel compile ", - "release": "time /t >trigger/release.trigger && git add trigger/release.trigger && git commit -m \"build: release\" && git push" + "release": "time /t >trigger/release.trigger && git add trigger/release.trigger && git commit -m \"build: release\" && git push", + "publish_to_atomgit": "node --experimental-json-modules ./scripts/publish-atomgit.js", + "get_version": "node --experimental-json-modules ./scripts/version.js" }, "license": "AGPL-3.0", "dependencies": { diff --git a/packages/ui/certd-client/src/locales/langs/zh-CN/vip.ts b/packages/ui/certd-client/src/locales/langs/zh-CN/vip.ts index ae61846fb..b3c6032d8 100644 --- a/packages/ui/certd-client/src/locales/langs/zh-CN/vip.ts +++ b/packages/ui/certd-client/src/locales/langs/zh-CN/vip.ts @@ -59,7 +59,7 @@ export default { vip_group_priority: "可加VIP群,您的需求将优先实现", unlimited_site_certificate_monitoring: "站点证书监控无限制", more_notification_methods: "更多通知方式", - plugins_fully_open: "插件全开放,群辉等更多插件", + plugins_fully_open: "插件全开放,群晖等更多插件", click_to_get_7_day_trial: "点击获取7天试用", years: "年", afdian_support_vip: "新用户开通永久专业版立享50优惠券", diff --git a/deploy.js b/scripts/deploy.js similarity index 96% rename from deploy.js rename to scripts/deploy.js index f917384f6..4c10e9bd7 100644 --- a/deploy.js +++ b/scripts/deploy.js @@ -1,7 +1,7 @@ import http from 'axios' import fs from 'fs' //读取 packages/core/pipline/package.json的版本号 -import {default as packageJson} from './packages/core/pipeline/package.json' assert { type: "json" }; +import {default as packageJson} from '../packages/core/pipeline/package.json' assert { type: "json" }; const certdVersion = packageJson.version console.log("certdVersion", certdVersion) diff --git a/scripts/publish-atomgit.js b/scripts/publish-atomgit.js new file mode 100644 index 000000000..70760b659 --- /dev/null +++ b/scripts/publish-atomgit.js @@ -0,0 +1,181 @@ +import fs from 'fs' +import axios from 'axios' + + +const AtomgitAccessToken = process.env.ATOMGIT_TOKEN +// CHANGELOG.md +const changelog = fs.readFileSync('./CHANGELOG.md', 'utf8') +// 解析CHANGELOG.md +let lines = changelog.split('\n') +const versionLineIndex = lines.findIndex(line => line.startsWith('## ')) +const versionLine = lines[versionLineIndex] +// ## [1.37.16](https://github.com/certd/certd/compare/v1.37.15...v1.37.16) (2025-12-15) +const versionTitle = versionLine.match(/\[(.*?)\]/)[1] + +const contentStart = versionLineIndex + 1 +lines = lines.slice(contentStart) +const contentEnd = lines.findIndex(line => { + return line.startsWith('## ') +}) +const content = lines.slice(0, contentEnd).join('\n') +console.log("-------title------/n") +console.log(versionTitle) +console.log("-------content------/n") +console.log(content) + +/** + * 创建仓库Release +POST +https://api.atomgit.com/api/v5/repos/:owner/:repo/releases +Request +Path Parameters +owner +string +required +仓库所属空间地址(企业、组织或个人的地址path) + +repo +string +required +仓库路径 + +Query Parameters +access_token +string +required +用户授权码 + +application/json +Body +tag_name +string +required +tag名称 + +name +string +required +release名称 + +body +string +required +release描述 + +target_commitish +string +分支名称或者commit SHA,如果tag不存在,需要新建tag则传入该参数,如果不传入该参数,则为默认分支的最新提交 + */ + +// 创建release +async function createRelease() { + const response = await axios.request({ + method: 'POST', + url: `https://api.atomgit.com/api/v5/repos/certd/certd/releases`, + headers: { + "Content-Type": "application/json" + }, + params: { + access_token: AtomgitAccessToken + }, + data: { + tag_name: `v${versionTitle}`, + name: `v${versionTitle}`, + body: content, + target_commitish: 'v2' + }, + } + ) + console.log("createRelease success") + return response.data +} + +/** + * 获取Release附件上传地址 +GET +https://api.atomgit.com/api/v5/repos/:owner/:repo/releases/:tag/upload_url +Request +Path Parameters +owner +string +required +仓库所属空间地址(企业、组织或个人的地址path) + +repo +string +required +仓库路径 + +tag +string +required +tag名称 + +Query Parameters +access_token +string +required +用户授权码 + +file_name +string +required +要上传的文件名称 + +Responses +200 +Response Headers +application/json +Schema +Example (auto) +Schema +url +string +required +上传的地址,使用put请求 + +headers +object + + */ +async function getUploadUrl() { + const response = await axios.request({ + method: 'GET', + url: `https://api.atomgit.com/api/v5/repos/certd/certd/releases/v${versionTitle}/upload_url`, + headers: { + "Content-Type": "application/json" + }, + params: { + access_token: AtomgitAccessToken, + file_name: `ui-${versionTitle}.zip` + }, + } + ) + console.log("getUploadUrl success:",response.data?.url) + return response.data // {url: string, headers: any} +} + +async function uploadFile(url, headers, data) { + const response = await axios.request({ + method: 'PUT', + url, + headers, + data, + } + ) + return response.data +} + +async function publishToAtomgit() { + const release = await createRelease() + const uploadUrl = await getUploadUrl() + const fileName = `ui.zip` + const fileData = fs.createReadStream(fileName) + const contentLength = fs.statSync(fileName).size + uploadUrl.headers['Content-Length'] = contentLength + const response = await uploadFile(uploadUrl.url, uploadUrl.headers, fileData) + console.log("uploadFile success:") + console.log("publishToAtomgit success") +} + +publishToAtomgit() \ No newline at end of file diff --git a/publish-check.js b/scripts/publish-check.js similarity index 100% rename from publish-check.js rename to scripts/publish-check.js diff --git a/scripts/version.js b/scripts/version.js new file mode 100644 index 000000000..86b95d54c --- /dev/null +++ b/scripts/version.js @@ -0,0 +1,3 @@ +import fs from 'fs' +const pkg = JSON.parse(fs.readFileSync('./packages/ui/certd-server/package.json')) +console.log(pkg.version) diff --git a/start.sh b/start.sh index 113bb86cd..4c3ad6695 100755 --- a/start.sh +++ b/start.sh @@ -18,10 +18,10 @@ fi # fi # find ./packages -mindepth 1 -maxdepth 1 -type d ! -name 'ui' -exec rm -rf {} + # echo "删除成功" - +echo "修改 pnpm-workspace.yaml" cat > pnpm-workspace.yaml << EOF packages: - - 'packages/ui/**' + - 'packages/ui/certd-server' EOF @@ -43,17 +43,31 @@ $SUDO_CMD npm install -g pnpm --registry https://registry.npmmirror.com echo "安装依赖" $SUDO_CMD pnpm install --registry https://registry.npmmirror.com -echo "开始构建" -echo "构建certd-client" -export NODE_OPTIONS=--max-old-space-size=32768 -cd packages/ui/certd-client -$SUDO_CMD_E pnpm run build -cp -r dist/* ../certd-server/public +# 获取版本号 +version=$(node --experimental-json-modules ./scripts/version.js) +echo "当前版本号为: $version" + +echo "开始构建" +cd packages/ui/certd-server echo "构建certd-server" -cd ../certd-server $SUDO_CMD_E pnpm run build echo "构建完成" + + +echo "下载前端ui" +# 如果zip有了就不下载 +if [ -f ui-$version.zip ]; then + echo "ui-$version.zip 已经存在,不需要下载" +else + # 下载之前清理一下 + rm -rf ui-*.zip + # https://atomgit.com/certd/certd/releases/download/v1.37.16/ui-1.37.16.zip + # 判断是否下载失败 + wget https://atomgit.com/certd/certd/releases/download/v$version/ui-$version.zip +# 覆盖解压缩 +unzip -o ui-$version.zip -d ./public + echo "启动服务" # 前台运行 diff --git a/trigger/publish.trigger b/trigger/publish.trigger new file mode 100644 index 000000000..b8626c4cf --- /dev/null +++ b/trigger/publish.trigger @@ -0,0 +1 @@ +4