deploy frontend #7
This file contains hidden or 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: Auto Deploy Frontend on Push | |
| on: | |
| push: | |
| branches: | |
| - stock # 监听 main 分支推送 | |
| paths: | |
| - 'frontend/**' | |
| - 'bin/**' | |
| - '.github/workflows/frontend-deploy.yml' | |
| - 'package-lock.json' | |
| jobs: | |
| deploy: | |
| runs-on: ubuntu-latest | |
| environment: AliyunECS # 如果你使用了环境 Secrets,必须指定 | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v3 | |
| - name: 2. 设置 Node.js 环境 | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '20' | |
| # 缓存 frontend 目录下的 npm 依赖,加速构建 [citation:1] | |
| cache: 'npm' | |
| cache-dependency-path: './frontend/package-lock.json' | |
| - name: 3. 安装依赖 📦 | |
| run: | | |
| cd frontend | |
| ls -al | |
| npm install [email protected] [email protected] [email protected] [email protected] --save --save-exact | |
| ls -al | |
| - name: 4. 构建项目 🔨 | |
| run: | | |
| cd frontend | |
| ls -al | |
| npm list echarts element-plus vue-router vuex --depth=0 | |
| npm run build | |
| ls -al | |
| - name: Deploy via SSH | |
| uses: appleboy/[email protected] | |
| with: | |
| host: ${{ secrets.SSH_HOST }} | |
| username: ${{ secrets.SSH_USER }} | |
| key: ${{ secrets.SSH_PRIVATE_KEY }} | |
| port: ${{ secrets.SSH_PORT || 22 }} | |
| script: | | |
| # 清理旧文件 | |
| rm -rf /data/html/* | |
| # 创建目录 | |
| mkdir -p /data/html/ | |
| - name: Deploy via SSH | |
| uses: appleboy/[email protected] | |
| with: | |
| host: ${{ secrets.SSH_HOST }} | |
| username: ${{ secrets.SSH_USER }} | |
| key: ${{ secrets.SSH_PRIVATE_KEY }} | |
| port: ${{ secrets.SSH_PORT || 22 }} # 如未设置,默认 22 | |
| source: "frontend/dist/*" | |
| target: "/data/html/" | |
| strip_components: 1 |