-
Notifications
You must be signed in to change notification settings - Fork 220
224 lines (200 loc) · 7.08 KB
/
test.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
name: test # The name must be the same as in test-docs.yml
on:
workflow_call:
inputs:
full-matrix:
description: "Run the full matrix"
required: true
type: boolean
ref:
description: "The git ref of elastic/apm-agent-python to run test workflow from."
required: false
type: string
pull_request:
paths-ignore:
- "**/*.md"
- "**/*.asciidoc"
push:
branches:
- main
paths-ignore:
- "**/*.md"
- "**/*.asciidoc"
schedule:
- cron: "0 2 * * *"
workflow_dispatch:
inputs:
full-matrix:
description: "Run the full matrix"
required: true
type: boolean
permissions:
contents: read
jobs:
build-distribution:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: ./.github/actions/build-distribution
create-matrix:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.generate.outputs.matrix }}
data: ${{ steps.split.outputs.data }}
chunks: ${{ steps.split.outputs.chunks }}
steps:
- uses: actions/checkout@v4
with:
ref: ${{ inputs.ref || github.ref }}
- id: generate
uses: elastic/apm-pipeline-library/.github/actions/version-framework@current
with:
# Use .ci/.matrix_python_full.yml if it's a scheduled workflow, otherwise use .ci/.matrix_python.yml
versionsFile: .ci/.matrix_python${{ (github.event_name == 'schedule' || github.event_name == 'push' || inputs.full-matrix) && '_full' || '' }}.yml
# Use .ci/.matrix_framework_full.yml if it's a scheduled workflow, otherwise use .ci/.matrix_framework.yml
frameworksFile: .ci/.matrix_framework${{ (github.event_name == 'schedule' || github.event_name == 'push' || inputs.full-matrix) && '_full' || '' }}.yml
excludedFile: .ci/.matrix_exclude.yml
- name: Split matrix
shell: python
id: split
run: |
import os
import json
def split(lst, n):
return [lst[i::n] for i in range(n)]
matrix = json.loads(os.environ['GENERATED_MATRIX'])
# Using the number 4 because the full matrix has roughly 400+ items
# Hence, it is split into chunks of size ~100
# We are doing this because the matrix in GH actions has a max limit of 256
chunks = split(matrix['include'], 4)
chunks_json = json.dumps(chunks)
with open(os.environ['GITHUB_OUTPUT'], 'a') as f:
print(f'chunks={chunks_json}', file=f)
env:
GENERATED_MATRIX: ${{ steps.generate.outputs.matrix }}
chunks-0:
needs: create-matrix
uses: ./.github/workflows/run-matrix.yml
with:
include: ${{ toJSON(fromJSON(needs.create-matrix.outputs.chunks)[0]) }}
chunks-1:
needs: create-matrix
uses: ./.github/workflows/run-matrix.yml
with:
include: ${{ toJSON(fromJSON(needs.create-matrix.outputs.chunks)[1]) }}
chunks-2:
needs: create-matrix
uses: ./.github/workflows/run-matrix.yml
with:
include: ${{ toJSON(fromJSON(needs.create-matrix.outputs.chunks)[2]) }}
chunks-3:
needs: create-matrix
uses: ./.github/workflows/run-matrix.yml
with:
include: ${{ toJSON(fromJSON(needs.create-matrix.outputs.chunks)[3]) }}
windows:
name: "windows (version: ${{ matrix.version }}, framework: ${{ matrix.framework }}, asyncio: ${{ matrix.asyncio }})"
runs-on: windows-2019
strategy:
fail-fast: false
matrix:
include:
# - version: "3.6"
# framework: "none"
# asyncio: "true"
# - version: "3.7"
# framework: none
# asyncio: true
- version: "3.8"
framework: none
asyncio: true
- version: "3.9" # waiting for greenlet to have binary wheels for 3.9
framework: none
asyncio: true
env:
VERSION: ${{ matrix.version }}
FRAMEWORK: ${{ matrix.framework }}
ASYNCIO: ${{ matrix.asyncio }}
steps:
- uses: actions/checkout@v4
with:
ref: ${{ inputs.ref || github.ref }}
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.version }}
cache: pip
cache-dependency-path: "tests/requirements/reqs-${{ matrix.framework }}.txt"
- name: Install tools
run: .\scripts\install-tools.bat
- name: Run tests
run: .\scripts\run-tests.bat
- if: success() || failure()
name: Upload JUnit Test Results
uses: actions/upload-artifact@v3
with:
name: test-results
path: "**/*-python-agent-junit.xml"
- if: success() || failure()
name: Upload Coverage Reports
uses: actions/upload-artifact@v3
with:
name: coverage-reports
path: "**/.coverage*"
# This job is here to have a single status check that can be set as required.
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idneeds
# If a run contains a series of jobs that need each other, a failure applies to all jobs in the dependency chain from the point of failure onwards.
all:
if: always()
runs-on: ubuntu-latest
needs:
- chunks-0
- chunks-1
- chunks-2
- chunks-3
- windows
steps:
- id: check
uses: elastic/apm-pipeline-library/.github/actions/check-dependent-jobs@current
with:
needs: ${{ toJSON(needs) }}
- run: ${{ steps.check.outputs.isSuccess }}
- if: failure() && (github.event_name == 'schedule' || github.event_name == 'push')
uses: elastic/apm-pipeline-library/.github/actions/notify-build-status@current
with:
status: ${{ steps.check.outputs.status }}
vaultUrl: ${{ secrets.VAULT_ADDR }}
vaultRoleId: ${{ secrets.VAULT_ROLE_ID }}
vaultSecretId: ${{ secrets.VAULT_SECRET_ID }}
slackChannel: "#apm-agent-python"
coverage:
name: Combine & check coverage.
needs: all
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ inputs.ref || github.ref }}
- uses: actions/setup-python@v5
with:
# Use latest Python, so it understands all syntax.
python-version: 3.11
- run: python -Im pip install --upgrade coverage[toml]
- uses: actions/download-artifact@v3
with:
name: coverage-reports
- name: Combine coverage & fail if it's <84%.
run: |
python -Im coverage combine
python -Im coverage html --skip-covered --skip-empty
# Report and write to summary.
python -Im coverage report | sed 's/^/ /' >> $GITHUB_STEP_SUMMARY
# Report again and fail if under 84%.
python -Im coverage report --fail-under=84
- name: Upload HTML report
uses: actions/upload-artifact@v4
with:
name: html-coverage-report
path: htmlcov
- uses: geekyeggo/delete-artifact@24928e75e6e6590170563b8ddae9fac674508aa1
with:
name: coverage-reports