Skip to content

Commit bb95c4f

Browse files
committed
Merge branch 'feat/ci_enchanced' into 'main'
feat(ci): ci enhanced See merge request espressif/esp-thread-br!160
2 parents a5ed23e + 48924c3 commit bb95c4f

File tree

7 files changed

+351
-57
lines changed

7 files changed

+351
-57
lines changed

.gitlab-ci.yml

Lines changed: 26 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ pre_commit:
4040
- ./install.sh
4141
- . ./export.sh
4242

43+
.setup_idf_master: &setup_idf_master
44+
- cd $CI_PROJECT_DIR
45+
- git clone --depth=1 -b master ${ESP_IDF_HTTP}
46+
- cd esp-idf
47+
- git submodule update --init --depth=1
48+
- ./install.sh
49+
- . ./export.sh
50+
4351
.build_basic_thread_border_router: &build_basic_thread_border_router
4452
- cd $IDF_PATH/examples/openthread/ot_rcp
4553
- idf.py set-target esp32h2
@@ -106,9 +114,12 @@ build_examples:
106114
image: espressif/idf:latest
107115
script:
108116
- *submodule_update
117+
- cd $ESP_THREAD_BR_PATH
118+
- python3 ${CI_TOOLS_PATH}/get_component_version.py $ESP_THREAD_BR_PATH/examples/basic_thread_border_router/main/idf_component.yml build_examples_result.txt esp_ot_cli_extension
119+
- python3 ${CI_TOOLS_PATH}/get_component_version.py $ESP_THREAD_BR_PATH/examples/basic_thread_border_router/main/idf_component.yml build_examples_result.txt esp_rcp_update
109120
- *build_basic_thread_border_router
110121
- cd $ESP_THREAD_BR_PATH
111-
- echo "build_examples_result=true" > build_examples_result.txt
122+
- echo "Success" > build_examples_result.txt
112123
artifacts:
113124
when: always
114125
paths:
@@ -134,10 +145,12 @@ build_idf_otbr_examples:
134145
image: $ESP_ENV_IMAGE
135146
allow_failure: true
136147
script:
137-
- *setup_idf
148+
- *setup_idf_master
149+
- cd $ESP_THREAD_BR_PATH
150+
- python3 ${CI_TOOLS_PATH}/get_component_version.py $IDF_PATH/examples/openthread/ot_br/main/idf_component.yml build_idf_otbr_example_result.txt esp_ot_cli_extension
138151
- *build_idf_example_ot_br
139152
- cd $ESP_THREAD_BR_PATH
140-
- echo "build_idf_otbr_example_result=true" > build_idf_otbr_example_result.txt
153+
- echo "Success" > build_idf_otbr_example_result.txt
141154
artifacts:
142155
when: always
143156
paths:
@@ -151,10 +164,12 @@ build_idf_otbr_autostart_examples:
151164
image: $ESP_ENV_IMAGE
152165
allow_failure: true
153166
script:
154-
- *setup_idf
167+
- *setup_idf_master
168+
- cd $ESP_THREAD_BR_PATH
169+
- python3 ${CI_TOOLS_PATH}/get_component_version.py $IDF_PATH/examples/openthread/ot_br/main/idf_component.yml build_idf_otbr_autostart_example_result.txt esp_ot_cli_extension
155170
- *build_idf_example_ot_br_autostart
156171
- cd $ESP_THREAD_BR_PATH
157-
- echo "build_idf_otbr_autostart_example_result=true" > build_idf_otbr_autostart_example_result.txt
172+
- echo "Success" > build_idf_otbr_autostart_example_result.txt
158173
artifacts:
159174
when: always
160175
paths:
@@ -168,10 +183,12 @@ build_idf_otcli_examples:
168183
image: $ESP_ENV_IMAGE
169184
allow_failure: true
170185
script:
171-
- *setup_idf
186+
- *setup_idf_master
187+
- cd $ESP_THREAD_BR_PATH
188+
- python3 ${CI_TOOLS_PATH}/get_component_version.py $IDF_PATH/examples/openthread/ot_cli/main/idf_component.yml build_idf_otcli_example_result.txt esp_ot_cli_extension
172189
- *build_idf_example_ot_cli
173190
- cd $ESP_THREAD_BR_PATH
174-
- echo "build_idf_otcli_example_result=true" > build_idf_otcli_example_result.txt
191+
- echo "Success" > build_idf_otcli_example_result.txt
175192
artifacts:
176193
when: always
177194
paths:
@@ -208,29 +225,8 @@ check_build_result:
208225
- build_idf_otcli_examples
209226
script:
210227
- *submodule_update
211-
- chmod 700 ./check_components_version.sh
212-
- ALLOW_EXT_CMD_FAILURE_OUTPUT=$(./check_components_version.sh "components/esp_ot_cli_extension")
213-
- ALLOW_EXT_CMD_FAILURE_VALUE=$(echo "$ALLOW_EXT_CMD_FAILURE_OUTPUT" | cut -d'=' -f2)
214-
- echo "ALLOW_EXT_CMD_FAILURE_VALUE=$ALLOW_EXT_CMD_FAILURE_VALUE"
215-
- ALLOW_RCP_UPDATE_FAILURE_OUTPUT=$(./check_components_version.sh "components/esp_rcp_update")
216-
- ALLOW_RCP_UPDATE_FAILURE_VALUE=$(echo "$ALLOW_RCP_UPDATE_FAILURE_OUTPUT" | cut -d'=' -f2)
217-
- echo "ALLOW_RCP_UPDATE_FAILURE_VALUE=$ALLOW_RCP_UPDATE_FAILURE_VALUE"
218-
- |
219-
if [ "$ALLOW_EXT_CMD_FAILURE_VALUE" == "true" ] || [ "$ALLOW_RCP_UPDATE_FAILURE_VALUE" == "true" ]; then
220-
echo "allow failure"
221-
exit 0;
222-
else
223-
if [ -f "build_examples_result.txt" ] &&
224-
[ -f "build_idf_otbr_example_result.txt" ] &&
225-
[ -f "build_idf_otbr_autostart_example_result.txt" ] &&
226-
[ -f "build_idf_otcli_example_result.txt" ]; then
227-
echo "Success!!!"
228-
exit 0
229-
else
230-
echo "Fail!!!"
231-
exit 1
232-
fi
233-
fi
228+
- chmod 700 ./check_build_results.sh
229+
- ./check_build_results.sh
234230
tags:
235231
- build
236232

.pre-commit-config.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,11 @@ repos:
66
rev: 'v14.0.6' # Use the sha / tag you want to point at
77
hooks:
88
- id: clang-format
9+
10+
- repo: local
11+
hooks:
12+
- id: check-version-increment
13+
name: Check Version Increment in Specific idf_component.yml
14+
entry: python3 check_components_version.py
15+
language: python
16+
files: "(components/esp_rcp_update/idf_component.yml|components/esp_ot_cli_extension/idf_component.yml)"

check_build_results.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/bash
2+
3+
# Define the commands in a list
4+
commands=(
5+
"components/esp_rcp_update build_examples_result.txt"
6+
"components/esp_ot_cli_extension build_examples_result.txt"
7+
"components/esp_ot_cli_extension build_idf_otbr_example_result.txt"
8+
"components/esp_ot_cli_extension build_idf_otbr_autostart_example_result.txt"
9+
"components/esp_ot_cli_extension build_idf_otcli_example_result.txt"
10+
)
11+
12+
# Loop through the list and run the commands
13+
for cmd in "${commands[@]}"; do
14+
python3 check_idf_example_build_results.py $cmd
15+
if [ $? -eq 1 ]; then
16+
echo "Error: The check for $cmd failed."
17+
exit 1
18+
fi
19+
done
20+
21+
# Exit with 0 if all commands succeed
22+
exit 0

check_components_version.py

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
import sys
2+
import subprocess
3+
4+
# Get the path parameters passed to the script
5+
if len(sys.argv) < 2:
6+
print("Error: No idf_component.yml path provided")
7+
sys.exit(1)
8+
9+
file_paths = sys.argv[1:]
10+
11+
# Print the received file paths for debugging
12+
print(f"Processing the following files: {file_paths}")
13+
14+
# Get the version number from the file
15+
def get_version_from_file(file_path):
16+
try:
17+
with open(file_path, 'r') as f:
18+
first_line = f.readline().strip()
19+
if first_line.startswith('version:'):
20+
return first_line.split(":")[1].strip().strip('"')
21+
else:
22+
print(f"Error: No version found in {file_path}")
23+
return None
24+
except Exception as e:
25+
print(f"Error reading {file_path}: {e}")
26+
return None
27+
28+
# Get the version number from the main branch
29+
def get_version_from_main_branch(file_path):
30+
try:
31+
# Get the version number from the main branch of the git repository
32+
result = subprocess.run(['git', 'show', 'main:' + file_path], capture_output=True, text=True)
33+
first_line = result.stdout.strip().split('\n')[0]
34+
if first_line.startswith('version:'):
35+
return first_line.split(":")[1].strip().strip('"')
36+
else:
37+
print(f"Error: No version found in {file_path} from main branch")
38+
return None
39+
except Exception as e:
40+
print(f"Error reading from main branch for {file_path}: {e}")
41+
return None
42+
43+
# Check the version to ensure the current version is not lower than the main branch version
44+
def check_version_increment(main_version, current_version):
45+
main_parts = list(map(int, main_version.split('.')))
46+
current_parts = list(map(int, current_version.split('.')))
47+
48+
if current_parts[0] < main_parts[0]:
49+
print(f"Error: Major version downgrade detected. Current version {current_version} is less than main version {main_version}.")
50+
return False
51+
if current_parts[0] == main_parts[0] and current_parts[1] < main_parts[1]:
52+
print(f"Error: Minor version downgrade detected. Current version {current_version} is less than main version {main_version}.")
53+
return False
54+
if current_parts[0] == main_parts[0] and current_parts[1] == main_parts[1] and current_parts[2] < main_parts[2]:
55+
print(f"Error: Patch version downgrade detected. Current version {current_version} is less than main version {main_version}.")
56+
return False
57+
58+
return True
59+
60+
# Perform checks for each of the provided file paths
61+
for file_path in file_paths:
62+
print(f"Processing file: {file_path}")
63+
64+
# Get the current branch version number
65+
current_version = get_version_from_file(file_path)
66+
if current_version is None:
67+
sys.exit(1)
68+
69+
# Get the main branch version number
70+
main_version = get_version_from_main_branch(file_path)
71+
if main_version is None:
72+
sys.exit(1)
73+
74+
# Compare the version numbers
75+
if not check_version_increment(main_version, current_version):
76+
sys.exit(1)
77+
78+
print("Version check passed successfully.")

check_components_version.sh

Lines changed: 0 additions & 27 deletions
This file was deleted.

0 commit comments

Comments
 (0)