Skip to content

Instantly share code, notes, and snippets.

@volodymyr-kasap
Created November 27, 2022 23:05
Show Gist options
  • Save volodymyr-kasap/d8108e91a7ff43a3316f933576d60e4e to your computer and use it in GitHub Desktop.
Save volodymyr-kasap/d8108e91a7ff43a3316f933576d60e4e to your computer and use it in GitHub Desktop.
Next.js CI/CD github actions
name: Deploy
on:
push:
branches: [ develop ]
jobs:
build:
if: github.ref == 'refs/heads/develop'
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [16.x]
steps:
- name: Clone repository
uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: Install dependencies
run: npm ci
- name: Generate build
run: npm run build
- name: Copy build to VPS
uses: appleboy/scp-action@master
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
port: 22
key: ${{ secrets.SSHKEY }}
source: ".,!node_modules"
target: "/var/www/frontend"
- name: Restart node server
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
key: ${{ secrets.SSHKEY }}
port: 22
script_stop: true
scipts: |
cd /var/www/frontend
npm install
pm2 restart frontend
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment