shanshanzhong d687e47fdc
Some checks failed
site-dist-deploy / build-and-deploy (push) Failing after 2s
ci(docker): 使用nvm替代直接运行node容器构建
修改docker构建流程,通过nvm安装并使用node 20,替代直接运行node容器的方式
2026-01-04 00:56:14 -08:00

104 lines
3.0 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 in Node container
run: |
set -e
export NVM_DIR="$HOME/.nvm"
if [ ! -d "$NVM_DIR" ]; then
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
fi
. "$NVM_DIR/nvm.sh"
nvm install 20
nvm use 20
node -v
npm -v
npm ci
echo "VITE_APP_BASE_URL=${VITE_APP_BASE_URL}" > .env.pord
npm run build:prod
tar -C dist -czf site_dist.tgz .
- 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