-
Notifications
You must be signed in to change notification settings - Fork 4
246 lines (198 loc) · 7.13 KB
/
test.yml
File metadata and controls
246 lines (198 loc) · 7.13 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
name: Test
on:
- pull_request
jobs:
base_coverage:
continue-on-error: true
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.base_ref }}
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.12
- name: Install Dependencies
run: pip install -e . -r dev-requirements.txt
- name: Test with pytest
run: |
pytest --cov=src --cov-report=lcov
mv coverage.lcov base-coverage.lcov
- name: Upload code coverage for base branch
uses: actions/upload-artifact@v4
with:
name: base-coverage.lcov
path: ./base-coverage.lcov
test:
runs-on: ubuntu-latest
strategy:
matrix:
python: ["3.10", "3.11", "3.12", "3.13"]
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python }}
- name: Install Dependencies
run: pip install -e . -r dev-requirements.txt
- name: Print installed packages
run: pip freeze
- name: Lint with Ruff
run: ruff check .
- name: Format with Ruff
run: ruff format --check .
- name: Check spelling
run: codespell .
- name: Lint with Flake8 (for docstrings)
if: ${{ contains('3.12,3.13', matrix.python) }}
# Flake8 crashes on Python < 3.12, so we exclude those versions.
# Flake8 is primarily here to lint the docstrings, which
# does not need to happen under multiple versions.
run: flake8 src
- name: Test with pytest
run: pytest --cov=src --cov-report=lcov
- name: Upload code coverage
uses: actions/upload-artifact@v4
with:
name: coverage-${{ matrix.python }}
path: ./coverage.lcov
- name: Analyse with MyPy
run: mypy
test-with-unpinned-deps:
runs-on: ubuntu-latest
strategy:
matrix:
python: ["3.10", "3.11", "3.12", "3.13"]
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python }}
- name: Install Dependencies
run: pip install -e .[dev]
- name: Print installed packages
run: pip freeze
- name: Lint with Ruff
run: ruff check .
- name: Format with Ruff
if: success() || failure()
run: ruff format --check .
- name: Analyse with MyPy
if: success() || failure()
run: mypy
- name: Test with pytest
if: success() || failure()
run: pytest --cov=src --cov-report=lcov
- name: Check quickstart, including installation
if: success() || failure()
run: bash ./docs/source/quickstart/test_quickstart_example.sh
coverage:
runs-on: ubuntu-latest
needs: [base_coverage, test]
steps:
- name: Download code coverage report
uses: actions/download-artifact@v4
with:
name: coverage-3.12
- name: Download code coverage report for base branch
id: download-base-coverage
continue-on-error: true
uses: actions/download-artifact@v4
with:
name: base-coverage.lcov
- name: Generate Code Coverage report
# Note, due to continue on error (to make job pass) we need to check the
# Status of the step directly not just use success() or failure()
if: steps.download-base-coverage.outcome == 'success'
id: code-coverage
uses: barecheck/code-coverage-action@v1
with:
barecheck-github-app-token: ${{ secrets.BARECHECK_GITHUB_APP_TOKEN }}
lcov-file: "./coverage.lcov"
base-lcov-file: "./base-coverage.lcov"
minimum-ratio: 0
send-summary-comment: true
show-annotations: "warning"
- name: Generate Code Coverage report if base job fails
if: steps.download-base-coverage.outcome == 'failure'
id: code-coverage-without-base
uses: barecheck/code-coverage-action@v1
with:
barecheck-github-app-token: ${{ secrets.BARECHECK_GITHUB_APP_TOKEN }}
lcov-file: "./coverage.lcov"
minimum-ratio: 0
send-summary-comment: true
show-annotations: "warning"
test-against-ofm-v3:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ../openflexure-microscope-server/
env:
REF: v3
steps: &test-against-ofm-steps
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Clone OpenFlexure Microscope Server
working-directory: .. # This step creates the default working directory
run: |
git clone https://gitlab.com/openflexure/openflexure-microscope-server.git
- name: Check out OpenFlexure Microscope Server
run: "git checkout $REF"
- name: Install OpenFlexure Microscope Server
run: "pip install -e ../openflexure-microscope-server/[dev]"
- name: Install LabThings-FastAPI
run: "pip install -e ../labthings-fastapi"
- name: Print installed packages
run: "pip freeze"
- name: Configure Git identity
run: |
git config --global user.name "Sir Unit of Test"
git config --global user.email "bogus@email.com"
- name: Pull OFM web app
run: python ./pull_webapp.py
- name: Run OFM unit tests
run: pytest
- name: Run OFM integration tests
run: pytest tests/integration_tests
- name: Run OFM lifecycle test
run: tests/lifecycle_test/testfile.py
- name: Type check with `mypy`
run: mypy src
analyse-pr-description:
# This job uses a regex to match the feature branch specified in the
# PR description. If there isn't one, it should be an empty string.
runs-on: ubuntu-latest
outputs:
feature-branch: ${{ steps.regex-match.outputs.group1 }}
steps:
- name: Check the pull request body for an OFM feature branch
id: regex-match
uses: KyoriPowered/action-regex-match@v3
with:
text: ${{ github.event.pull_request.body }}
regex: '^\s*OFM[ \-_]Feature[ \-_]Branch:\s*([\w\-./]+)'
flags: 'mi'
- name: Print the recovered branch
run: |
echo "Matched string: '${{ steps.regex-match.outputs.match }}'"
echo "Matched group: '${{ steps.regex-match.outputs.group1 }}'"
test-against-ofm-feature-branch:
# This job uses the feature branch found by `analyse-pr-description`.
# If that job didn't find a feature branch, it will be an empty string
# so this job won't run.
needs: analyse-pr-description
if: needs.analyse-pr-description.outputs.feature-branch != ''
runs-on: ubuntu-latest
continue-on-error: true
defaults:
run:
working-directory: ../openflexure-microscope-server/
env:
REF: ${{ needs.analyse-pr-description.outputs.feature-branch }}
steps: *test-against-ofm-steps