-
Notifications
You must be signed in to change notification settings - Fork 2.7k
307 lines (265 loc) · 9.67 KB
/
tests.yml
File metadata and controls
307 lines (265 loc) · 9.67 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
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
# If you change this name also do it in ci_metrics.yml
name: Tests
# The workflow will always run, but the actual tests will only execute when:
# - The workflow is triggered manually.
# - The push is to main or a release branch.
# - There are changes to relevant files on a pull request.
# Note: If no conditions are met, the workflow will complete successfully without running tests
# to satisfy Branch Protection rules.
on:
workflow_dispatch: # Activate this workflow manually
push:
branches:
- main
# release branches have the form v1.9.x
- "v[0-9].*[0-9].x"
# when we push, we do not need to satisfy Branch Protection rules, so we can ignore PRs that just change docs
paths-ignore:
- 'docs/**'
- 'docs-website/**'
pull_request:
types:
- opened
- reopened
- synchronize
env:
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
CORE_AZURE_CS_ENDPOINT: ${{ secrets.CORE_AZURE_CS_ENDPOINT }}
CORE_AZURE_CS_API_KEY: ${{ secrets.CORE_AZURE_CS_API_KEY }}
AZURE_OPENAI_API_KEY: ${{ secrets.AZURE_OPENAI_API_KEY }}
AZURE_OPENAI_ENDPOINT: ${{ secrets.AZURE_OPENAI_ENDPOINT }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
HF_API_TOKEN: ${{ secrets.HUGGINGFACE_API_KEY }}
PYTHON_VERSION: "3.10"
HATCH_VERSION: "1.16.5"
jobs:
check-if-changed:
# This job checks if the relevant files have been changed.
# We check for changes in the check-if-changed job instead of using paths/paths-ignore at workflow level.
# This ensures the "Mark tests as completed" job always runs, which is required by Branch Protection rules.
name: Check if changed
runs-on: ubuntu-slim
permissions:
pull-requests: read
# Specifying outputs is not needed to make the job work, but only to comply with actionlint
outputs:
changes: ${{ steps.changes.outputs.changes }}
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Check for changed code
id: changes
uses: dorny/paths-filter@fbd0ab8f3e69293af611ebaee6363fc25e6d187d # v4.0.1
with:
filters: |
changes:
- "haystack/**/*.py"
- "test/**/*.py"
- "pyproject.toml"
- ".github/utils/*.py"
- "scripts/*.py"
format:
needs: check-if-changed
# Run tests if: manual trigger, push to main/release, or relevant files changed
if: |
github.event_name == 'workflow_dispatch' ||
github.event_name == 'push' ||
(needs.check-if-changed.outputs.changes == 'true')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
with:
python-version: "${{ env.PYTHON_VERSION }}"
- name: Install Hatch
run: pip install hatch==${{ env.HATCH_VERSION }}
- name: Ruff - check format and linting
run: hatch run fmt-check
- name: Check presence of license header
run: docker run --rm -v "$(pwd):/github/workspace" ghcr.io/korandoru/hawkeye check
check-imports:
needs: format
runs-on: ubuntu-slim
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
with:
python-version: "${{ env.PYTHON_VERSION }}"
- name: Install Hatch
run: pip install hatch==${{ env.HATCH_VERSION }}
- name: Check imports
run: hatch run python .github/utils/check_imports.py
unit-tests:
name: Unit / ${{ matrix.os }}
needs: format
timeout-minutes: 30
strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest
- windows-latest
- macos-latest
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
with:
python-version: "${{ env.PYTHON_VERSION }}"
- name: Install Hatch
id: hatch
shell: bash
run: |
pip install hatch==${{ env.HATCH_VERSION }}
echo "env=$(hatch env find test)" >> "$GITHUB_OUTPUT"
- name: Run
run: hatch run test:unit
- uses: actions/cache/save@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
id: cache
if: matrix.os == 'macos-latest'
with:
path: ${{ steps.hatch.outputs.env }}
key: ${{ runner.os }}-${{ github.sha }}
- name: Coveralls
# We upload only coverage for ubuntu as handling both os
# complicates the workflow too much for little to no gain
if: matrix.os == 'ubuntu-latest'
uses: coverallsapp/github-action@5cbfd81b66ca5d10c19b062c04de0199c215fb6e # v2.3.7
continue-on-error: true
with:
path-to-lcov: coverage.xml
mypy:
needs: unit-tests
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
# With the default value of 1, there are corner cases where tj-actions/changed-files
# fails with a `no merge base` error
fetch-depth: 0
- name: Get changed files
id: files
uses: tj-actions/changed-files@22103cc46bda19c2b464ffe86db46df6922fd323 # v47.0.5
with:
files: |
**/*.py
pyproject.toml
files_ignore: |
test/**
.github/**
scripts/**
- uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
if: steps.files.outputs.any_changed == 'true'
with:
python-version: "${{ env.PYTHON_VERSION }}"
- name: Install Hatch
id: hatch
if: steps.files.outputs.any_changed == 'true'
run: |
pip install hatch==${{ env.HATCH_VERSION }}
echo "env=$(hatch env find test)" >> "$GITHUB_OUTPUT"
- name: Mypy
if: steps.files.outputs.any_changed == 'true'
run: |
mkdir .mypy_cache
hatch run test:types
integration-tests-linux:
name: Integration / ubuntu-latest
needs: unit-tests
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
with:
python-version: "${{ env.PYTHON_VERSION }}"
- name: Install Hatch
id: hatch
shell: bash
run: |
pip install hatch==${{ env.HATCH_VERSION }}
echo "env=$(hatch env find test)" >> "$GITHUB_OUTPUT"
- name: Run
run: hatch run test:integration-only-fast
integration-tests-macos:
name: Integration / macos-latest
needs: unit-tests
runs-on: macos-latest
timeout-minutes: 30
env:
HAYSTACK_MPS_ENABLED: false
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
with:
python-version: "${{ env.PYTHON_VERSION }}"
- name: Install Hatch
id: hatch
shell: bash
run: |
pip install hatch==${{ env.HATCH_VERSION }}
echo "env=$(hatch env find test)" >> "$GITHUB_OUTPUT"
- uses: actions/cache/restore@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
id: cache
with:
path: ${{ steps.hatch.outputs.env }}
key: ${{ runner.os }}-${{ github.sha }}
- name: Run
run: hatch run test:integration-only-fast
integration-tests-windows:
name: Integration / windows-latest
needs: unit-tests
runs-on: windows-latest
timeout-minutes: 30
env:
HAYSTACK_XPU_ENABLED: false
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
with:
python-version: "${{ env.PYTHON_VERSION }}"
- name: Install Hatch
id: hatch
shell: bash
run: |
pip install hatch==${{ env.HATCH_VERSION }}
echo "env=$(hatch env find test)" >> "$GITHUB_OUTPUT"
- name: Run
run: hatch run test:integration-only-fast
notify-slack-on-failure:
if: failure() && github.ref_name == 'main'
needs:
- check-imports
- mypy
- integration-tests-linux
- integration-tests-macos
- integration-tests-windows
runs-on: ubuntu-slim
steps:
- uses: deepset-ai/notify-slack-action@3cda73b77a148f16f703274198e7771340cf862b # v1
with:
slack-webhook-url: ${{ secrets.SLACK_WEBHOOK_URL_NOTIFICATIONS }}
tests-completed:
# This job always runs and succeeds if all tests succeed or are skipped. It is required by Branch Protection rules.
name: Mark tests as completed
runs-on: ubuntu-slim
if: ${{ always() && !cancelled() }}
needs:
- check-imports
- mypy
- integration-tests-linux
- integration-tests-macos
- integration-tests-windows
steps:
- name: Mark tests as completed
run: |
if [ "${{ needs.check-imports.result }}" = "failure" ] ||
[ "${{ needs.mypy.result }}" = "failure" ] ||
[ "${{ needs.integration-tests-linux.result }}" = "failure" ] ||
[ "${{ needs.integration-tests-macos.result }}" = "failure" ] ||
[ "${{ needs.integration-tests-windows.result }}" = "failure" ]; then
echo "Tests failed!"
exit 1
else
echo "Tests completed!"
fi