Val213 patch add ci #44
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build and Deploy Nuxt Frontend (SPA) | |
on: | |
push: | |
branches: [ "main" ] | |
pull_request: | |
branches: [ "main" ] | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Set up Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: '20.17.0' | |
- name: Install dependencies | |
run: | | |
cd frontend | |
npm install | |
- name: Build Nuxt frontend (SPA) | |
run: | | |
cd frontend | |
npm run build | |
- name: List build directory (for debugging) | |
run: | | |
ls -la frontend/.output | |
- name: Compress build artifacts | |
run: | | |
cd frontend | |
tar -czf nuxt-build.tar.gz .output nuxt.config.ts package.json assets ecosystem.config.js | |
- name: List compressed file (for debugging) | |
run: | | |
ls -la frontend/nuxt-build.tar.gz | |
- name: Upload Nuxt build artifacts | |
uses: actions/upload-artifact@v4 | |
with: | |
name: nuxt-build | |
path: frontend/nuxt-build.tar.gz | |
deploy: | |
runs-on: ubuntu-latest | |
needs: build | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Download Nuxt build artifacts | |
uses: actions/download-artifact@v4 | |
with: | |
name: nuxt-build | |
path: . | |
- name: Deploy Nuxt frontend (SPA) | |
env: | |
SSH_PRIVATE_KEY: ${{ secrets.DEPLOY_KEY }} | |
SSH_PASSWORD: ${{ secrets.SSH_PASSWORD }} | |
run: | | |
# 打印 SSH 私钥的路径和内容 | |
echo "$SSH_PRIVATE_KEY" > deploy_key | |
ls -la deploy_key | |
chmod 600 deploy_key | |
# 使用 SSH 连接到服务器 | |
ssh -o StrictHostKeyChecking=no -i deploy_key [email protected] | |
# 打印 Node.js 版本以检查是否切换到了正确版本 | |
echo "Current Node.js version:" | |
node --version | |
# 在服务器上部署 Nuxt 前端 | |
echo "Deploying Nuxt frontend..." | |
sudo -E mkdir -p /usr/share/nginx/html/ibminscut && | |
sudo -E tar -xzf nuxt-build.tar.gz -C /usr/share/nginx/html/ibminscut && | |
sudo -E chown -R www-data:www-data /usr/share/nginx/html/ibminscut && | |
sudo -E chmod -R 755 /usr/share/nginx/html/ibminscut && | |
rm nuxt-build.tar.gz && | |
cd /usr/share/nginx/html/ibminscut && | |
sudo -E npm install --production && | |
sudo -E pm2 start /usr/share/nginx/html/ibminscut/ecosystem.config.js || { echo 'SSH command failed'; exit 1; } | |
rm deploy_key |