shanshanzhong ae9f9063a9
Some checks failed
site-dist-deploy / build-and-deploy (push) Failing after 3s
refactor(ci): 将复杂构建逻辑提取到独立脚本中
重构 CI 构建流程,将原有的复杂构建逻辑提取到独立的 ci-build.sh 脚本中
简化 docker.yml 工作流文件,提高可维护性和复用性
2026-01-04 03:01:23 -08:00

94 lines
2.6 KiB
YAML

name: site-dist-deploy
on:
push:
branches:
- main
- develop
pull_request:
branches:
- main
- develop
env:
VITE_APP_BASE_URL: https://h.hifast.biz
SSH_HOST: ${{ vars.PRO_SSH_HOST }}
SSH_PORT: ${{ vars.PRO_SSH_PORT }}
SSH_USER: ${{ vars.PRO_SSH_USER }}
SSH_PASSWORD: ${{ vars.PRO_SSH_PASSWORD }}
DEPLOY_PATH: /var/www/down
jobs:
build-and-deploy:
runs-on: landing-hero-web01
steps:
- name: Manual checkout (no Node required)
run: |
set -e
if git rev-parse --is-inside-work-tree >/dev/null 2>&1; then
git fetch --all --tags
git checkout "${{ github.ref_name }}"
git reset --hard "origin/${{ github.ref_name }}"
else
REPO_URL="${{ github.server_url }}/${{ github.repository }}"
echo "Cloning $REPO_URL"
git clone --depth=1 --branch "${{ github.ref_name }}" "$REPO_URL" .
git fetch --tags
fi
- name: Build dist with Unified Script
env:
VITE_APP_BASE_URL: "https://h.hifast.biz"
run: |
chmod +x scripts/ci-build.sh
./scripts/ci-build.sh
- name: Prepare target directory
uses: appleboy/ssh-action@v1.0.3
with:
host: ${{ env.SSH_HOST }}
username: ${{ env.SSH_USER }}
password: ${{ env.SSH_PASSWORD }}
port: ${{ env.SSH_PORT }}
timeout: 300s
script: |
mkdir -p ${{ env.DEPLOY_PATH }}
rm -rf ${{ env.DEPLOY_PATH }}/*
mkdir -p /tmp/ci-upload
- name: Upload dist archive
uses: appleboy/scp-action@v0.1.7
with:
host: ${{ env.SSH_HOST }}
username: ${{ env.SSH_USER }}
password: ${{ env.SSH_PASSWORD }}
port: ${{ env.SSH_PORT }}
source: "site_dist.tgz"
target: "/tmp/ci-upload"
overwrite: true
- name: Extract archive to deploy path
uses: appleboy/ssh-action@v1.0.3
with:
host: ${{ env.SSH_HOST }}
username: ${{ env.SSH_USER }}
password: ${{ env.SSH_PASSWORD }}
port: ${{ env.SSH_PORT }}
timeout: 300s
script: |
cd ${{ env.DEPLOY_PATH }}
tar -xzf /tmp/ci-upload/site_dist.tgz
rm -f /tmp/ci-upload/site_dist.tgz
- name: Reload Nginx
uses: appleboy/ssh-action@v1.0.3
with:
host: ${{ env.SSH_HOST }}
username: ${{ env.SSH_USER }}
password: ${{ env.SSH_PASSWORD }}
port: ${{ env.SSH_PORT }}
timeout: 300s
script: |
nginx -t && nginx -s reload