272 lines (244 loc) · 8.59 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
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
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
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.11' }}"
PYTHON_FILTER: "${{ (inputs.test-py2 && !inputs.test-py3) && '2.7' || (!inputs.test-py2 && inputs.test-py3) && (inputs.python-version || '3.11') || '' }}"
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"
TEST_RESULTS_DIR: ".test-results/${{ inputs.job-name }}"
# 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_FILE: ".trace-captures/${{ inputs.job-name }}"
TRACE_CAPTURE_LOG: ".trace-captures/output.log"
steps:
- 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 }}"
- 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
# TODO: use the more descriptive `--lint` variant when ddev is released
run: ddev test -s ${{ 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: ddev test --cov --junit ${{ inputs.target }}
- name: Run Unit & Integration tests with minimum version of base package
if: inputs.standard && inputs.minimum-base-package
run: ddev test --compat --recreate --junit ${{ inputs.target }}
- 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: ddev env test --base --new-env --junit ${{ inputs.target }}
- name: Run E2E tests
if: inputs.standard && inputs.repo != 'core'
env:
DD_API_KEY: "${{ secrets.DD_API_KEY }}"
run: ddev env test --new-env --junit ${{ inputs.target }}
- 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: ddev env test --base --new-env --junit ${{ inputs.target }}:latest
- 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()
uses: codecov/codecov-action@v4
with:
files: "${{ inputs.target }}/coverage.xml"
flags: "${{ inputs.target }}"