name: Salon 生产发布 on: workflow_dispatch: inputs: prepare_run_id: description: 自动准备工作流的运行 ID required: true type: string release_sha: description: prod 合并提交 SHA required: true type: string jobs: deploy: runs-on: jayucloud env: GITHUB_SERVER_URL: http://192.168.5.15:3000 WEB_TARGET_HOST: ${{ secrets.SALON_PROD_WEB_HOST }} WEB_TARGET_PORT: ${{ secrets.SALON_PROD_WEB_PORT }} WEB_TARGET_USER: ${{ secrets.SALON_PROD_WEB_USER }} WEB_REMOTE_DIR: ${{ secrets.SALON_PROD_WEB_DIR }} steps: - name: 从内网 Gitea 检出发布脚本 shell: bash env: GITEA_TOKEN: ${{ secrets.GITHUB_TOKEN }} CHECKOUT_SHA: ${{ inputs.release_sha }} run: | set -euo pipefail test -n "$GITEA_TOKEN" test -n "$CHECKOUT_SHA" git init . 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.id) process.exit(2); process.stdout.write(String(item.id));' "$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: NACOS_ENVIRONMENT: prod-both NACOS_PROD_URLS: ${{ secrets.NACOS_PROD_URLS }} NACOS_PROD_USERNAME: ${{ secrets.NACOS_PROD_USERNAME }} NACOS_PROD_PASSWORD: ${{ secrets.NACOS_PROD_PASSWORD }} NACOS_DR_URLS: ${{ secrets.NACOS_DR_URLS }} NACOS_DR_USERNAME: ${{ secrets.NACOS_DR_USERNAME }} NACOS_DR_PASSWORD: ${{ secrets.NACOS_DR_PASSWORD }} run: node .gitea/scripts/publish-nacos.mjs - name: 写入临时 SSH 配置和目标清单 shell: bash env: SALON_PROD_SSH_PRIVATE_KEY: ${{ secrets.SALON_PROD_SSH_PRIVATE_KEY }} SALON_PROD_KNOWN_HOSTS: ${{ secrets.SALON_PROD_KNOWN_HOSTS }} run: | set -euo pipefail test -n "$SALON_PROD_SSH_PRIVATE_KEY" test -n "$SALON_PROD_KNOWN_HOSTS" test -n "$WEB_TARGET_HOST" test -n "$WEB_TARGET_PORT" test -n "$WEB_TARGET_USER" test -n "$WEB_REMOTE_DIR" mkdir -p "$RUNNER_TEMP/salon-prod" printf '%s\n' "$SALON_PROD_SSH_PRIVATE_KEY" > "$RUNNER_TEMP/salon-prod/id_ed25519" printf '%s\n' "$SALON_PROD_KNOWN_HOSTS" > "$RUNNER_TEMP/salon-prod/known_hosts" chmod 600 "$RUNNER_TEMP/salon-prod/id_ed25519" "$RUNNER_TEMP/salon-prod/known_hosts" cat > "$RUNNER_TEMP/salon-prod/servers.json" <- ./docs/scripts/deploy-jayucloud-salon-production.ps1 -Deploy -SkipDatabaseInit -RequireSystemd -PackageDirectory "artifacts/release" -ServerInfoJsonPath "$env:SERVER_INFO_JSON" -SshKeyPath "$env:SSH_KEY_PATH" -KnownHostsPath "$env:KNOWN_HOSTS_PATH" -WebTargetName salon-web -WebRemoteDir "$env:WEB_REMOTE_DIR"