-
Notifications
You must be signed in to change notification settings - Fork 3
240 lines (208 loc) · 8.04 KB
/
docker-auto-test.yaml
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
name: Testing pipeline
on:
pull_request:
branches:
- "*"
jobs:
build-and-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.sha }}
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.10.13"
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: "20"
- name: Install Docker Compose
run: |
sudo apt-get update
sudo apt-get install -y docker-compose
- name: Cache Poetry dependencies
uses: actions/cache@v3
with:
path: ~/.cache/pypoetry
key: ${{ runner.os }}-poetry-${{ hashFiles('**/poetry.lock') }}
restore-keys: |
${{ runner.os }}-poetry-
- name: Cache npm dependencies
uses: actions/cache@v3
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Cache Docker images
uses: actions/cache@v3
with:
path: /var/lib/docker
key: ${{ runner.os }}-docker-${{ hashFiles('**/Dockerfile') }}
restore-keys: |
${{ runner.os }}-docker-
# Commented out mochawesome installation as it's only needed for Cypress
# - name: Install mochawesome and marge
# run: |
# npm install mochawesome mochawesome-merge mochawesome-report-generator --save-dev
- name: Install Poetry
run: pip install poetry==1.6.1
- name: Install backend dependencies
run: |
# Ensure that pip, setuptools, and wheel are up to date
pip install --upgrade pip setuptools wheel
# Install Poetry dependencies
cd backend
poetry config virtualenvs.create false
poetry install
pip install pytest-github-actions-annotate-failures typing_extensions
- name: Install frontend dependencies
run: |
cd frontend
npm ci
- name: Fix docker-compose.yml
run: |
sed -i 's/: true/: "true"/g; s/: false/: "false"/g' docker-compose.yml
- name: Build and start services
run: |
docker-compose build
docker-compose up -d
- name: Run backend tests
id: backend_tests
continue-on-error: true
run: |
cd backend
poetry run pytest --junitxml=pytest-results.xml
env:
LCFS_DB_HOST: localhost
LCFS_DB_PORT: 5432
LCFS_DB_USER: lcfs
LCFS_DB_PASS: development_only
LCFS_DB_BASE: lcfs
LCFS_REDIS_HOST: localhost
LCFS_REDIS_PORT: 6379
LCFS_REDIS_PASSWORD: development_only
APP_ENVIRONMENT: dev
- name: Upload pytest results
if: always()
uses: actions/upload-artifact@v3
with:
name: pytest-results
path: backend/pytest-results.xml
- name: Run frontend tests
id: frontend_tests
continue-on-error: true
run: |
cd frontend
npm run test:run -- --reporter=junit --outputFile=vitest-results.xml
env:
CI: true
- name: Upload Vitest results
if: always()
uses: actions/upload-artifact@v3
with:
name: vitest-results
path: frontend/vitest-results.xml
# Commented out Cypress-related steps
# - name: Create cypress.env.json
# run: |
# echo '{
# "admin_idir_username": "${{ secrets.ADMIN_IDIR_USERNAME }}",
# "admin_idir_password": "${{ secrets.ADMIN_IDIR_PASSWORD }}",
# "org1_bceid_username": "${{ secrets.ORG1_BCEID_USERNAME }}",
# "org1_bceid_password": "${{ secrets.ORG1_BCEID_PASSWORD }}",
# "org1_bceid_id": "${{ secrets.ORG1_BCEID_ID }}",
# "org1_bceid_userId": "${{ secrets.ORG1_BCEID_USERID }}",
# "org2_bceid_username": "${{ secrets.ORG2_BCEID_USERNAME }}",
# "org2_bceid_password": "${{ secrets.ORG2_BCEID_PASSWORD }}",
# "org2_bceid_id": "${{ secrets.ORG2_BCEID_ID }}",
# "org2_bceid_userId": "${{ secrets.ORG2_BCEID_USERID }}"
# }' > frontend/cypress.env.json
# - name: Run Cypress tests
# id: cypress_tests
# continue-on-error: true
# uses: cypress-io/github-action@v6
# with:
# command: npm run cypress:run
# wait-on: 'http://localhost:3000'
# working-directory: frontend
# env:
# ADMIN_IDIR_USERNAME: ${{ secrets.ADMIN_IDIR_USERNAME }}
# ADMIN_IDIR_PASSWORD: ${{ secrets.ADMIN_IDIR_PASSWORD }}
# org1_bceid_username: ${{ secrets.ORG1_BCEID_USERNAME }}
# org1_bceid_password: ${{ secrets.ORG1_BCEID_PASSWORD }}
# org1_bceid_id: ${{ secrets.ORG1_BCEID_ID }}
# org1_bceid_userId: ${{ secrets.ORG1_BCEID_USERID }}
# org2_bceid_username: ${{ secrets.ORG2_BCEID_USERNAME }}
# org2_bceid_password: ${{ secrets.ORG2_BCEID_PASSWORD }}
# org2_bceid_id: ${{ secrets.ORG2_BCEID_ID }}
# org2_bceid_userId: ${{ secrets.ORG2_BCEID_USERID }}
# - name: Combine mochawesome reports
# run: |
# npx mochawesome-merge frontend/cypress/reports/*.json > frontend/cypress/reports/combined-report.json
# - name: Generate HTML report
# run: |
# npx marge frontend/cypress/reports/combined-report.json --reportDir frontend/cypress/reports --inline
# - name: Generate test summary
# run: |
# node generate-summary.js
# - name: Post test summary as a comment
# if: always()
# run: |
# SUMMARY=$(cat frontend/cypress/reports/test-summary.txt)
# gh pr comment ${{ github.event.pull_request.number }} --body "$SUMMARY"
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# - name: Upload Cypress results
# if: always()
# uses: actions/upload-artifact@v3
# with:
# name: cypress-results
# path: |
# frontend/cypress/reports/
# frontend/cypress/screenshots/
# - name: Post Cypress results as a comment
# if: always()
# run: |
# gh pr comment ${{ github.event.pull_request.number }} --body "Cypress test report is available [here](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}). Download the 'cypress-results' artifact to view the report."
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Stop services
if: always()
run: docker-compose down
- name: Publish Backend Test Results
uses: EnricoMi/publish-unit-test-result-action@v2
if: always()
with:
files: backend/pytest-results.xml
github_token: ${{ secrets.GITHUB_TOKEN }}
comment_title: "Backend Test Results"
check_name: "Backend Test Results"
fail_on: "errors"
report_individual_runs: "true"
deduplicate_classes_by_file_name: "true"
- name: Publish Frontend Test Results
uses: EnricoMi/publish-unit-test-result-action@v2
if: always()
with:
files: frontend/vitest-results.xml
github_token: ${{ secrets.GITHUB_TOKEN }}
comment_title: "Frontend Test Results"
check_name: "Frontend Test Results"
fail_on: "errors"
report_individual_runs: "true"
deduplicate_classes_by_file_name: "true"
- name: Check test results
if: always()
run: |
if [ "${{ steps.backend_tests.outcome }}" == "failure" ] || \
[ "${{ steps.frontend_tests.outcome }}" == "failure" ]; then
# Note: When re-enabling Cypress tests, add this condition:
# || [ "${{ steps.cypress_tests.outcome }}" == "failure" ]
echo "One or more tests failed"
exit 1
else
echo "All tests passed"
fi