forked from espressif/esp-modbus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
347 lines (319 loc) · 9.87 KB
/
.gitlab-ci.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
stages:
- build
- target_test
- deploy
variables:
# System environment
ESP_DOCS_ENV_IMAGE: "$CI_DOCKER_REGISTRY/esp-idf-doc-env-v5.3:1-1"
ESP_DOCS_PATH: "$CI_PROJECT_DIR"
TEST_DIR: "$CI_PROJECT_DIR/test"
# GitLab-CI environment
GET_SOURCES_ATTEMPTS: "10"
ARTIFACT_DOWNLOAD_ATTEMPTS: "10"
GIT_SUBMODULE_STRATEGY: none
# Define a matrix for IDF versions and their corresponding targets
.options_list:
markers:
TEST_PORT:
- "tcp"
- "serial"
- "generic"
# - "tcp_p4"
# - "serial_p4"
.setup_idf_tools: &setup_idf_tools |
tools/idf_tools.py --non-interactive install && eval "$(tools/idf_tools.py --non-interactive export)" || exit 1
.add_gh_key_remote: &add_gh_key_remote |
command -v ssh-agent >/dev/null || exit 1
eval $(ssh-agent -s)
printf '%s\n' "${GH_PUSH_KEY}" | tr -d '\r' | ssh-add - > /dev/null
mkdir -p ~/.ssh && chmod 700 ~/.ssh
[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config || ssh-keyscan -t rsa github.com >> ~/.ssh/known_hosts
git remote remove github || true
git remote add github ${GH_PUSH_REPO}
after_script:
# Just for cleaning space, no other causes
- git clean -ffdx
.build_template:
stage: build
tags:
- build
variables:
SIZE_INFO_LOCATION: "${TEST_DIR}/size_info.txt"
IDF_CCACHE_ENABLE: "1"
after_script:
# Show ccache statistics if enabled globally
- test "$CI_CCACHE_STATS" == 1 && test -n "$(which ccache)" && ccache --show-stats || true
dependencies: []
.before_script_build_jobs:
before_script:
- pip install idf-component-manager --upgrade
- pip install "idf_build_apps~=1.0.1"
.check_idf_ver: &check_idf_ver |
export IDF_PATH=$(find /opt -type d -name "*idf*" \
\( -exec test -f '{}/tools/idf.py' \; -and -exec test -f '{}/tools/idf_tools.py' \; \
\) -print -quit)
if [ -z "${IDF_PATH}" ];then
echo "IDF version is not found."
else
cd ${IDF_PATH}
export IDF_DESCRIBE=$(git describe)
export IDF_VERSION=${IDF_DESCRIBE%-*}
echo "$IDF_VERSION" >> $TEST_DIR/idf_version_info.txt
echo "ESP-IDF: $IDF_VERSION"
fi
# This template gets expanded multiple times, once for every IDF version.
# IDF version is specified by setting the espressif/idf image tag.
#
# TEST_TARGETS sets the list of IDF_TARGET values to build the test for.
# It should contain only the targets with optimized assembly implementations.
#
.build_pytest_template:
stage: build
extends:
- .build_template
- .before_script_build_jobs
artifacts:
name: artifacts_${CI_JOB_NAME}
paths:
- "**/build*/size.json"
- "**/build*/build.log"
- "**/build*/build_log.txt"
- "**/build*/*.bin"
- "**/build*/*.elf"
- "**/build*/*.map"
- "**/build*/flasher_args.json"
- "**/build*/flash_project_args"
- "**/build*/config/sdkconfig.json"
- "**/build*/bootloader/*.bin"
- "**/build*/partition_table/*.bin"
- "**/idf_version_info.txt"
- $SIZE_INFO_LOCATION
when: always
expire_in: 3 weeks
script:
# CI specific options start from "--collect-size-info xxx". could ignore when running locally
# The script below will build all test applications defined in environment variable $TEST_TARGETS
- *check_idf_ver
- cd ${TEST_DIR}
- python -m idf_build_apps build -v -p ${TEST_PORT}
--recursive
--target all
--default-build-targets ${TEST_TARGETS}
--config "sdkconfig.ci.*=" --build-dir "build_@t_@w"
--build-log build_log.txt
--check-warnings
--ignore-warning-file ../tools/ignore_build_warnings.txt
--collect-size-info $SIZE_INFO_LOCATION
--manifest-rootpath .
--manifest-file .build-test-rules.yml
# delete all other build artifacts, except esp32
- echo "Delete build folders:" $(find . -type d -regex '^\./.*build_esp32[a-z]+[0-9]+[_a-z]*' -print -exec rm -rf {} +)
variables:
TEST_TARGETS: "esp32"
build_idf_latest:
extends: .build_pytest_template
image: espressif/idf:latest
parallel:
matrix:
- !reference [.options_list, markers]
variables:
TEST_TARGETS: "esp32 esp32s2 esp32s3 esp32c2 esp32c3 esp32c5 esp32c6 esp32c61 esp32h2 esp32p4"
# Check the support policy for esp-idf v5.3
build_idf_v5.3:
extends: .build_pytest_template
image: espressif/idf:release-v5.3
parallel:
matrix:
- !reference [.options_list, markers]
variables:
TEST_TARGETS: "esp32 esp32s2 esp32s3 esp32c2 esp32c3 esp32c6 esp32h2 esp32p4"
build_idf_v5.2:
extends: .build_pytest_template
image: espressif/idf:release-v5.2
parallel:
matrix:
- !reference [.options_list, markers]
variables:
TEST_TARGETS: "esp32 esp32s2 esp32s3 esp32c2 esp32c3 esp32c6 esp32h2"
build_idf_v5.1:
extends: .build_pytest_template
image: espressif/idf:release-v5.1
parallel:
matrix:
- !reference [.options_list, markers]
variables:
TEST_TARGETS: "esp32 esp32s2 esp32s3 esp32c2 esp32c3"
build_idf_v5.0:
extends: .build_pytest_template
image: espressif/idf:release-v5.0
parallel:
matrix:
- !reference [.options_list, markers]
variables:
TEST_TARGETS: "esp32 esp32s2 esp32s3 esp32c2 esp32c3"
.target_test_template:
stage: target_test
timeout: 1 hour
variables:
GIT_DEPTH: 1
SUBMODULES_TO_FETCH: "none"
cache:
# Usually do not need submodule-cache in target_test
- key: pip-cache
paths:
- .cache/pip
policy: pull
.before_script_pytest_jobs:
before_script:
# Install pytest-embedded to perform test cases (workaround to upgrade the version )
- pip install --only-binary cryptography pytest-embedded pytest-embedded-serial-esp pytest-embedded-idf --upgrade
.test_template:
extends:
- .before_script_pytest_jobs
tags:
- multi_dut_modbus_${TEST_PORT}
variables:
IDF_TARGET: "esp32" # the only esp32 runners are available for now
artifacts:
name: artifacts_${CI_JOB_NAME}
paths:
- "${TEST_DIR}/*/*.log"
- "${TEST_DIR}/*.txt"
- "${TEST_DIR}/*/results_*.xml"
- "${TEST_DIR}/pytest_embedded_log/"
reports:
junit: ${TEST_DIR}/${TEST_PORT}/results_${IDF_TARGET}_${IDF_VER%-*}.xml
when: always
expire_in: 1 week
script: |
export IDF_VER=$(cat ${TEST_DIR}/idf_version_info.txt)
cd ${TEST_DIR}/${TEST_PORT}
echo "Start test job: ${CI_JOB_NAME}, version: ${IDF_VER%-*}, folder: ${PWD##*/}"
python -m pytest --embedded-services serial,esp,idf --junit-xml=${TEST_DIR}/${TEST_PORT}/results_${IDF_TARGET}_${IDF_VER%-*}.xml --target=${IDF_TARGET}
ls -lh > ${TEST_DIR}/test_dir.txt
target_test_latest:
stage: target_test
image: "$CI_DOCKER_REGISTRY/target-test-env-v5.3:1"
extends: .test_template
needs:
- build_idf_latest
parallel:
matrix:
- !reference [.options_list, markers]
after_script: []
# Test the support policy for esp-idf v5.3
target_test_v5.3:
stage: target_test
image: "$CI_DOCKER_REGISTRY/target-test-env-v5.3:1"
extends: .test_template
needs:
- build_idf_v5.3
parallel:
matrix:
- !reference [.options_list, markers]
after_script: []
target_test_v5.2:
stage: target_test
image: "$CI_DOCKER_REGISTRY/target-test-env-v5.2:2"
extends: .test_template
needs:
- build_idf_v5.2
parallel:
matrix:
- !reference [.options_list, markers]
after_script: []
target_test_v5.1:
stage: target_test
image: "$CI_DOCKER_REGISTRY/target-test-env-v5.1:1"
extends: .test_template
needs:
- build_idf_v5.1
parallel:
matrix:
- !reference [.options_list, markers]
after_script: []
target_test_v5.0:
stage: target_test
image: "$CI_DOCKER_REGISTRY/target-test-env-v5.0:3"
extends: .test_template
parallel:
matrix:
- !reference [.options_list, markers]
needs:
job: build_idf_v5.0
artifacts: true
after_script: []
build_docs:
stage: build
image: $ESP_DOCS_ENV_IMAGE
tags:
- build_docs
artifacts:
when: always
paths:
- docs/_build/*/*/*.txt
- docs/_build/*/*/html/*
expire_in: 4 days
# No cleaning when the artifacts
after_script: []
script:
- cd docs
- pip install -r requirements.txt
- ./generate_docs
.deploy_docs_template:
stage: deploy
image: $ESP_DOCS_ENV_IMAGE
tags:
- deploy_docs
needs:
- build_docs
only:
changes:
- "docs/**/*"
script:
- source ${CI_PROJECT_DIR}/docs/utils.sh
- add_doc_server_ssh_keys $DOCS_DEPLOY_PRIVATEKEY $DOCS_DEPLOY_SERVER $DOCS_DEPLOY_SERVER_USER
- export GIT_VER=$(git describe --always)
- pip install -r ${CI_PROJECT_DIR}/docs/requirements.txt
- deploy-docs
deploy_docs_preview:
extends:
- .deploy_docs_template
except:
refs:
- master
variables:
TYPE: "preview"
DOCS_BUILD_DIR: "${CI_PROJECT_DIR}/docs/_build/"
DOCS_DEPLOY_PRIVATEKEY: "$DOCS_DEPLOY_KEY"
DOCS_DEPLOY_SERVER: "$DOCS_SERVER"
DOCS_DEPLOY_SERVER_USER: "$DOCS_SERVER_USER"
DOCS_DEPLOY_PATH: "$DOCS_PATH"
DOCS_DEPLOY_URL_BASE: "https://$DOCS_PREVIEW_SERVER_URL/docs/esp-modbus"
deploy_docs_production:
extends:
- .deploy_docs_template
only:
refs:
- master
variables:
TYPE: "production"
DOCS_BUILD_DIR: "${CI_PROJECT_DIR}/docs/_build/"
DOCS_DEPLOY_PRIVATEKEY: "$DOCS_PROD_DEPLOY_KEY"
DOCS_DEPLOY_SERVER: "$DOCS_PROD_SERVER"
DOCS_DEPLOY_SERVER_USER: "$DOCS_PROD_SERVER_USER"
DOCS_DEPLOY_PATH: "$DOCS_PROD_PATH"
DOCS_DEPLOY_URL_BASE: "https://docs.espressif.com/projects/esp-modbus"
upload_to_component_manager:
stage: deploy
image: python:3.10-alpine
tags:
- deploy
rules:
- if: '$CI_COMMIT_BRANCH == "master"'
- if: '$FORCE_PUSH_COMPONENT == "1"'
script:
- pip install idf-component-manager
- export IDF_COMPONENT_API_TOKEN=${ESP_MODBUS_API_KEY}
- export COMP_VERSION=$(grep 'version:' idf_component.yml | head -n 1 | awk '{print $2}' | tr -d '"')
- compote component upload --namespace=espressif --name=esp-modbus --allow-existing --version=${COMP_VERSION}