feat: add GitHub Actions workflow to build and deploy application to … #1
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: Build and Deploy | |
| on: | |
| push: | |
| branches: | |
| - main | |
| jobs: | |
| build-and-deploy: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 20 | |
| cache: "npm" | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Build Next.js application | |
| run: npm run build | |
| - name: Deploy to server via SCP | |
| uses: appleboy/scp-action@v0.1.7 | |
| with: | |
| host: ${{ secrets.SERVER_HOST }} | |
| username: ${{ secrets.SERVER_USERNAME }} | |
| password: ${{ secrets.SERVER_PASSWORD }} | |
| port: ${{ secrets.SERVER_PORT }} | |
| source: ".next/,public/,package.json,package-lock.json,next.config.mjs,next.config.js" | |
| target: "/home/cosmic-linux-2/osp-frontend" | |
| overwrite: true | |
| - name: Install dependencies and restart PM2 | |
| uses: appleboy/ssh-action@v1.2.0 | |
| with: | |
| host: ${{ secrets.SERVER_HOST }} | |
| username: ${{ secrets.SERVER_USERNAME }} | |
| password: ${{ secrets.SERVER_PASSWORD }} | |
| port: ${{ secrets.SERVER_PORT }} | |
| script: | | |
| cd /home/cosmic-linux-2/osp-frontend | |
| npm ci --omit=dev | |
| pm2 restart osp-frontend |