-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
83 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
name: CI/CD Backend | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
services: | ||
postgres: | ||
image: postgres:13 | ||
ports: | ||
- 5432:5432 | ||
env: | ||
DATABASE_HOST: ${{ secrets.DATABASE_HOST }} | ||
DATABASE_PORT: ${{ secrets.DATABASE_PORT }} | ||
DATABASE_USER: ${{ secrets.DATABASE_USER }} | ||
DATABASE_PASSWORD: ${{ secrets.DATABASE_PASSWORD }} | ||
DATABASE_NAME: ${{ secrets.DATABASE_NAME }} | ||
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: ${{ secrets.DATABASE_HOST }} | ||
DATABASE_PORT: ${{ secrets.DATABASE_PORT }} | ||
DATABASE_USER: ${{ secrets.DATABASE_USER }} | ||
DATABASE_PASSWORD: ${{ secrets.DATABASE_PASSWORD }} | ||
DATABASE_NAME: ${{ secrets.DATABASE_NAME }} | ||
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 Render | ||
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 |