diff --git a/.gitea/workflows/salon-prod-deploy.yml b/.gitea/workflows/salon-prod-deploy.yml index 0d2ce642..edf960ac 100644 --- a/.gitea/workflows/salon-prod-deploy.yml +++ b/.gitea/workflows/salon-prod-deploy.yml @@ -35,6 +35,52 @@ jobs: git remote add origin "$GITHUB_SERVER_URL/$GITHUB_REPOSITORY.git" git -c http.extraheader="Authorization: token $GITEA_TOKEN" fetch --no-tags --depth=1 origin "$CHECKOUT_SHA" git checkout --detach "$CHECKOUT_SHA" + - name: 检查发布工具链 + shell: bash + run: | + set -euo pipefail + java -version 2>&1 | grep -q '17\.' + node --version | grep -q '^v20\.' + pwsh --version + - name: 下载已审核发布包 + shell: bash + env: + GITEA_TOKEN: ${{ secrets.GITHUB_TOKEN }} + PREPARE_RUN_ID: ${{ inputs.prepare_run_id }} + ARTIFACT_NAME: salon-prod-${{ inputs.release_sha }} + run: | + set -euo pipefail + test -n "$GITEA_TOKEN" + test -n "$PREPARE_RUN_ID" + test -n "$ARTIFACT_NAME" + api_base="$GITHUB_SERVER_URL/api/actions_pipeline/_apis/pipelines/workflows/$PREPARE_RUN_ID/artifacts?api-version=6.0-preview" + response_file="$RUNNER_TEMP/salon-prod-artifacts.json" + curl --fail-with-body --silent --show-error --retry 3 --retry-all-errors \ + -H "Authorization: Bearer $GITEA_TOKEN" "$api_base" > "$response_file" + artifact_id=$(node -e 'const fs=require("fs"); const name=process.argv[1]; const data=JSON.parse(fs.readFileSync(process.argv[2],"utf8")); const item=(data.value||[]).find(v=>v.name===name); if(!item||!item.fileContainerResourceUrl) process.exit(2); const m=item.fileContainerResourceUrl.match(/\\/(\\d+)\\/path$/); if(!m) process.exit(3); process.stdout.write(m[1]);' "$ARTIFACT_NAME" "$response_file") + path_url="$GITHUB_SERVER_URL/api/actions_pipeline/_apis/pipelines/workflows/$PREPARE_RUN_ID/artifacts/$artifact_id/path?api-version=6.0-preview" + curl --fail-with-body --silent --show-error --retry 3 --retry-all-errors \ + -H "Authorization: Bearer $GITEA_TOKEN" "$path_url" > "$RUNNER_TEMP/salon-prod-artifact-path.json" + mkdir -p artifacts/release + node - "$RUNNER_TEMP/salon-prod-artifact-path.json" "$GITHUB_SERVER_URL" "$PREPARE_RUN_ID" "$artifact_id" "$GITEA_TOKEN" <<'NODE' + const fs = require('fs'); + const { execFileSync } = require('child_process'); + const [pathFile, server, runId, artifactId, token] = process.argv.slice(2); + const data = JSON.parse(fs.readFileSync(pathFile, 'utf8')); + const files = data.value || []; + if (files.length === 0) throw new Error('Artifact 未返回任何文件'); + for (const file of files) { + if (!file.contentLocation || !file.path) throw new Error('Artifact 文件项缺少下载地址或路径'); + const relativePath = file.path.split('/').slice(1).join('/'); + if (!relativePath || relativePath.includes('..')) throw new Error(`非法 Artifact 路径: ${file.path}`); + const output = `artifacts/release/${relativePath}`; + fs.mkdirSync(require('path').dirname(output), { recursive: true }); + execFileSync('curl', ['--fail-with-body', '--silent', '--show-error', '--retry', '3', '--retry-all-errors', '-H', `Authorization: Bearer ${token}`, `${server}${file.contentLocation}?itemPath=${encodeURIComponent(file.path)}`, '-o', output], { stdio: 'inherit' }); + } + NODE + test -f artifacts/release/manifest.json + test -f artifacts/release/backend/JC-Salon-Core.jar || find artifacts/release -name 'JC-Salon-Core.jar' -exec cp {} artifacts/release/backend/JC-Salon-Core.jar \; + test -f artifacts/release/backend/JC-Salon-Gateway.jar || find artifacts/release -name 'JC-Salon-Gateway.jar' -exec cp {} artifacts/release/backend/JC-Salon-Gateway.jar \; - name: 发布并校验 Salon 生产 Nacos shell: bash env: @@ -46,21 +92,6 @@ jobs: NACOS_DR_USERNAME: ${{ secrets.NACOS_DR_USERNAME }} NACOS_DR_PASSWORD: ${{ secrets.NACOS_DR_PASSWORD }} run: node .gitea/scripts/publish-nacos.mjs - - name: 检查发布工具链 - shell: bash - run: | - set -euo pipefail - java -version 2>&1 | grep -q '17\.' - node --version | grep -q '^v20\.' - pwsh --version - - name: 下载已审核发布包 - uses: actions/download-artifact@v3 - with: - name: salon-prod-${{ inputs.release_sha }} - path: artifacts/release - repository: ${{ github.repository }} - run-id: ${{ inputs.prepare_run_id }} - github-token: ${{ secrets.GITHUB_TOKEN }} - name: 写入临时 SSH 配置和目标清单 shell: bash env: diff --git a/docs/scripts/生产Salon Gitea流水线配置说明_20260827.md b/docs/scripts/生产Salon Gitea流水线配置说明_20260827.md index 49006394..a0085c6a 100644 --- a/docs/scripts/生产Salon Gitea流水线配置说明_20260827.md +++ b/docs/scripts/生产Salon Gitea流水线配置说明_20260827.md @@ -4,6 +4,7 @@ - `.gitea/workflows/salon-prod-prepare.yml`:仅在 `sit` 来源的 PR 合并到 `prod` 后自动运行,构建后端、前端和 SQL 归档并上传 Artifact,不修改生产环境。 - `.gitea/workflows/salon-prod-deploy.yml`:仅支持手工运行,填写准备工作流运行 ID 和合并提交 SHA 后,下载对应 Artifact 并执行生产发布。 +- 发布工作流通过 Gitea Actions Artifact 原生接口下载准备产物,不使用 GitHub 专用的 `actions/download-artifact` 跨运行接口;下载并校验成功后才发布生产 Nacos 配置。 - 两个 Salon 工作流使用内网 Gitea API 直接拉取提交,不依赖 `actions/checkout` 的 GitHub 外部仓库;Runner 需能访问 `http://192.168.5.15:3000`。 ## prod 分支保护