From bfc29ea2627835b8227c195595d45c340a6ee6cd Mon Sep 17 00:00:00 2001 From: cheney Date: Tue, 8 Sep 2026 10:58:16 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20cicd=EF=BC=9A=E6=9E=84?= =?UTF-8?q?=E5=BB=BA=E5=90=8E=E5=8F=91=E5=B8=83=20R2=20+=20website=20?= =?UTF-8?q?=E5=88=B0=20GitHub=EF=BC=8C=E5=AF=86=E9=92=A5=E8=B5=B0=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E4=B8=AD=E5=BF=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitea/workflows/ci.yaml | 166 +++++++++++++++++++++++++++++++-------- .gitignore | 1 + buildenv/Dockerfile | 17 ++-- kit/package.json | 3 +- meta.json | 2 +- 5 files changed, 149 insertions(+), 40 deletions(-) diff --git a/.gitea/workflows/ci.yaml b/.gitea/workflows/ci.yaml index 0476d1d..6d9264c 100644 --- a/.gitea/workflows/ci.yaml +++ b/.gitea/workflows/ci.yaml @@ -1,12 +1,49 @@ -name: TDevOPsCICD +name: TDevOpsCICD on: [push] jobs: - build-image: + build-kit: runs-on: ubuntu-latest steps: - uses: https://gitea.com/actions/checkout@v4 + + - name: 从配置中心加载密钥 + env: + CONFIG_CENTER_URL: ${{ secrets.CONFIG_CENTER_URL }} + CONFIG_CENTER_TOKEN: ${{ secrets.CONFIG_CENTER_TOKEN }} + run: | + set -e + BASE_URL="${CONFIG_CENTER_URL:-http://bh.vps.honor3.com:8008}" + AUTH_ARGS=() + if [ -n "$CONFIG_CENTER_TOKEN" ]; then + AUTH_ARGS=(-H "Authorization: Bearer ${CONFIG_CENTER_TOKEN}") + fi + curl -fsSL "${AUTH_ARGS[@]}" "$BASE_URL/api/projects" -o /tmp/cc-projects.json + node -e ' + const fs = require("fs"); + const projects = JSON.parse(fs.readFileSync("/tmp/cc-projects.json", "utf8")).data; + const proj = projects.find(p => p.name === "CommonExternalService"); + if (!proj) { console.error("project CommonExternalService not found"); process.exit(1); } + fs.writeFileSync("/tmp/cc-project-id", proj.id); + ' + PROJECT_ID=$(cat /tmp/cc-project-id) + curl -fsSL "${AUTH_ARGS[@]}" "$BASE_URL/api/projects/$PROJECT_ID/configs" -o /tmp/cc-configs.json + node -e ' + const fs = require("fs"); + const data = JSON.parse(fs.readFileSync("/tmp/cc-configs.json", "utf8")).data; + const allow = ["CF_API_TOKEN","CF_R2_PUBLIC_URL","CF_R2_BUCKET","GH_TOKEN","GH_OWNER","GH_REPO","GH_BRANCH"]; + const loaded = []; + for (const c of data) { + const key = String(c.key).split("/").pop(); + if (allow.includes(key) && c.value) { + fs.appendFileSync(process.env.GITHUB_ENV, `${key}=${c.value}\n`); + loaded.push(key); + } + } + console.log("loaded config keys:", loaded.join(", ")); + ' + - name: Setup Bun run: | curl -fsSL https://bun.sh/install | bash @@ -14,39 +51,106 @@ jobs: export PATH="$BUN_INSTALL/bin:$PATH" echo "BUN_INSTALL=$HOME/.bun" >> $GITHUB_ENV echo "$HOME/.bun/bin" >> $GITHUB_PATH - - name: Build Binary + + - name: Install pkg + run: npm i -g pkg + + - name: Install deps + run: | + cd kit + bun i + + - name: Build Windows (bun 交叉编译) + run: | + cd kit + bun run windows + ls -la ./dist/windows/ + + - name: Build Linux (bun, 现代 glibc) + run: | + cd kit + bun run linux + ls -la ./dist/linux/ + + - name: Build Linux (pkg, 低版本 glibc / Kylin V10) + 打包 zip + run: | + set -e + cd kit + # pkg 首次构建需要从 GitHub 下载 node14 基础运行时,网络不稳时重试 + for i in 1 2 3; do npm run pkg-linux && break || sleep 5; done + test -f ./dist/kylin/kit || { echo "pkg build failed"; exit 1; } + if ! command -v zip >/dev/null 2>&1; then + (apt-get update -qq && apt-get install -y -qq zip) >/dev/null 2>&1 || true + fi + command -v zip >/dev/null 2>&1 || { echo "zip not available"; exit 1; } + cd ./dist/kylin + zip -9 -j kit.zip kit + rm -f kit + ls -la . + + - name: 上传到 Gitea packages(存档) env: OBJECT_TOKEN: ${{ secrets.OBJECT_TOKEN }} GITEA_BASE_URL: http://git.honor3.com PACKAGE_OWNER: Fullstack REPO_NAME: kit.program - PACKAGE_NAME: kit PACKAGE_VERSION: ${{ github.ref_name }} run: | - set -e # 遇到错误立即退出 - echo ---------------------------------------- - echo "Branch/Tag: ${{ github.ref_name }}" - echo "Commit SHA: ${{ github.sha }}" - bun -v - cd kit - bun i - - echo "=== Building Windows ===" - bun run windows - ls -la ./dist/windows/ - - echo "=== Uploading Windows ===" - curl -v -X POST \ - -H "Authorization: token $OBJECT_TOKEN" \ - -F "data=@./dist/windows/kit.exe" \ - "$GITEA_BASE_URL/api/packages/$PACKAGE_OWNER/generic/$REPO_NAME/$PACKAGE_VERSION/kit.exe" - - echo "=== Building Linux ===" - bun run linux - ls -la ./dist/linux/ - - echo "=== Uploading Linux ===" - curl -v -X POST \ - -H "Authorization: token $OBJECT_TOKEN" \ - -F "data=@./dist/linux/kit" \ - "$GITEA_BASE_URL/api/packages/$PACKAGE_OWNER/generic/$REPO_NAME/$PACKAGE_VERSION/kit" + set -e + curl -fsSL -X POST -H "Authorization: token $OBJECT_TOKEN" \ + -F "data=@./kit/dist/windows/kit.exe" \ + "$GITEA_BASE_URL/api/packages/$PACKAGE_OWNER/generic/$REPO_NAME/$PACKAGE_VERSION/kit.exe" + curl -fsSL -X POST -H "Authorization: token $OBJECT_TOKEN" \ + -F "data=@./kit/dist/linux/kit" \ + "$GITEA_BASE_URL/api/packages/$PACKAGE_OWNER/generic/$REPO_NAME/$PACKAGE_VERSION/kit" + curl -fsSL -X POST -H "Authorization: token $OBJECT_TOKEN" \ + -F "data=@./kit/dist/kylin/kit.zip" \ + "$GITEA_BASE_URL/api/packages/$PACKAGE_OWNER/generic/$REPO_NAME/$PACKAGE_VERSION/kit-kylin.zip" + + - name: 上传二进制到 Cloudflare R2(公开桶) + run: | + set -e + test -n "$CF_API_TOKEN" || { echo "CF_API_TOKEN 未从配置中心加载"; exit 1; } + npm i -g wrangler + export CLOUDFLARE_API_TOKEN="$CF_API_TOKEN" + # 仅需 token,wrangler 会自动从 token 解析账号 ID,无需 CF_ACCOUNT_ID + BUCKET="${CF_R2_BUCKET:-store}" + wrangler r2 object put "$BUCKET/data/windows/kit.exe" --file ./kit/dist/windows/kit.exe --content-type application/octet-stream --remote + wrangler r2 object put "$BUCKET/data/linux/kit" --file ./kit/dist/linux/kit --content-type application/octet-stream --remote + wrangler r2 object put "$BUCKET/data/kylin/kit.zip" --file ./kit/dist/kylin/kit.zip --content-type application/zip --remote + + - name: 发布 website 到 GitHub(触发 Cloudflare Pages 自动部署) + env: + REF_NAME: ${{ github.ref_name }} + SHA: ${{ github.sha }} + run: | + set -e + test -n "$GH_TOKEN" || { echo "GH_TOKEN 未从配置中心加载"; exit 1; } + mkdir -p website/static/data + cat > website/static/data/kit.json <