-
Notifications
You must be signed in to change notification settings - Fork 1.5k
332 lines (305 loc) · 12.4 KB
/
test-target.yml
File metadata and controls
332 lines (305 loc) · 12.4 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
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
# This is a copy of the test target workflow created for testing updates on the workflow without impacting the on used in our PRs.
# Since this workflow is used through workflow dispatch, it needs to be in master to be able tot be executed. This means that we cannot
# easily update it to test someth8ing without impacting onging runs.
name: Test Target
on:
workflow_call:
inputs:
job-name:
required: true
type: string
target:
required: true
type: string
target-env:
description: "Specific target env to run"
required: false
default: ""
type: string
platform:
required: true
type: string
runner:
required: true
type: string
repo:
required: true
type: string
python-version:
required: false
default: "3.13"
type: string
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: "datadog/agent-dev:master-py3"
type: string
agent-image-py2:
required: false
default: "datadog/agent-dev:master-py2"
type: string
agent-image-windows:
required: false
default: "datadog/agent-dev:master-py3-win-servercore"
type: string
agent-image-windows-py2:
required: false
default: "datadog/agent-dev:master-py2-win-servercore"
type: string
setup-env-vars:
required: false
default: ""
type: string
pytest-args:
description: "Arguments to pass to pytest"
required: false
type: string
default: ""
context:
description: "Context where the test is run. This is used for CI visibility descovery."
required: false
default: "standard"
type: string
step-timeout-minutes:
description: "Timeout in minutes for ddev test steps"
required: false
default: 60
type: number
defaults:
run:
shell: bash
jobs:
run:
name: "${{ inputs.job-name }}${{ inputs.target-env && format('-{0}', inputs.target-env) || '' }}"
runs-on: ${{ fromJson(inputs.runner) }}
permissions:
# needed for compute-matrix in test-target.yml
contents: read
steps:
- name: Set up Windows
if: runner.os == 'Windows'
run: |-
# Enable disk performance counters
diskperf -y
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Download workflow scripts from integrations-core
if: inputs.repo != 'core'
run: |
mkdir -p .github/workflows/scripts
curl -sL https://raw.githubusercontent.com/DataDog/integrations-core/master/.github/workflows/scripts/setup-test-env.sh -o .github/workflows/scripts/setup-test-env.sh
curl -sL https://raw.githubusercontent.com/DataDog/integrations-core/master/.github/workflows/scripts/run-unit-integration-tests.sh -o .github/workflows/scripts/run-unit-integration-tests.sh
curl -sL https://raw.githubusercontent.com/DataDog/integrations-core/master/.github/workflows/scripts/run-e2e-tests.sh -o .github/workflows/scripts/run-e2e-tests.sh
chmod +x .github/workflows/scripts/*.sh
- name: Set environment variables
# This step sets the following environment variables for the entire workflow via setup-test-env.sh:
# FORCE_COLOR
# TEST_RESULTS_BASE_DIR
# PYTHON_VERSION
# PYTHONUNBUFFERED
# SKIP_ENV_NAME
# DDEV_E2E_AGENT
# DDEV_E2E_AGENT_PY2
# DD_ENV
# DD_SERVICE
# DD_TRACE_ANALYTICS_ENABLED
# DD_CIVISIBILITY_ENABLED
# DD_CIVISIBILITY_AGENTLESS_ENABLED
# DD_CIVISIBILITY_AUTO_INSTRUMENTATION_PROVIDER
# DD_PROFILING_ENABLED
# DD_SITE
# DD_API_KEY
# MINIMUM_BASE_PACKAGE_PREFIX
# TEST_RESULTS_DIR
# DD_TAGS
# DOCKER_USERNAME
# DOCKER_ACCESS_TOKEN
# ORACLE_DOCKER_USERNAME
# ORACLE_DOCKER_PASSWORD
# DD_GITHUB_USER
# DD_GITHUB_TOKEN
# INPUT_REPO
# INPUT_TARGET
# INPUT_TARGET_ENV
# INPUT_TARGET_STR
# INPUT_PLATFORM
# INPUT_MINIMUM_BASE_PACKAGE
# INPUT_PYTEST_ARGS
# INPUT_IS_FORK
run: bash .github/workflows/scripts/setup-test-env.sh
env:
INPUT_PYTHON_VERSION: ${{ inputs.python-version }}
INPUT_TEST_PY2: ${{ inputs.test-py2 }}
INPUT_TEST_PY3: ${{ inputs.test-py3 }}
INPUT_PLATFORM: ${{ inputs.platform }}
INPUT_AGENT_IMAGE: ${{ inputs.agent-image }}
INPUT_AGENT_IMAGE_PY2: ${{ inputs.agent-image-py2 }}
INPUT_AGENT_IMAGE_WINDOWS: ${{ inputs.agent-image-windows }}
INPUT_AGENT_IMAGE_WINDOWS_PY2: ${{ inputs.agent-image-windows-py2 }}
INPUT_TARGET: ${{ inputs.target }}
INPUT_TARGET_ENV: ${{ inputs.target-env }}
INPUT_REPO: ${{ inputs.repo }}
INPUT_CONTEXT: ${{ inputs.context }}
INPUT_MINIMUM_BASE_PACKAGE: ${{ inputs.minimum-base-package }}
INPUT_JOB_NAME: "${{ inputs.job-name }}${{ inputs.target-env && format('-{0}', inputs.target-env) || '' }}"
INPUT_PYTEST_ARGS: ${{ inputs.pytest-args }}
INPUT_IS_FORK: ${{ github.event.pull_request.head.repo.fork || false }}
DD_API_KEY_SECRET: ${{ secrets.DD_API_KEY }}
SETUP_ENV_VARS: ${{ inputs.setup-env-vars }}
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
DOCKER_ACCESS_TOKEN: ${{ secrets.DOCKER_ACCESS_TOKEN }}
ORACLE_DOCKER_USERNAME: ${{ secrets.ORACLE_DOCKER_USERNAME }}
ORACLE_DOCKER_PASSWORD: ${{ secrets.ORACLE_DOCKER_PASSWORD }}
DD_GITHUB_USER: ${{ github.actor }}
DD_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Tag job for CI Visibility
# Skip on fork PRs and non-core repos since secrets won't be available
if: env.INPUT_IS_FORK != 'true' && env.INPUT_REPO == 'core'
uses: ./.github/actions/tag-job
with:
tags: ${{ env.DD_TAGS }}
dd_api_key: ${{ secrets.DD_API_KEY }}
dd_site: ${{ env.DD_SITE }}
- 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@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
with:
python-version: "${{ env.PYTHON_VERSION }}"
cache: 'pip'
- name: Restore cache
if: inputs.repo == 'core'
uses: actions/cache/restore@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3
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 upgrade_check false
ddev config set repos.${{ inputs.repo }} .
ddev config set repo ${{ inputs.repo }}
- name: Lint
timeout-minutes: ${{ inputs.step-timeout-minutes }}
run: |-
ddev test --lint ${{ inputs.target }} || {
echo "::error::Lint failed!"
echo "::error::Please update to the latest version of ddev to ensure you are using the latest linting rules and then run 'ddev test --fmt ${{ inputs.target }}' to fix formatting issues."
exit 1
}
- name: Prepare for testing
timeout-minutes: ${{ inputs.step-timeout-minutes }}
run: ddev ci setup ${{ inputs.target-env && format('{0}:{1}', inputs.target, inputs.target-env) || inputs.target }}
- name: Run Unit & Integration tests
if: inputs.latest != true
timeout-minutes: ${{ inputs.step-timeout-minutes }}
run: bash .github/workflows/scripts/run-unit-integration-tests.sh
- name: Run E2E tests
if: (inputs.repo == 'core' && !inputs.minimum-base-package) || inputs.repo != 'core'
timeout-minutes: ${{ inputs.step-timeout-minutes }}
run: bash .github/workflows/scripts/run-e2e-tests.sh
env:
INPUT_SESSION_NAME: "e2e-tests"
- name: Run benchmarks
if: inputs.benchmark
timeout-minutes: ${{ inputs.step-timeout-minutes }}
env:
DDEV_TEST_ENABLE_TRACING: "${{ inputs.repo == 'core' && (inputs.target != 'sqlserver' || inputs.platform != 'windows') && env.INPUT_IS_FORK != 'true' && '1' || '0' }}"
DD_TEST_SESSION_NAME: "benchmarks"
run: ddev test --bench --junit ${{ inputs.target-env && format('{0}:{1}', inputs.target, inputs.target-env) || inputs.target }}
- name: Run tests and verify support for the latest version
if: inputs.latest
timeout-minutes: ${{ inputs.step-timeout-minutes }}
env:
DDEV_TEST_ENABLE_TRACING: "${{ inputs.repo == 'core' && (inputs.target != 'sqlserver' || inputs.platform != 'windows') && env.INPUT_IS_FORK != 'true' && '1' || '0' }}"
DD_TEST_SESSION_NAME: "latest-tests"
run: ddev test --latest --junit ${{ inputs.target-env && format('{0}:{1}', inputs.target, inputs.target-env) || inputs.target }}
- name: Run E2E tests for the latest version
if: inputs.latest
timeout-minutes: ${{ inputs.step-timeout-minutes }}
run: bash .github/workflows/scripts/run-e2e-tests.sh
env:
# Override INPUT_TARGET to include :latest suffix
INPUT_TARGET: "${{ inputs.target }}:latest"
INPUT_SESSION_NAME: "latest-e2e-tests"
INPUT_IS_LATEST: "true"
- 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@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
with:
name: "${{ env.MINIMUM_BASE_PACKAGE_PREFIX }}test-results-${{ inputs.target }}${{ inputs.target-env && format('-{0}', inputs.target-env) || '' }}-${{ inputs.platform }}"
path: "${{ env.TEST_RESULTS_BASE_DIR }}"
- name: Upload local_clone debug info (ddev only)
if: always() && inputs.target == 'ddev'
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
with:
name: "${{ env.MINIMUM_BASE_PACKAGE_PREFIX }}local-clone-debug-${{ inputs.platform }}"
path: "local_clone_debug.txt"
if-no-files-found: ignore
- name: Upload coverage data as artifact
if: >
!github.event.repository.private &&
always() &&
inputs.pytest-args != '-m flaky'
# Flaky tests will have low coverage, don't include in artifacts to avoid pipeline issues
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
with:
name: "${{ env.MINIMUM_BASE_PACKAGE_PREFIX }}coverage-${{ inputs.target }}${{ inputs.target-env && format('-{0}', inputs.target-env) || '' }}-${{ inputs.platform }}"
path: "${{ inputs.target }}/coverage.xml"
if-no-files-found: ignore