Files
JayuCloud/.gitea/workflows/sit环境回退上一个版本.yml
T
xiaowang 3ad792115c
环境分支晋级检查 / environment-promotion-source (pull_request_target) Successful in 1s
自动发布开发环境 Nacos 配置 / publish (push) Successful in 29s
fix(actions): use Chinese workflow filenames
2026-10-16 14:48:49 +08:00

79 lines
3.5 KiB
YAML

name: 测试环境回退上一个版本
"on":
workflow_dispatch:
inputs:
auto_rollback:
description: 是否由自动失败流程触发
required: false
type: boolean
concurrency:
group: release-sit
cancel-in-progress: false
jobs:
rollback:
runs-on: jayucloud
container:
options: >-
-v /opt/software/panel/apps/gitea/act_runner/salon-release:/salon-release
env:
GITHUB_SERVER_URL: http://192.168.5.15:3000
RELEASE_ENVIRONMENT: sit
RELEASE_STORE_ROOT: /salon-release
NACOS_ENVIRONMENT: sit
AUTO_ROLLBACK: ${{ inputs.auto_rollback }}
WEB_TARGET_HOST: 10.66.0.3
WEB_TARGET_PORT: 22
WEB_TARGET_USER: root
WEB_REMOTE_DIR: /opt/jc-salon-frontend-sit
SALON_PROD_SSH_PASSWORD: ${{ secrets.SALON_PROD_SSH_PASSWORD }}
NACOS_SIT_URLS: ${{ secrets.NACOS_SIT_URLS }}
NACOS_SIT_USERNAME: ${{ secrets.NACOS_SIT_USERNAME }}
NACOS_SIT_PASSWORD: ${{ secrets.NACOS_SIT_PASSWORD }}
steps:
- name: 检出回退脚本
shell: bash
env:
GITEA_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_SERVER_URL: http://192.168.5.15:3000
run: |
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 "$GITHUB_SHA"
git checkout --detach "$GITHUB_SHA"
- name: 读取最近成功版本
shell: bash
run: |
set -euo pipefail
test -f /salon-release/records/sit/latest-success-deploy.json
node - <<'NODE' >> "$GITHUB_ENV"
const fs = require('fs');
const latest = JSON.parse(fs.readFileSync('/salon-release/records/sit/latest-success-deploy.json'));
const id = process.env.AUTO_ROLLBACK === 'true' ? latest.releaseId : latest.previousReleaseId;
if (!id) throw new Error('没有可回退的 SIT 成功版本');
const target = JSON.parse(fs.readFileSync(`/salon-release/records/sit/deploy/${id}.json`));
console.log(`PACKAGE_DIRECTORY=${target.packageDir}`);
console.log(`ROLLBACK_SNAPSHOT_ID=${target.activeSnapshotId}`);
console.log(`ROLLBACK_RELEASE_ID=${target.releaseId}`);
console.log(`NACOS_RELEASE_ID=${target.nacosReleaseId}`);
NODE
- name: 安装 SSH 密码工具
shell: bash
run: apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends sshpass
- name: 恢复 SIT Nacos
shell: bash
env:
NACOS_SNAPSHOT_ID: ${{ env.ROLLBACK_SNAPSHOT_ID }}
NACOS_RELEASE_ID: ${{ env.NACOS_RELEASE_ID }}
AUTO_ROLLBACK: 'true'
NACOS_ROLLBACK_INVALIDATE: 'true'
run: node .gitea/scripts/rollback-nacos.mjs
- name: 执行 SIT 应用回退
shell: pwsh
run: ./docs/scripts/deploy-jayucloud-salon-production.ps1 -Deploy -SkipDatabaseInit -AllowSitTarget -RequireSystemd -PackageDirectory "$env:PACKAGE_DIRECTORY" -SshPassword "$env:SALON_PROD_SSH_PASSWORD" -CoreRemoteAppDir /opt/jc-salon-core-sit -GatewayRemoteAppDir /opt/jc-salon-gateway-sit -CorePattern '^sit-app01$' -GatewayPattern '^sit-app01$' -CoreServiceName jc-salon-core-sit -GatewayServiceName jc-salon-gateway-sit -CoreHealthPort 181 -GatewayHealthPort 180 -WebTargetName salon-web-sit -WebRemoteDir "$env:WEB_REMOTE_DIR" -PublicBaseUrl https://sit.yunail.art
- name: 记录回退后的成功版本
shell: bash
run: node .gitea/scripts/record-rollback.mjs