-
Notifications
You must be signed in to change notification settings - Fork 1.5k
419 lines (388 loc) · 15.7 KB
/
test-target.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
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
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
# "target" refers to the integration (a.k.a. check) that we want to test.
# This action is a template that we reuse in other actions such as test-all or pr-test.
name: Test target
on:
workflow_call:
inputs:
job-name:
required: true
type: string
target:
required: true
type: string
platform:
required: true
type: string
runner:
required: true
type: string
repo:
required: true
type: string
python-version:
required: false
default: ""
type: string
standard:
required: false
default: false
type: boolean
benchmark:
required: false
default: false
type: boolean
latest:
required: false
default: false
type: boolean
minimum-base-package:
required: false
default: false
type: boolean
# integrations-core repo no longer tests Python 2, only Python 3.
# We keep the options in the workflow for community and marketplace partners.
# They may still continue to test Python 2 and Agent 6.
test-py2:
required: false
default: false
type: boolean
test-py3:
required: false
default: true
type: boolean
agent-image:
required: false
default: ""
type: string
agent-image-py2:
required: false
default: ""
type: string
agent-image-windows:
required: false
default: ""
type: string
agent-image-windows-py2:
required: false
default: ""
type: string
traces-artifact-name:
required: false
default: "traces"
type: string
trace-agent-port:
required: false
default: "8126"
type: string
setup-env-vars:
required: false
default: ""
type: string
pytest-args:
description: "Arguments to pass to pytest"
required: false
type: string
default: ""
defaults:
run:
shell: bash
jobs:
run:
name: "${{ inputs.job-name }}"
runs-on: ${{ fromJson(inputs.runner) }}
env:
FORCE_COLOR: "1"
PYTHON_VERSION: "${{ inputs.python-version || '3.12' }}"
PYTHON_FILTER: "${{ (inputs.test-py2 && !inputs.test-py3) && '2.7' || (!inputs.test-py2 && inputs.test-py3) && (inputs.python-version || '3.12') || '' }}"
SKIP_ENV_NAME: "${{ (inputs.test-py2 && !inputs.test-py3) && 'py3.*' || (!inputs.test-py2 && inputs.test-py3) && 'py2.*' || '' }}"
# Windows E2E requires Windows containers
DDEV_E2E_AGENT: "${{ inputs.platform == 'windows' && (inputs.agent-image-windows || 'datadog/agent-dev:master-py3-win-servercore') || inputs.agent-image }}"
DDEV_E2E_AGENT_PY2: "${{ inputs.platform == 'windows' && (inputs.agent-image-windows-py2 || 'datadog/agent-dev:master-py2-win-servercore') || inputs.agent-image-py2 }}"
# Test results for later processing
TEST_RESULTS_BASE_DIR: "test-results"
# Tracing to monitor our test suite
DD_ENV: "ci"
DD_SERVICE: "ddev-integrations-${{ inputs.repo }}"
DD_TAGS: "team:agent-integrations,platform:${{ inputs.platform }},integration:${{ inputs.target }}"
DD_TRACE_ANALYTICS_ENABLED: "true"
# Capture traces for a separate job to do the submission
TRACE_CAPTURE_BASE_DIR: "trace-captures"
TRACE_CAPTURE_LOG: "trace-captures/output.log"
steps:
- name: Set environment variables with sanitized paths
run: |
# We want to replace leading dots as they will make directories hidden, which will cause them to be ignored by upload-artifact and EnricoMi/publish-unit-test-result-action
JOB_NAME=$(echo "${{ inputs.job-name }}" | sed 's/^\./Dot/')
echo "TEST_RESULTS_DIR=$TEST_RESULTS_BASE_DIR/$JOB_NAME" >> $GITHUB_ENV
echo "TRACE_CAPTURE_FILE=$TRACE_CAPTURE_BASE_DIR/$JOB_NAME" >> $GITHUB_ENV
- name: Set up Windows
if: runner.os == 'Windows'
run: |-
# Enable disk performance counters
diskperf -y
- uses: actions/checkout@v4
- name: Set up Python 2.7
if: inputs.test-py2
run: |
if [ "$RUNNER_OS" == "Linux" ]; then
sudo apt update
sudo apt install python2 python2-dev
sudo update-alternatives --install /usr/bin/python python /usr/bin/python2 1
elif [ "$RUNNER_OS" == "Windows" ]; then
choco install python2
else
echo "$RUNNER_OS not supported"
exit 1
fi
shell: bash
- name: Set up Python ${{ env.PYTHON_VERSION }}
uses: actions/setup-python@v5
with:
python-version: "${{ env.PYTHON_VERSION }}"
cache: 'pip'
- name: Restore cache
if: inputs.repo == 'core'
uses: actions/cache/restore@v4
with:
path: ${{ runner.os == 'Windows' && '~\AppData\Local\pip\Cache' || runner.os == 'macOS' && '~/Library/Caches/pip' || '~/.cache/pip' }}
key: >-
${{ format(
'v01-python-{0}-{1}-{2}-{3}',
env.pythonLocation,
hashFiles('datadog_checks_base/pyproject.toml'),
hashFiles('datadog_checks_dev/pyproject.toml'),
hashFiles('ddev/pyproject.toml')
)}}
restore-keys: |-
v01-python-${{ env.pythonLocation }}
- name: Install ddev from local folder
if: inputs.repo == 'core'
run: |-
pip install -e ./datadog_checks_dev[cli]
pip install -e ./ddev
- name: Install ddev from PyPI
if: inputs.repo != 'core'
run: pip install ddev
- name: Configure ddev
run: |-
ddev config set repos.${{ inputs.repo }} .
ddev config set repo ${{ inputs.repo }}
- name: Lint
run: ddev test --lint ${{ inputs.target }}
- name: Prepare for testing
env: >-
${{ fromJson(inputs.setup-env-vars || format(
'{{
"PYTHONUNBUFFERED": "1",
"DOCKER_USERNAME": "{0}",
"DOCKER_ACCESS_TOKEN": "{1}",
"ORACLE_DOCKER_USERNAME": "{2}",
"ORACLE_DOCKER_PASSWORD": "{3}",
"SINGLESTORE_LICENSE": "{4}",
"DD_GITHUB_USER": "{5}",
"DD_GITHUB_TOKEN": "{6}"
}}',
secrets.DOCKER_USERNAME,
secrets.DOCKER_ACCESS_TOKEN,
secrets.ORACLE_DOCKER_USERNAME,
secrets.ORACLE_DOCKER_PASSWORD,
secrets.SINGLESTORE_LICENSE,
github.actor,
secrets.GITHUB_TOKEN
))}}
run: ddev ci setup ${{ inputs.target }}
- name: Set up trace capturing
if: inputs.repo == 'core'
env:
PYTHONUNBUFFERED: "1"
run: |-
mkdir "${{ env.TRACE_CAPTURE_BASE_DIR }}"
python .ddev/ci/scripts/traces.py capture --port "${{ inputs.trace-agent-port }}" --record-file "${{ env.TRACE_CAPTURE_FILE }}" > "${{ env.TRACE_CAPTURE_LOG }}" 2>&1 &
- name: Run Unit & Integration tests
if: inputs.standard && !inputs.minimum-base-package
env:
DDEV_TEST_ENABLE_TRACING: "${{ inputs.repo == 'core' && '1' || '0' }}"
run: |
if [ '${{ inputs.pytest-args }}' = '-m flaky' ]; then
set +e # Disable immediate exit
ddev test --cov --junit ${{ inputs.target }} -- ${{ inputs.pytest-args }} -k "not fips"
exit_code=$?
if [ $exit_code -eq 5 ]; then
# Flaky test count can be zero, this is done to avoid pipeline failure
echo "No tests were collected."
exit 0
else
exit $exit_code
fi
else
ddev test --cov --junit ${{ inputs.target }} ${{ inputs.pytest-args != '' && format('-- {0} -k "not fips"', inputs.pytest-args) || '-- -k "not fips"' }}
fi
- name: Run Unit & Integration tests with minimum version of base package
if: inputs.standard && inputs.minimum-base-package
run: |
if [ '${{ inputs.pytest-args }}' = '-m flaky' ]; then
set +e # Disable immediate exit
ddev test --compat --recreate --junit ${{ inputs.target }} -- ${{ inputs.pytest-args }} -k "not fips"
exit_code=$?
if [ $exit_code -eq 5 ]; then
# Flaky test count can be zero, this is done to avoid pipeline failure
echo "No tests were collected."
exit 0
else
exit $exit_code
fi
else
ddev test --compat --recreate --junit ${{ inputs.target }} ${{ inputs.pytest-args != '' && format('-- {0} -k "not fips"', inputs.pytest-args) || '-- -k "not fips"' }}
fi
- name: Run E2E tests with latest base package
if: inputs.standard && inputs.repo == 'core' && !inputs.minimum-base-package
env:
DD_API_KEY: "${{ secrets.DD_API_KEY }}"
run: |
# '-- all' is passed for e2e tests if pytest args are provided
# This is done to avoid ddev from interpreting the arguments as environments
# instead of pytest-args, because by default if no environment is provided
# after -- it will run all environments. So when pytests args are provided
# ddev will interpret '-m' as an environment to run the e2e test on and fails
# This is not required when no pytest args are provided and it will run all environments
# by default
if [ '${{ inputs.pytest-args }}' = '-m flaky' ]; then
set +e # Disable immediate exit
ddev env test --base --new-env --junit ${{ inputs.target }} -- all ${{ inputs.pytest-args }} -k "not fips"
exit_code=$?
if [ $exit_code -eq 5 ]; then
# Flaky test count can be zero, this is done to avoid pipeline failure
echo "No tests were collected."
exit 0
else
exit $exit_code
fi
elif [ '${{ inputs.pytest-args }}' = '-m "not flaky"' ]; then
set +e # Disable immediate exit
ddev env test --base --new-env --junit ${{ inputs.target }} -- all ${{ inputs.pytest-args }} -k "not fips"
exit_code=$?
if [ $exit_code -eq 5 ]; then
# Flaky test count can be zero, this is done to avoid pipeline failure
echo "No tests were collected."
exit 0
else
exit $exit_code
fi
else
ddev env test --base --new-env --junit ${{ inputs.target }} ${{ inputs.pytest-args != '' && format('-- all {0} -k "not fips"', inputs.pytest-args) || '-- all -k "not fips"' }}
fi
- name: Run E2E tests
if: inputs.standard && inputs.repo != 'core'
env:
DD_API_KEY: "${{ secrets.DD_API_KEY }}"
run: |
# '-- all' is passed for e2e tests if pytest args are provided
# This is done to avoid ddev from interpreting the arguments as environments
# instead of pytest-args, because by default if no environment is provided
# after -- it will run all environments. So when pytests args are provided
# ddev will interpret '-m' as an environment to run the e2e test on and fails
# This is not required when no pytest args are provided and it will run all environments
# by default
if [ '${{ inputs.pytest-args }}' = '-m flaky' ]; then
set +e # Disable immediate exit
ddev env test --new-env --junit ${{ inputs.target }} -- all ${{ inputs.pytest-args }} -k "not fips"
exit_code=$?
if [ $exit_code -eq 5 ]; then
# Flaky test count can be zero, this is done to avoid pipeline failure
echo "No tests were collected."
exit 0
else
exit $exit_code
fi
elif [ '${{ inputs.pytest-args }}' = '-m "not flaky"' ]; then
set +e # Disable immediate exit
ddev env test --new-env --junit ${{ inputs.target }} -- all ${{ inputs.pytest-args }} -k "not fips"
exit_code=$?
if [ $exit_code -eq 5 ]; then
# Flaky test count can be zero, this is done to avoid pipeline failure
echo "No tests were collected."
exit 0
else
exit $exit_code
fi
else
ddev env test --new-env --junit ${{ inputs.target }} ${{ inputs.pytest-args != '' && format('-- all {0} -k "not fips"', inputs.pytest-args) || '-- all -k "not fips"' }}
fi
- name: Run benchmarks
if: inputs.benchmark
run: ddev test --bench --junit ${{ inputs.target }}
- name: Run tests and verify support for the latest version
if: inputs.latest
run: ddev test --latest --junit ${{ inputs.target }}
- name: Run E2E tests for the latest version
if: inputs.latest
env:
DD_API_KEY: "${{ secrets.DD_API_KEY }}"
DDEV_TEST_ENABLE_TRACING: "${{ inputs.repo == 'core' && '1' || '0' }}"
run: |
# '-- all' is passed for e2e tests if pytest args are provided
# This is done to avoid ddev from interpreting the arguments as environments
# instead of pytest-args, because by default if no environment is provided
# after -- it will run all environments. So when pytests args are provided
# ddev will interpret '-m' as an environment to run the e2e test on and fails
# This is not required when no pytest args are provided and it will run all environments
# by default
if [ '${{ inputs.pytest-args }}' = '-m flaky' ]; then
set +e # Disable immediate exit
ddev env test --base --new-env --junit ${{ inputs.target }}:latest -- all ${{ inputs.pytest-args }} -k "not fips"
exit_code=$?
if [ $exit_code -eq 5 ]; then
# Flaky test count can be zero, this is done to avoid pipeline failure
echo "No tests were collected."
exit 0
else
exit $exit_code
fi
elif [ '${{ inputs.pytest-args }}' = '-m "not flaky"' ]; then
set +e # Disable immediate exit
ddev env test --base --new-env --junit ${{ inputs.target }}:latest -- all ${{ inputs.pytest-args }}
exit_code=$?
if [ $exit_code -eq 5 ]; then
# Flaky test count can be zero, this is done to avoid pipeline failure
echo "No tests were collected."
exit 0
else
exit $exit_code
fi
else
ddev env test --base --new-env --junit ${{ inputs.target }}:latest ${{ inputs.pytest-args != '' && format('-- all {0} -k "not fips"', inputs.pytest-args) || '-- all -k "not fips"' }}
fi
- name: View trace log
if: inputs.repo == 'core' && always()
run: cat "${{ env.TRACE_CAPTURE_LOG }}"
- name: Upload captured traces
if: inputs.repo == 'core' && always()
uses: actions/upload-artifact@v4
with:
name: "${{ inputs.traces-artifact-name }}-${{ inputs.target }}-${{ inputs.platform }}"
path: "${{ env.TRACE_CAPTURE_FILE }}"
- name: Finalize test results
if: always()
run: |-
mkdir -p "${{ env.TEST_RESULTS_DIR }}"
if [[ -d ${{ inputs.target }}/.junit ]]; then
mv ${{ inputs.target }}/.junit/*.xml "${{ env.TEST_RESULTS_DIR }}"
fi
- name: Upload test results
if: always()
uses: actions/upload-artifact@v4
with:
name: "test-results-${{ inputs.target }}-${{ inputs.platform }}"
path: "${{ env.TEST_RESULTS_BASE_DIR }}"
- name: Upload coverage data
if: >
inputs.standard &&
!github.event.repository.private &&
always() &&
inputs.pytest-args != '-m flaky'
# Flaky tests will have low coverage, don't upload it to avoid pipeline failure
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: "${{ inputs.target }}/coverage.xml"
flags: "${{ inputs.target }}"