-
Notifications
You must be signed in to change notification settings - Fork 0
113 lines (105 loc) · 2.89 KB
/
backend_pipeline.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
name: Backend Pipeline
# Workflow triggers
on:
push:
branches:
- 'main'
paths:
- 'backend/**'
- '.github/workflows/backend_pipeline.yml'
pull_request:
branches:
- 'main'
paths:
- 'backend/**'
- '.github/workflows/backend_pipeline.yml'
schedule:
- cron: 0 0 * * MON # Schedule pipeline to run monday midnight after sunday ends
workflow_dispatch: # Enable manual runs of workflow
# Workflow stages
jobs:
# Perform Lint Checks
lint:
name: Lint Checks
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./backend
steps:
- uses: actions/checkout@v4
- name: Use Node.js 20.x
uses: actions/setup-node@v4
with:
node-version: '20.x'
- name: Install pnpm
run: npm install -g pnpm
- name: Install Dependencies
run: pnpm install
- name: Run lint script
run: pnpm run lint
# Run Unit Tests
test:
name: Unit Tests
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./backend
steps:
- uses: actions/checkout@v4
- name: Use Node.js 20.x
uses: actions/setup-node@v4
with:
node-version: 20.x
- name: Install pnpm
run: npm install -g pnpm
- name: Install dependencies
run: pnpm install
- name: Clear jest cache
run: pnpm jest --clearCache
- name: Run unit tests with jest
run: pnpm run test
# Build Application
build:
name: Build Application
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./backend
steps:
- uses: actions/checkout@v4
- name: Use Node.js 20.x
uses: actions/setup-node@v4
with:
node-version: '20.x'
- name: Install pnpm
run: npm install -g pnpm
- name: Install Dependencies
run: pnpm install
- name: Compile TypeScript into JavaScript
run: pnpm run build
# Deploy Application to Development Environment
deploy-dev:
name: Deploy to Development Environment
needs: [lint, test, build] # lint, test, and build must pass before deployment
if: github.event_name == 'schedule' || github.event_name == 'push' # only deploy on push and weekly CRON job
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME_DEV }}
password: ${{ secrets.DOCKER_PASSWORD_DEV }}
- name: Build and Push Docker image
uses: docker/build-push-action@v5
with:
context: ./backend
file: ./backend/Dockerfile.dev
push: true
tags: fitnessehealthapp/backend:development
platforms: linux/amd64
- name: Deploy Docker Image to Render
run: |
curl -X POST ${{ secrets.RENDER_DEPLOY_HOOK_DEV }}