-
Notifications
You must be signed in to change notification settings - Fork 3
89 lines (76 loc) · 2.1 KB
/
backend.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
name: CI/CD Backend
on:
push:
branches:
- main
- develop
pull_request:
branches:
- main
- develop
- feature/*
- release/*
- hotfix/*
jobs:
build:
runs-on: ubuntu-latest
services:
postgres:
image: postgres:13
ports:
- 5432:5432
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: test_db
options: >-
--health-cmd="pg_isready -U postgres"
--health-interval=10s
--health-timeout=5s
--health-retries=5
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: "18.19.1"
- name: Install dependencies
run: |
cd backend
npm install
- name: Set executable permissions
run: |
cd backend
chmod +x node_modules/.bin/eslint node_modules/.bin/jest
- name: Run lint
run: |
cd backend
npm run lint
- name: Run tests
env:
DATABASE_HOST: 127.0.0.1
DATABASE_PORT: 5432
DATABASE_USER: postgres
DATABASE_PASSWORD: postgres
DATABASE_NAME: test_db
run: |
cd backend
npm test
- name: Build Docker image
run: |
docker build -t ${{ secrets.DOCKER_USERNAME }}/backend:latest -f backend/Dockerfile ./backend
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Push Docker image
run: |
docker push ${{ secrets.DOCKER_USERNAME }}/backend:latest
- name: Deploy to Railway
if: github.ref == 'refs/heads/main'
env:
_API_KEY: ${{ secrets.RENDER_API_KEY }}
run: |
curl -X POST -H "Accept: application/json" -H "Authorization: Bearer ${{ secrets.RENDER_API_KEY }}" -d '' https://api.render.com/deploy/srv-xxxxxxxxxxxxxxxxxx