From ce90f46504f559e231b1ecba4ea81a59e7f9c9e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=A5=E6=B5=A9?= Date: Tue, 9 Sep 2025 14:14:23 +0800 Subject: [PATCH] =?UTF-8?q?ci:=20=E5=88=9D=E5=A7=8B=E5=8C=96=20CI/CD=20?= =?UTF-8?q?=E6=B5=81=E6=B0=B4=E7=BA=BF=E5=B9=B6=E8=BF=9B=E8=A1=8C=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .dev.vars.example | 3 ++ .env | 2 + .github/workflows/ci-cd.yaml | 75 ++++++++++++++++++++++++++++++++++++ .gitignore | 4 +- index.html | 2 +- package.json | 3 +- worker-configuration.d.ts | 4 +- wrangler.jsonc | 1 + 8 files changed, 88 insertions(+), 6 deletions(-) create mode 100644 .dev.vars.example create mode 100644 .env create mode 100644 .github/workflows/ci-cd.yaml diff --git a/.dev.vars.example b/.dev.vars.example new file mode 100644 index 0000000..3adeeff --- /dev/null +++ b/.dev.vars.example @@ -0,0 +1,3 @@ +# Wrangler 开发环境配置示例文件 +# 复制此文件为 .dev.vars 并填入实际的环境变量值 +# 该文件用于本地开发时的环境变量设置 diff --git a/.env b/.env new file mode 100644 index 0000000..d636bca --- /dev/null +++ b/.env @@ -0,0 +1,2 @@ +VITE_BUILD_COMMIT= +VITE_BUILD_TIME= diff --git a/.github/workflows/ci-cd.yaml b/.github/workflows/ci-cd.yaml new file mode 100644 index 0000000..b18464c --- /dev/null +++ b/.github/workflows/ci-cd.yaml @@ -0,0 +1,75 @@ +name: CI/CD Pipeline + +defaults: + run: + shell: bash + +env: + TZ: Asia/Shanghai + +on: + push: + workflow_dispatch: + +jobs: + lint-build-and-typecheck: + runs-on: ubuntu-latest + container: gitea/runner-images:ubuntu-latest-slim # https://github.com/cloudflare/wrangler-action/issues/329#issuecomment-3046747722 + + steps: + - name: 🛠️ 设置Node环境 + uses: yanhao98/composite-actions/setup-node-environment@41ff2ce04aed748954bd860668b69edd103bba2c + + - name: 🔍 静态代码分析 + run: pnpm run lint + + - name: 📦 构建项目 + run: pnpm run build-only + env: + VITE_BUILD_COMMIT: ${{ github.sha }} + + - name: 📊 计算构建大小 + run: | + echo "📊 构建大小统计:" + echo "----------------------------------------" + echo "🔹 人类可读格式: $(du -sh dist | cut -f1)" + echo "🔹 以MB为单位: $(du -sm dist | cut -f1) MB" + echo "🔹 以KB为单位: $(du -sk dist | cut -f1) KB" + echo "🔹 文件总数: $(find dist -type f | wc -l) 个文件" + echo "----------------------------------------" + + - name: ✅ 类型检查 + run: pnpm run type-check # 要先 build,保证 components.d.ts 存在 + + deploy: + runs-on: ubuntu-latest + needs: lint-build-and-typecheck + if: github.ref == 'refs/heads/main' + + # https://github.com/cloudflare/wrangler-action/issues/329#issuecomment-3046747722 + container: + image: gitea/runner-images:ubuntu-latest-slim + + steps: + - name: 🛠️ 设置Node环境 + uses: yanhao98/composite-actions/setup-node-environment@41ff2ce04aed748954bd860668b69edd103bba2c + + - name: 📦 构建项目 + run: pnpm run build-only + env: + VITE_BUILD_COMMIT: ${{ github.sha }} + + # - name: 🚀 上传版本到 Cloudflare + # uses: cloudflare/wrangler-action@v3 + # id: upload + # with: + # apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} + # accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} + # command: versions upload --tag "${{ github.sha }}" --message "Deploy commit ${{ github.sha }} from ${{ github.ref_name }}" + + - name: 🚀 部署到 Cloudflare + uses: cloudflare/wrangler-action@v3 + with: + apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} + accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} + command: deploy diff --git a/.gitignore b/.gitignore index 4ab4658..4aa2c46 100644 --- a/.gitignore +++ b/.gitignore @@ -34,5 +34,5 @@ playwright-report/ .wrangler .dev.vars* !.dev.vars.example -.env* -!.env.example +# .env* +# !.env.example diff --git a/index.html b/index.html index 9d30802..08f2576 100644 --- a/index.html +++ b/index.html @@ -1,5 +1,5 @@ - + diff --git a/package.json b/package.json index c6e4b34..550ac9d 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,8 @@ "-wrangler:pages:deploy:prod": "wrangler pages deploy dist --project-name=vue-ts-example-2025", "-deploy:preview": "run-s build-only wrangler:pages:deploy:preview", "-deploy:prod": "run-s build-only wrangler:pages:deploy:prod", - "deploy": "pnpm run build && wrangler deploy", + "wrangler:deploy": "pnpm run build && wrangler deploy", + "wrangler:versions:upload": "pnpm run build && wrangler versions upload", "cf-typegen": "wrangler types" }, "dependencies": { diff --git a/worker-configuration.d.ts b/worker-configuration.d.ts index ff4cbd0..50110b8 100644 --- a/worker-configuration.d.ts +++ b/worker-configuration.d.ts @@ -5440,7 +5440,7 @@ type AIGatewayHeaders = { [key: string]: string | number | boolean | object; }; type AIGatewayUniversalRequest = { - provider: AIGatewayProviders | string; // eslint-disable-line + provider: AIGatewayProviders | string; endpoint: string; headers: Partial; query: unknown; @@ -5456,7 +5456,7 @@ declare abstract class AiGateway { gateway?: UniversalGatewayOptions; extraHeaders?: object; }): Promise; - getUrl(provider?: AIGatewayProviders | string): Promise; // eslint-disable-line + getUrl(provider?: AIGatewayProviders | string): Promise; } interface AutoRAGInternalError extends Error { } diff --git a/wrangler.jsonc b/wrangler.jsonc index 651f33c..bb3293c 100644 --- a/wrangler.jsonc +++ b/wrangler.jsonc @@ -7,6 +7,7 @@ "name": "vue-ts-example-2025", "compatibility_date": "2025-09-09", "main": "server/index.ts", + "workers_dev": true, "assets": { "not_found_handling": "single-page-application", },