-
Notifications
You must be signed in to change notification settings - Fork 4
197 lines (190 loc) · 6.59 KB
/
tests-and-coverage.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
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
name: Unit, functional, integration tests and code coverage
on:
push:
branches: "**"
permissions:
id-token: write
contents: read
jobs:
backend-functional-tests:
env:
COVERAGE_FILE: .coverage.backend-functional-tests
runs-on: ubuntu-latest
defaults:
run:
working-directory: .
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: "3.10"
- name: set up postgres
run: |
docker build ./database -t pgvalor
docker run -p 5432:5432 -e POSTGRES_PASSWORD=password -e POSTGRES_DB=valor -d pgvalor
sleep 3
docker build ./migrations -t migrations
docker run -e POSTGRES_PASSWORD=password -e POSTGRES_HOST=localhost -e POSTGRES_DB=valor -e POSTGRES_USERNAME=postgres -e POSTGRES_PORT=5432 --network "host" migrations
- name: run functional tests
run: |
cd api && pip install ".[test]"
POSTGRES_PASSWORD=password POSTGRES_HOST=localhost POSTGRES_DB=valor POSTGRES_USERNAME=postgres POSTGRES_PORT=5432 coverage run --source=valor_api -m pytest -v tests/functional-tests
env:
POSTGRES_PASSWORD: password
POSTGRES_HOST: localhost
POSTGRES_DB: valor
POSTGRES_USERNAME: postgres
POSTGRES_PORT: 5432
- run: cd api && coverage report
- name: upload coverage report as artifact
uses: actions/upload-artifact@v3
with:
name: ${{ env.COVERAGE_FILE }}
path: api/${{ env.COVERAGE_FILE }}
integration-tests:
env:
COVERAGE_FILE: .coverage.integration-tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: build postgres
run: |
docker build ./database -t pgvalor
- name: setup back end test env
run: docker compose -p valor -f docker-compose.yml -f docker-compose.cicd-override.yml --env-file ./api/.env.testing up --build -d
- uses: actions/setup-python@v4
with:
python-version: "3.10"
- name: install api
run: pip install -e ".[test]"
working-directory: ./api
- name: install client
run: pip install -e ".[test]"
working-directory: ./client
- name: run integration tests
run: coverage run -a --source="api/valor_api,client/valor" -m pytest -v integration_tests/client/*
- name: run external integration tests
run: |
if ${{ github.ref == 'refs/heads/main' }}; then
coverage run -a --source="api/valor_api,client/valor" -m pytest -v integration_tests/external/*
fi
env:
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
MISTRAL_API_KEY: ${{ secrets.MISTRAL_API_KEY }}
- run: coverage report
- name: upload coverage report as artifact
uses: actions/upload-artifact@v3
with:
name: ${{ env.COVERAGE_FILE }}
path: ${{ env.COVERAGE_FILE }}
- name: install typescript client
run: npm install
working-directory: ./ts-client
- name: run typescript client tests
run: npm run test
working-directory: ./ts-client
- run: make stop-env
- run: docker compose -p valor -f docker-compose.yml -f docker-compose.cicd-override.yml --env-file ./api/.env.testing up --build -d
env:
VALOR_SECRET_KEY: ${{ vars.SECRET_KEY }}
VALOR_USERNAME: ${{ vars.USERNAME }}
VALOR_PASSWORD: ${{ vars.PASSWORD }}
- name: sleep to give back end time to spin up
run: sleep 15
- name: test auth
run: pytest -v integration_tests/auth/*
env:
VALOR_USERNAME_FOR_TESTING: ${{ vars.USERNAME }}
VALOR_PASSWORD_FOR_TESTING: ${{ vars.PASSWORD }}
backend-unit-tests:
env:
COVERAGE_FILE: .coverage.backend-unit-tests
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./api
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: "3.10"
- run: pip install ".[test]"
- run: coverage run --source=valor_api -m pytest -v tests/unit-tests
- run: coverage report
- name: upload coverage report as artifact
uses: actions/upload-artifact@v3
with:
name: ${{ env.COVERAGE_FILE }}
path: api/${{ env.COVERAGE_FILE }}
client-unit-tests:
env:
COVERAGE_FILE: .coverage.client-unit-tests
runs-on: ubuntu-latest
strategy:
matrix:
python: ["3.7", "3.8", "3.9", "3.10", "3.11"]
defaults:
run:
working-directory: ./client
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python }}
- run: pip install tox
- run: tox -e py
- name: upload coverage report as artifact
uses: actions/upload-artifact@v3
with:
name: ${{ env.COVERAGE_FILE }}
path: client/${{ env.COVERAGE_FILE }}
combine-coverage-report:
needs:
[
backend-functional-tests,
integration-tests,
backend-unit-tests,
client-unit-tests,
]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: "3.10"
- run: pip install coverage
- uses: actions/download-artifact@v3
with:
name: .coverage.backend-unit-tests
- uses: actions/download-artifact@v3
with:
name: .coverage.client-unit-tests
- uses: actions/download-artifact@v3
with:
name: .coverage.integration-tests
- uses: actions/download-artifact@v3
with:
name: .coverage.backend-functional-tests
- run: coverage combine
- run: coverage report -m
# https://nedbatchelder.com/blog/202209/making_a_coverage_badge.html
- run: |
coverage json
export TOTAL=$(python -c "import json;print(json.load(open('coverage.json'))['totals']['percent_covered_display'])")
echo "total=$TOTAL" >> $GITHUB_ENV
if (( $TOTAL < 90 )); then
echo "Coverage is below 90%"
exit 1
fi
- name: "Make badge"
if: github.ref == 'refs/heads/main'
uses: schneegans/[email protected]
with:
auth: ${{ secrets.GIST_SECRET }}
gistID: c002bbe8c0e479921401b884f4b9fc53
filename: valor-coverage.json
label: Coverage
message: ${{ env.total }}%
minColorRange: 50
maxColorRange: 90
valColorRange: ${{ env.total }}