-
Notifications
You must be signed in to change notification settings - Fork 0
224 lines (187 loc) · 6.66 KB
/
test.yml
File metadata and controls
224 lines (187 loc) · 6.66 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
name: Tests
on:
push:
branches:
- develop
pull_request:
branches-ignore:
- master
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.ref }}
cancel-in-progress: true
env:
DEFAULT_PYTHON: '3.14'
MIN_COVERAGE: 92
permissions:
contents: write
checks: write
pull-requests: write
jobs:
tests:
name: Run tests (Python ${{ matrix.python-version }}, Pydantic v${{ matrix.pydantic-version }} on ${{ matrix.os }})
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- python-version: '3.7'
pydantic-version: '1'
os: ubuntu-22.04
- python-version: '3.14'
pydantic-version: '2'
os: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
- name: Start container dependencies
run: |
docker compose -f docker-compose.test.yml down -v --remove-orphans
docker compose -f docker-compose.test.yml up -d db ldap
# https://docs.docker.com/build/ci/github-actions/cache/#local-cache
- name: Cache Docker layers
uses: actions/cache@v5
with:
path: ${{ runner.temp }}/.buildx-cache
key: ${{ runner.os }}-buildx-${{ hashFiles('docker/Dockerfile.backend', 'pyproject.toml', 'uv.lock') }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Build Backend Container
uses: docker/build-push-action@v7
with:
context: .
file: docker/Dockerfile.backend
tags: mtsrus/horizon-backend:develop
target: test
build-args: |
PYTHON_VERSION=${{ matrix.python-version }}
push: false
load: true
cache-from: type=local,src=${{ runner.temp }}/.buildx-cache
- name: Creare reports dir
run: |
mkdir -p reports/
sudo chmod 777 -R reports/
- name: Start Backend
run: |
docker compose -f docker-compose.test.yml up -d --wait --wait-timeout 60
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v6
with:
python-version: ${{ matrix.python-version }}
- name: Install system dependencies
# this step is needed for successful installation of "bonsai" library in python dependencies
run: sudo apt-get update && sudo apt-get install -y libldap2-dev libsasl2-dev
- name: Install uv
uses: astral-sh/setup-uv@v7
with:
enable-cache: 'false'
# astral-sh/setup-uv cannot restore multiple keys
- name: Cache uv
uses: actions/cache@v5
with:
path: ~/.cache/uv
key: ${{ runner.os }}-python${{ env.DEFAULT_PYTHON }}-pydantic${{ matrix.pydantic-version }}-${{ hashFiles('uv.lock') }}
restore-keys: |
${{ runner.os }}-python${{ env.DEFAULT_PYTHON }}-pydantic${{ matrix.pydantic-version }}-${{ hashFiles('uv.lock') }}
${{ runner.os }}-python${{ env.DEFAULT_PYTHON }}-pydantic${{ matrix.pydantic-version }}-
${{ runner.os }}-python${{ env.DEFAULT_PYTHON }}-
- name: Install dependencies
run: |
uv sync --all-extras --group test
if [ "${{ matrix.pydantic-version }}" == "1" ]; then
uv run pip install "pydantic<2.0.0"
fi
- name: Run Tests
run: |
source .env.local
uv run coverage run -m pytest --junitxml=reports/junit/test-${{ matrix.os }}-${{ matrix.python-version }}-${{ matrix.pydantic-version }}.xml
- name: Dump backend logs on failure
if: failure()
uses: jwalton/gh-docker-logs@v2
with:
images: mtsrus/horizon-backend
dest: ./logs
- name: Shutdown Backend Container
if: always()
run: |
docker compose -f docker-compose.test.yml down -v --remove-orphans
- name: Upload server logs
uses: actions/upload-artifact@v7
if: failure()
with:
name: backend-logs-${{ matrix.os }}-${{ matrix.python-version }}-${{ matrix.pydantic-version }}
path: logs/*
- name: Upload Coverage Results
uses: actions/upload-artifact@v7
if: success() || failure()
with:
name: coverage-${{ matrix.os }}-${{ matrix.python-version }}-${{ matrix.pydantic-version }}
path: reports/
# https://github.com/actions/upload-artifact/issues/602
include-hidden-files: true
all_done:
name: Tests done
runs-on: ubuntu-latest
permissions:
contents: write
checks: write
pull-requests: write
if: success() || failure()
needs: [tests]
steps:
- name: Checkout code
uses: actions/checkout@v6
- name: Download all raw coverage data
uses: actions/download-artifact@v8
with:
path: reports/
pattern: coverage-*
merge-multiple: true
- name: Show test results
uses: mikepenz/action-junit-report@v6
with:
report_paths: reports/junit/*.xml
- name: Set up Python ${{ env.DEFAULT_PYTHON }}
uses: actions/setup-python@v6
with:
python-version: ${{ env.DEFAULT_PYTHON }}
- name: Install uv
uses: astral-sh/setup-uv@v7
with:
enable-cache: 'false'
- name: Install dependencies
run: |
uv sync --group test
- name: Combine Coverage Data
run: |
uv run coverage combine
uv run coverage xml -o reports/coverage.xml
- name: Coverage comment
id: coverage
uses: MishaKav/pytest-coverage-comment@v1
with:
pytest-xml-coverage-path: ./reports/coverage.xml
default-branch: develop
xml-skip-covered: true
report-only-changed-files: true
hide-comment: ${{ github.event_name != 'pull_request' }}
- name: Dynamic Badges
uses: schneegans/dynamic-badges-action@v1.7.0
if: github.repository == 'MTSWebServices/horizon' && github.event_name == 'push'
with:
auth: ${{ secrets.AUTOMERGE_TOKEN }}
gistID: 03e73a82ecc4709934540ce8201cc3b4
filename: horizon_badge.json
label: Coverage
message: ${{ steps.coverage.outputs.coverage }}
color: ${{ steps.coverage.outputs.color }}
- name: Fail if coverage too low
if: ${{ steps.coverage.outputs.coverage < env.MIN_COVERAGE }}
run: |
echo "Coverage is below ${{ env.MIN_COVERAGE }}%!"
exit 1
- name: All done
run: echo 1