-
Notifications
You must be signed in to change notification settings - Fork 1
263 lines (219 loc) · 6.46 KB
/
Copy pathci-cd.yml
File metadata and controls
263 lines (219 loc) · 6.46 KB
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
name: CI/CD Pipeline
on:
push:
branches: [main, develop]
pull_request:
branches: [main, develop]
env:
NODE_VERSION: '20'
jobs:
backend-lint:
name: Backend - Lint & Format Check
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [20.x]
steps:
- uses: actions/checkout@v4
- name: Setup Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
cache-dependency-path: backend/package-lock.json
- name: Install dependencies
run: |
cd backend
npm ci
- name: Run ESLint
run: |
cd backend
npm run lint
- name: Check code formatting
run: |
cd backend
npm run format -- --check
backend-test:
name: Backend - Unit & Integration Tests
runs-on: ubuntu-latest
needs: backend-lint
services:
mysql:
image: mysql:8.0
env:
MYSQL_ROOT_PASSWORD: root_password
MYSQL_DATABASE: dispatchcore_test
options: >-
--health-cmd="mysqladmin ping"
--health-interval=10s
--health-timeout=5s
--health-retries=3
ports:
- 3306:3306
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
cache-dependency-path: backend/package-lock.json
- name: Install dependencies
run: |
cd backend
npm ci
- name: Run unit tests
env:
DB_HOST: localhost
DB_PORT: 3306
DB_USER: root
DB_PASSWORD: root_password
DB_NAME: dispatchcore_test
NODE_ENV: test
run: |
cd backend
npm run test:unit || echo "No unit tests yet"
- name: Run integration tests
env:
DB_HOST: localhost
DB_PORT: 3306
DB_USER: root
DB_PASSWORD: root_password
DB_NAME: dispatchcore_test
NODE_ENV: test
run: |
cd backend
npm run test:integration || echo "No integration tests yet"
- name: Upload coverage
uses: codecov/codecov-action@v3
with:
files: ./backend/coverage/lcov.info
flags: backend
fail_ci_if_error: false
frontend-lint:
name: Frontend - Lint & Build Check
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [20.x]
steps:
- uses: actions/checkout@v4
- name: Setup Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
cache-dependency-path: frontend/package-lock.json
- name: Install dependencies
run: |
cd frontend
npm ci
- name: Run ESLint
run: |
cd frontend
npm run lint
- name: Type check
run: |
cd frontend
npx tsc --noEmit
- name: Build project
run: |
cd frontend
npm run build
frontend-test:
name: Frontend - Unit & Component Tests
runs-on: ubuntu-latest
needs: frontend-lint
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
cache-dependency-path: frontend/package-lock.json
- name: Install dependencies
run: |
cd frontend
npm ci
- name: Run unit tests
run: |
cd frontend
npm run test:unit || echo "No unit tests yet"
- name: Run component tests
run: |
cd frontend
npm run test:components || echo "No component tests yet"
- name: Upload coverage
uses: codecov/codecov-action@v3
with:
files: ./frontend/coverage/lcov.info
flags: frontend
fail_ci_if_error: false
security-audit:
name: Security - Audit Dependencies
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
- name: Backend - npm audit
run: |
cd backend
npm audit --audit-level=moderate || echo "Audit vulnerabilities found"
continue-on-error: true
- name: Frontend - npm audit
run: |
cd frontend
npm audit --audit-level=moderate || echo "Audit vulnerabilities found"
continue-on-error: true
build-artifacts:
name: Build & Generate Artifacts
runs-on: ubuntu-latest
needs: [backend-test, frontend-test]
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
- name: Build backend
run: |
cd backend
npm ci
npm run lint
- name: Build frontend
run: |
cd frontend
npm ci
npm run build
- name: Upload frontend build
uses: actions/upload-artifact@v4
with:
name: frontend-build
path: frontend/dist
retention-days: 7
- name: Create release notes
run: |
echo "## Build Artifacts" > RELEASE_NOTES.md
echo "- Frontend build: dist/" >> RELEASE_NOTES.md
echo "- Timestamp: $(date)" >> RELEASE_NOTES.md
notify:
name: Notify Build Status
runs-on: ubuntu-latest
needs: [backend-lint, backend-test, frontend-lint, frontend-test]
if: always()
steps:
- name: Check build status
run: |
if [ "${{ needs.backend-lint.result }}" = "failure" ] || \
[ "${{ needs.backend-test.result }}" = "failure" ] || \
[ "${{ needs.frontend-lint.result }}" = "failure" ] || \
[ "${{ needs.frontend-test.result }}" = "failure" ]; then
echo "Build Failed - Check logs"
exit 1
fi
echo "All checks passed successfully!"