Build, Test and Deploy Backend to vps #70
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, Test and Deploy Backend to vps | |
on: | |
push: | |
branches: ["main"] | |
paths: backend/** | |
workflow_dispatch: | |
jobs: | |
build: | |
runs-on: self-hosted | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Set up Node.js 16.x | |
uses: actions/setup-node@v3 | |
with: | |
node-version: 16.x | |
cache: "npm" | |
- run: npm ci | |
working-directory: ./backend | |
- name: kill all running instances | |
run: pm2 kill | |
- name: Copying .env.production from /home/gps/envs/.env.production | |
run: cp /home/gps/envs/.env.production .env.production | |
working-directory: ./backend | |
- name: Copying .env.test from /home/gps/envs/.env.test | |
run: cp /home/gps/envs/.env.test .env.test | |
working-directory: ./backend | |
- name: Run tests | |
run: | | |
export NODE_ENV=test | |
npm run test | |
working-directory: ./backend | |
- run: export NODE_ENV=production | |
- run: npm run build --if-present | |
working-directory: ./backend | |
- name: run deploy script | |
working-directory: ./backend | |
run: | | |
export NODE_ENV=production | |
pm2 start "npm run start" --update-env |