fix: use dist/ from GitHub Actions instead of rebuilding on VPS #25
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: Deploy to VPS | |
| on: | |
| push: | |
| branches: | |
| - main | |
| - develop | |
| workflow_dispatch: # Cho phép chạy thủ công | |
| jobs: | |
| deploy: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Setup pnpm | |
| uses: pnpm/action-setup@v2 | |
| with: | |
| version: 9 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '20' | |
| cache: 'pnpm' | |
| - name: Install dependencies | |
| run: pnpm install --frozen-lockfile | |
| - name: Run linter | |
| run: pnpm run lint | |
| continue-on-error: true # Nếu lint fail vẫn tiếp tục | |
| - name: Build application | |
| run: pnpm run build | |
| - name: Deploy to VPS | |
| uses: appleboy/scp-action@master | |
| with: | |
| host: ${{ secrets.VPS_HOST }} | |
| username: ${{ secrets.VPS_USERNAME }} | |
| key: ${{ secrets.VPS_SSH_KEY }} | |
| port: ${{ secrets.VPS_PORT || 22 }} | |
| source: "dist/,package.json,pnpm-lock.yaml" | |
| target: "/home/${{ secrets.VPS_USERNAME }}/elearning-backend" | |
| strip_components: 0 | |
| - name: Execute deployment script on VPS | |
| uses: appleboy/ssh-action@master | |
| with: | |
| host: ${{ secrets.VPS_HOST }} | |
| username: ${{ secrets.VPS_USERNAME }} | |
| key: ${{ secrets.VPS_SSH_KEY }} | |
| port: ${{ secrets.VPS_PORT || 22 }} | |
| script: | | |
| cd /home/${{ secrets.VPS_USERNAME }}/elearning-backend | |
| chmod +x deploy.sh | |
| ./deploy.sh | |