From fc0b363a3386b8ce883498af479d470b7e529b3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=20=E7=9B=B8=E5=8D=BF?= Date: Fri, 30 Jan 2026 13:23:51 +0800 Subject: [PATCH] chore: gitea actions --- .gitea/actions/get-version/action.yaml | 60 +++++++++ .gitea/actions/wecom-notification/action.yaml | 124 ++++++++++++++++++ .gitea/workflows/deploy-dev.yaml | 58 ++++++++ apps/web/vite.config.ts | 2 +- packages/core/src/App.vue | 5 +- packages/core/src/layout/online-layout.vue | 3 + packages/core/src/layout/stand-alone.vue | 0 packages/core/src/router/index.ts | 4 +- .../src/views/{Home.vue => index copy.vue} | 0 packages/core/src/views/index.vue | 95 ++++++++++++++ packages/core/src/views/online/index.vue | 3 + 11 files changed, 347 insertions(+), 7 deletions(-) create mode 100644 .gitea/actions/get-version/action.yaml create mode 100644 .gitea/actions/wecom-notification/action.yaml create mode 100644 .gitea/workflows/deploy-dev.yaml create mode 100644 packages/core/src/layout/online-layout.vue create mode 100644 packages/core/src/layout/stand-alone.vue rename packages/core/src/views/{Home.vue => index copy.vue} (100%) create mode 100644 packages/core/src/views/index.vue create mode 100644 packages/core/src/views/online/index.vue diff --git a/.gitea/actions/get-version/action.yaml b/.gitea/actions/get-version/action.yaml new file mode 100644 index 0000000..263188c --- /dev/null +++ b/.gitea/actions/get-version/action.yaml @@ -0,0 +1,60 @@ +name: Get Version +description: 从 package.json 读取版本号,与最新 tag 对比决定使用哪个版本 + +outputs: + version: + description: 最终确定的版本号 (带 v 前缀) + value: ${{ steps.get_version.outputs.version }} + +runs: + using: composite + steps: + - name: Get version from package.json + id: get_version + shell: bash + run: | + PKG_VERSION=$(node -p "require('./package.json').version") + echo "Package.json version: ${PKG_VERSION}" + + # 获取最新的tag(按版本号排序) + LATEST_TAG=$(git ls-remote --tags origin 'refs/tags/v*' 2>/dev/null | sed 's/.*refs\/tags\///' | sed 's/\^{}//' | sort -V | tail -n 1 || echo "") + echo "Latest tag: ${LATEST_TAG}" + + # 版本比较函数 + version_compare() { + # 返回: 0 = 相等, 1 = v1 > v2, 2 = v1 < v2 + if [[ "$1" == "$2" ]]; then echo 0; return; fi + local IFS=. + local i v1=($1) v2=($2) + for ((i=0; i<${#v1[@]} || i<${#v2[@]}; i++)); do + local n1=${v1[i]:-0} n2=${v2[i]:-0} + if ((n1 > n2)); then echo 1; return; fi + if ((n1 < n2)); then echo 2; return; fi + done + echo 0 + } + + if [[ -z "${LATEST_TAG}" ]]; then + # 没有任何tag,直接使用package.json版本 + NEW_TAG="v${PKG_VERSION}" + echo "No existing tags, using package.json version: ${NEW_TAG}" + else + # 去掉v前缀进行比较 + LATEST_VERSION="${LATEST_TAG#v}" + COMPARE_RESULT=$(version_compare "${PKG_VERSION}" "${LATEST_VERSION}") + + if [[ "${COMPARE_RESULT}" == "1" ]]; then + # package.json版本更大,使用它 + NEW_TAG="v${PKG_VERSION}" + echo "Package.json version is greater, using: ${NEW_TAG}" + else + # 最新tag版本更大或相等,在其基础上递增patch + IFS='.' read -r MAJOR MINOR PATCH <<< "${LATEST_VERSION}" + PATCH=$((PATCH + 1)) + NEW_TAG="v${MAJOR}.${MINOR}.${PATCH}" + echo "Incrementing from latest tag, new version: ${NEW_TAG}" + fi + fi + + echo "version=${NEW_TAG}" >> $GITHUB_OUTPUT + echo "Final Version: ${NEW_TAG}" diff --git a/.gitea/actions/wecom-notification/action.yaml b/.gitea/actions/wecom-notification/action.yaml new file mode 100644 index 0000000..f4d1b55 --- /dev/null +++ b/.gitea/actions/wecom-notification/action.yaml @@ -0,0 +1,124 @@ +name: WeChat Work Notification +description: 发送企业微信群机器人通知 +author: Your Team + +inputs: + webhook_url: + description: 企业微信群机器人 Webhook URL + required: true + status: + description: 构建状态 (success/failure/cancelled) + required: true + default: success + title: + description: 通知标题 + required: true + repository: + description: 仓库名称 + required: false + default: ${{ github.repository }} + branch: + description: 分支名称 + required: false + default: '' + version: + description: 版本号 + required: false + default: '' + actor: + description: 构建触发人 + required: false + default: ${{ github.actor }} + run_number: + description: 运行序号 + required: false + default: ${{ github.run_number }} + run_url: + description: 运行详情 URL + required: false + default: '' + failed_step: + description: 失败的步骤名称 + required: false + default: '' + extra_content: + description: 额外的通知内容 (markdown 格式) + required: false + default: '' + +runs: + using: composite + steps: + - name: Send WeChat Work Notification + shell: bash + run: | + # 设置状态图标和文本 + if [ "${{ inputs.status }}" = "success" ]; then + STATUS_ICON="✅" + STATUS_TEXT="成功" + elif [ "${{ inputs.status }}" = "cancelled" ]; then + STATUS_ICON="⚠️" + STATUS_TEXT="已取消" + else + STATUS_ICON="❌" + STATUS_TEXT="失败" + fi + + # 构建通知内容 + CONTENT="## ${STATUS_ICON} ${{ inputs.title }} ${STATUS_TEXT}" + + # 添加仓库信息 + if [ -n "${{ inputs.repository }}" ]; then + CONTENT="${CONTENT}\n> **仓库**: ${{ inputs.repository }}" + fi + + # 添加分支信息 + if [ -n "${{ inputs.branch }}" ]; then + CONTENT="${CONTENT}\n> **分支**: ${{ inputs.branch }}" + fi + + # 添加版本信息 + if [ -n "${{ inputs.version }}" ]; then + CONTENT="${CONTENT}\n> **版本**: ${{ inputs.version }}" + fi + + # 添加构建人 + if [ -n "${{ inputs.actor }}" ]; then + CONTENT="${CONTENT}\n> **构建人**: ${{ inputs.actor }}" + fi + + # 添加运行序号 + if [ -n "${{ inputs.run_number }}" ]; then + CONTENT="${CONTENT}\n> **运行序号**: #${{ inputs.run_number }}" + fi + + # 添加失败步骤信息 + if [ -n "${{ inputs.failed_step }}" ]; then + CONTENT="${CONTENT}\n> **失败步骤**: ${{ inputs.failed_step }}" + fi + + # 添加额外内容 + if [ -n "${{ inputs.extra_content }}" ]; then + CONTENT="${CONTENT}\n> ${{ inputs.extra_content }}" + fi + + # 添加查看详情链接 + if [ -n "${{ inputs.run_url }}" ]; then + CONTENT="${CONTENT}\n> [查看详情](${{ inputs.run_url }})" + fi + + echo "========== 企业微信通知 ==========" + echo "状态: ${STATUS_ICON} ${STATUS_TEXT}" + echo "标题: ${{ inputs.title }}" + echo "Webhook URL: ${{ inputs.webhook_url }}" + echo "==================================" + + # 发送通知 + curl -s -X POST "${{ inputs.webhook_url }}" \ + -H "Content-Type: application/json" \ + -d "{ + \"msgtype\": \"markdown\", + \"markdown\": { + \"content\": \"${CONTENT}\" + } + }" diff --git a/.gitea/workflows/deploy-dev.yaml b/.gitea/workflows/deploy-dev.yaml new file mode 100644 index 0000000..dd1d47f --- /dev/null +++ b/.gitea/workflows/deploy-dev.yaml @@ -0,0 +1,58 @@ +name: Deploy Dev + +on: + workflow_dispatch: + inputs: + # 分支 + target_branch: + description: 请输入要发布的分支名称 + required: true + default: dev + type: string + +jobs: + build-and-deploy: + runs-on: node-22 + + steps: + - uses: https://gitee.com/youtellme/checkout@v4 + with: + ref: ${{ inputs.target_branch }} + fetch-depth: 1 + + - name: Setup pnpm + id: setup_pnpm + uses: https://gitee.com/youtellme/pnpm-action-setup@v4 + with: + version: 9 + + - name: Install dependencies + id: install + run: | + rm -rf pnpm-lock.yaml node_modules + pnpm install + + - run: pnpm run build:web + + # 压缩 dist 文件夹 + - name: zip dist folder + run: | + TIMESTAMP=$(date +%Y%m%d%H%M%S) + BRANCH_NAME="${{ inputs.target_branch }}" + SAFE_BRANCH_NAME="${BRANCH_NAME//\//_}" + mkdir -p zip-output + zip -r -q zip-output/cslab-dcs-web_${SAFE_BRANCH_NAME}_${TIMESTAMP}.zip apps/web/dist/ + ls -lh zip-output/ + + # 上传 zip 文件到 RustFS + - name: Upload zip to RustFS (S3) + uses: jakejarvis/s3-sync-action@master + with: + args: --acl public-read + env: + AWS_S3_BUCKET: ${{ vars.RUSTFS_AWS_S3_BUCKET }} + AWS_ACCESS_KEY_ID: ${{ vars.RUSTFS_ACCESS_KEY }} + AWS_SECRET_ACCESS_KEY: ${{ vars.RUSTFS_SECRET_KEY }} + AWS_REGION: us-east-1 + AWS_S3_ENDPOINT: ${{ vars.RUSTFS_AWS_S3_ENDPOINT }} + SOURCE_DIR: zip-output diff --git a/apps/web/vite.config.ts b/apps/web/vite.config.ts index 2572c65..420a93e 100644 --- a/apps/web/vite.config.ts +++ b/apps/web/vite.config.ts @@ -8,7 +8,7 @@ const coreRoot = resolve(__dirname, '../../packages/core') export default defineConfig({ ...createSharedViteConfig(coreRoot), root: __dirname, - base: './', // 确保相对路径,方便部署 + base: '/dcs-web/', // 确保相对路径,方便部署 build: { outDir: 'dist', emptyOutDir: true, diff --git a/packages/core/src/App.vue b/packages/core/src/App.vue index 2516844..a12f8db 100644 --- a/packages/core/src/App.vue +++ b/packages/core/src/App.vue @@ -1,12 +1,9 @@ diff --git a/packages/core/src/layout/online-layout.vue b/packages/core/src/layout/online-layout.vue new file mode 100644 index 0000000..c4e75c7 --- /dev/null +++ b/packages/core/src/layout/online-layout.vue @@ -0,0 +1,3 @@ + diff --git a/packages/core/src/layout/stand-alone.vue b/packages/core/src/layout/stand-alone.vue new file mode 100644 index 0000000..e69de29 diff --git a/packages/core/src/router/index.ts b/packages/core/src/router/index.ts index f505334..3b8a13c 100644 --- a/packages/core/src/router/index.ts +++ b/packages/core/src/router/index.ts @@ -5,14 +5,14 @@ const routes: RouteRecordRaw[] = [ { path: '/', name: 'Home', - component: () => import('../views/Home.vue'), + component: () => import('../views/index.vue'), meta: { title: '首页' }, }, // 可以添加更多路由 ] const router = createRouter({ - history: createWebHashHistory(), // 使用 Hash 模式兼容 Electron + history: createWebHashHistory('/dcs-web'), // 使用 Hash 模式兼容 Electron routes, }) diff --git a/packages/core/src/views/Home.vue b/packages/core/src/views/index copy.vue similarity index 100% rename from packages/core/src/views/Home.vue rename to packages/core/src/views/index copy.vue diff --git a/packages/core/src/views/index.vue b/packages/core/src/views/index.vue new file mode 100644 index 0000000..e331ea4 --- /dev/null +++ b/packages/core/src/views/index.vue @@ -0,0 +1,95 @@ + + + + + diff --git a/packages/core/src/views/online/index.vue b/packages/core/src/views/online/index.vue new file mode 100644 index 0000000..c4e75c7 --- /dev/null +++ b/packages/core/src/views/online/index.vue @@ -0,0 +1,3 @@ +