-
Notifications
You must be signed in to change notification settings - Fork 17
223 lines (187 loc) · 6.59 KB
/
test.yml
File metadata and controls
223 lines (187 loc) · 6.59 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
name: ResCanvas Test Pipeline
on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main, develop ]
env:
PYTHON_VERSION: '3.10'
NODE_VERSION: '18'
jobs:
backend-unit-tests:
name: Backend Unit Tests
runs-on: ubuntu-latest
services:
mongodb:
image: mongo:6
env:
MONGO_INITDB_ROOT_USERNAME: testuser
MONGO_INITDB_ROOT_PASSWORD: testpass
options: >-
--health-cmd "mongosh --eval 'db.adminCommand(\"ping\")'"
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 27017:27017
redis:
image: redis:7-alpine
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 6379:6379
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Cache Python dependencies
uses: actions/cache@v3
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Wait for MongoDB
run: |
for i in {1..30}; do
if mongosh --host localhost:27017 --username testuser --password testpass --authenticationDatabase admin --eval "db.adminCommand('ping')" > /dev/null 2>&1; then
echo "MongoDB is ready"
break
fi
echo "Waiting for MongoDB... ($i/30)"
sleep 2
done
- name: Install dependencies
run: |
cd backend
pip install -r requirements.txt
- name: Generate test keys
run: |
cd backend
python3 gen_keys.py > /tmp/keys.txt
export SIGNER_PUBLIC_KEY=$(grep "Public Key:" /tmp/keys.txt | awk '{print $3}')
export SIGNER_PRIVATE_KEY=$(grep "Private Key:" /tmp/keys.txt | awk '{print $3}')
printf "JWT_SECRET=test-secret-key-do-not-use-in-production\n" > .env
printf "MONGO_ATLAS_URI=mongodb://testuser:testpass@localhost:27017/?authSource=admin\n" >> .env
printf "SIGNER_PUBLIC_KEY=%s\n" "$SIGNER_PUBLIC_KEY" >> .env
printf "SIGNER_PRIVATE_KEY=%s\n" "$SIGNER_PRIVATE_KEY" >> .env
printf "RESILIENTDB_GRAPHQL_URI=https://cloud.resilientdb.com/graphql\n" >> .env
printf "RES_DB_BASE_URI=https://crow.resilientdb.com\n" >> .env
- name: Run unit tests
env:
JWT_SECRET: 'test-secret-key-do-not-use-in-production'
RESILIENTDB_GRAPHQL_URI: 'https://cloud.resilientdb.com/graphql'
RES_DB_BASE_URI: 'https://crow.resilientdb.com'
run: |
cd backend
export SIGNER_PUBLIC_KEY=$(grep "SIGNER_PUBLIC_KEY=" .env | cut -d'=' -f2)
export SIGNER_PRIVATE_KEY=$(grep "SIGNER_PRIVATE_KEY=" .env | cut -d'=' -f2)
pytest tests/unit/ -n auto -m unit
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
with:
file: ./backend/coverage.xml
flags: backend-unit
name: backend-unit-coverage
- name: Upload coverage artifacts
uses: actions/upload-artifact@v4
with:
name: backend-unit-coverage
path: backend/htmlcov/
frontend-unit-tests:
name: Frontend Unit Tests
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VERSION }}
- name: Cache Node modules
uses: actions/cache@v3
with:
path: frontend/node_modules
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Install dependencies
run: |
cd frontend
npm ci
- name: Run unit tests
run: |
cd frontend
npm test -- --coverage --watchAll=false --testPathIgnorePatterns='Canvas.test.js|Dashboard.test.js|App.test.js' --ci
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
with:
file: ./frontend/coverage/coverage-final.json
flags: frontend-unit
name: frontend-unit-coverage
- name: Upload coverage artifacts
uses: actions/upload-artifact@v4
with:
name: frontend-unit-coverage
path: frontend/coverage/
code-quality:
name: Code Quality Checks
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Install Python linters
run: |
pip install flake8 black
- name: Run flake8
run: |
cd backend
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics --exclude=incubator-*,__pycache__
- name: Check black formatting
continue-on-error: true
run: |
cd backend
black --check . --exclude='incubator-*'
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VERSION }}
- name: Cache Node modules
uses: actions/cache@v3
with:
path: frontend/node_modules
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Install frontend dependencies
run: |
cd frontend
npm ci
- name: Run ESLint
run: |
cd frontend
npm run lint || true
coverage-report:
name: Generate Coverage Report
needs: [backend-unit-tests, frontend-unit-tests]
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Download all coverage artifacts
uses: actions/download-artifact@v4
- name: Display coverage summary
run: |
echo "## Coverage Summary" >> $GITHUB_STEP_SUMMARY
echo "Coverage reports have been uploaded to Codecov" >> $GITHUB_STEP_SUMMARY
echo "View detailed reports in the artifacts" >> $GITHUB_STEP_SUMMARY