Skip to content

Commit bc6be5e

Browse files
committed
feat(pre-commit): support to check file versions
1 parent de115e2 commit bc6be5e

File tree

14 files changed

+138
-12
lines changed

14 files changed

+138
-12
lines changed

.github/workflows/check_versions.yml renamed to .github/workflows/check_lib_versions.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Check Versions
1+
name: Check Library Versions
22

33
on:
44
pull_request:
@@ -26,5 +26,5 @@ jobs:
2626
echo "prerelease: ${{ steps.last_release.outputs.prerelease }}"
2727
echo "url: ${{ steps.last_release.outputs.url }}"
2828
- name: Check & Compare versions
29-
run: bash ./.github/scripts/check_versions.sh ${{ steps.last_release.outputs.tag_name }}
29+
run: bash ./.github/scripts/check_lib_versions.sh ${{ steps.last_release.outputs.tag_name }}
3030

.pre-commit-config.yaml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ repos:
3939
hooks:
4040
- id: sync-conf-files
4141
name: Update when configuration files change
42-
entry: python .github/ci/sync_conf_files.py ./
42+
entry: python tools/sync_conf_files.py ./
43+
language: system
44+
files: '.*ESP_Panel_(Board_Custom|Board_Supported|Conf)\.h'
45+
46+
- repo: local
47+
hooks:
48+
- id: check-file-versions
49+
name: Update when versions change
50+
entry: python tools/check_file_version.py ./
4351
language: system
4452
files: '.*ESP_Panel_(Board_Custom|Board_Supported|Conf)\.h'

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
# ChangeLog
22

3-
## v0.1.2 - 2024-05-27
3+
## v0.1.2 - 2024-06-01
44

55
### Enhancements:
66

77
* feat(config): add version control for all configuration files by @lzw655 (#32)
8+
* feat(touch): add i2c st1633 by @lzw655 (#22)
9+
* feat(pre-commit): support to check file versions
810

911
### Bugfixes:
1012

ESP_Panel_Board_Custom.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@
362362
*/
363363
#define ESP_PANEL_BOARD_CUSTOM_FILE_VERSION_MAJOR 0
364364
#define ESP_PANEL_BOARD_CUSTOM_FILE_VERSION_MINOR 1
365-
#define ESP_PANEL_BOARD_CUSTOM_FILE_VERSION_PATCH 0
365+
#define ESP_PANEL_BOARD_CUSTOM_FILE_VERSION_PATCH 1
366366

367367
#endif /* ESP_PANEL_USE_CUSTOM_BOARD */
368368

examples/LVGL/v8/Porting/ESP_Panel_Board_Custom.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@
362362
*/
363363
#define ESP_PANEL_BOARD_CUSTOM_FILE_VERSION_MAJOR 0
364364
#define ESP_PANEL_BOARD_CUSTOM_FILE_VERSION_MINOR 1
365-
#define ESP_PANEL_BOARD_CUSTOM_FILE_VERSION_PATCH 0
365+
#define ESP_PANEL_BOARD_CUSTOM_FILE_VERSION_PATCH 1
366366

367367
#endif /* ESP_PANEL_USE_CUSTOM_BOARD */
368368

examples/LVGL/v8/Rotation/ESP_Panel_Board_Custom.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@
362362
*/
363363
#define ESP_PANEL_BOARD_CUSTOM_FILE_VERSION_MAJOR 0
364364
#define ESP_PANEL_BOARD_CUSTOM_FILE_VERSION_MINOR 1
365-
#define ESP_PANEL_BOARD_CUSTOM_FILE_VERSION_PATCH 0
365+
#define ESP_PANEL_BOARD_CUSTOM_FILE_VERSION_PATCH 1
366366

367367
#endif /* ESP_PANEL_USE_CUSTOM_BOARD */
368368

examples/Panel/PanelTest/ESP_Panel_Board_Custom.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@
362362
*/
363363
#define ESP_PANEL_BOARD_CUSTOM_FILE_VERSION_MAJOR 0
364364
#define ESP_PANEL_BOARD_CUSTOM_FILE_VERSION_MINOR 1
365-
#define ESP_PANEL_BOARD_CUSTOM_FILE_VERSION_PATCH 0
365+
#define ESP_PANEL_BOARD_CUSTOM_FILE_VERSION_PATCH 1
366366

367367
#endif /* ESP_PANEL_USE_CUSTOM_BOARD */
368368

examples/SquareLine/v8/Porting/ESP_Panel_Board_Custom.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@
362362
*/
363363
#define ESP_PANEL_BOARD_CUSTOM_FILE_VERSION_MAJOR 0
364364
#define ESP_PANEL_BOARD_CUSTOM_FILE_VERSION_MINOR 1
365-
#define ESP_PANEL_BOARD_CUSTOM_FILE_VERSION_PATCH 0
365+
#define ESP_PANEL_BOARD_CUSTOM_FILE_VERSION_PATCH 1
366366

367367
#endif /* ESP_PANEL_USE_CUSTOM_BOARD */
368368

examples/SquareLine/v8/WiFiClock/ESP_Panel_Board_Custom.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@
362362
*/
363363
#define ESP_PANEL_BOARD_CUSTOM_FILE_VERSION_MAJOR 0
364364
#define ESP_PANEL_BOARD_CUSTOM_FILE_VERSION_MINOR 1
365-
#define ESP_PANEL_BOARD_CUSTOM_FILE_VERSION_PATCH 0
365+
#define ESP_PANEL_BOARD_CUSTOM_FILE_VERSION_PATCH 1
366366

367367
#endif /* ESP_PANEL_USE_CUSTOM_BOARD */
368368

src/ESP_PanelVersions.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
/* File `ESP_Panel_Board_Custom.h` */
2222
#define ESP_PANEL_BOARD_CUSTOM_VERSION_MAJOR 0
2323
#define ESP_PANEL_BOARD_CUSTOM_VERSION_MINOR 1
24-
#define ESP_PANEL_BOARD_CUSTOM_VERSION_PATCH 0
24+
#define ESP_PANEL_BOARD_CUSTOM_VERSION_PATCH 1
2525

2626
/* File `ESP_Panel_Board_Supported.h` */
2727
#define ESP_PANEL_BOARD_SUPPORTED_VERSION_MAJOR 0

src/touch/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
| [FT5x06](https://components.espressif.com/components/espressif/esp_lcd_touch_ft5x06) | 1.0.6 |
88
| [GT911](https://components.espressif.com/components/espressif/esp_lcd_touch_gt911) | 1.1.0 |
99
| [GT1151](https://components.espressif.com/components/espressif/esp_lcd_touch_gt1151) | 1.0.5~1 |
10+
| ST1633 | 0.1.0 |
1011
| [ST7123](https://components.espressif.com/components/espressif/esp_lcd_touch_st7123) | 0.0.1 |
1112
| [TT21100](https://components.espressif.com/components/espressif/esp_lcd_touch_tt21100) | 1.1.0 |
1213
| [XPT2046](https://components.espressif.com/components/atanisoft/esp_lcd_touch_xpt2046) | 1.0.4 |

tools/check_file_version.py

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
# SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
import os
5+
import sys
6+
import re
7+
8+
internal_version_file = "src/ESP_PanelVersions.h"
9+
internal_version_macross = [
10+
{
11+
"file": "ESP_Panel_Conf.h",
12+
"macro": {
13+
"major": "ESP_PANEL_CONF_VERSION_MAJOR",
14+
"minor": "ESP_PANEL_CONF_VERSION_MINOR",
15+
"patch": "ESP_PANEL_CONF_VERSION_PATCH"
16+
},
17+
},
18+
{
19+
"file": "ESP_Panel_Board_Custom.h",
20+
"macro": {
21+
"major": "ESP_PANEL_BOARD_CUSTOM_VERSION_MAJOR",
22+
"minor": "ESP_PANEL_BOARD_CUSTOM_VERSION_MINOR",
23+
"patch": "ESP_PANEL_BOARD_CUSTOM_VERSION_PATCH"
24+
},
25+
},
26+
{
27+
"file": "ESP_Panel_Board_Supported.h",
28+
"macro": {
29+
"major": "ESP_PANEL_BOARD_SUPPORTED_VERSION_MAJOR",
30+
"minor": "ESP_PANEL_BOARD_SUPPORTED_VERSION_MINOR",
31+
"patch": "ESP_PANEL_BOARD_SUPPORTED_VERSION_PATCH"
32+
},
33+
},
34+
]
35+
file_version_macros = [
36+
{
37+
"file": "ESP_Panel_Conf.h",
38+
"macro": {
39+
"major": "ESP_PANEL_CONF_FILE_VERSION_MAJOR",
40+
"minor": "ESP_PANEL_CONF_FILE_VERSION_MINOR",
41+
"patch": "ESP_PANEL_CONF_FILE_VERSION_PATCH"
42+
},
43+
},
44+
{
45+
"file": "ESP_Panel_Board_Custom.h",
46+
"macro": {
47+
"major": "ESP_PANEL_BOARD_CUSTOM_FILE_VERSION_MAJOR",
48+
"minor": "ESP_PANEL_BOARD_CUSTOM_FILE_VERSION_MINOR",
49+
"patch": "ESP_PANEL_BOARD_CUSTOM_FILE_VERSION_PATCH"
50+
},
51+
},
52+
{
53+
"file": "ESP_Panel_Board_Supported.h",
54+
"macro": {
55+
"major": "ESP_PANEL_BOARD_SUPPORTED_FILE_VERSION_MAJOR",
56+
"minor": "ESP_PANEL_BOARD_SUPPORTED_FILE_VERSION_MINOR",
57+
"patch": "ESP_PANEL_BOARD_SUPPORTED_FILE_VERSION_PATCH"
58+
},
59+
},
60+
]
61+
62+
63+
def extract_version(file_path, version_dict):
64+
if os.path.dirname(file_path) == "":
65+
file_path = os.path.join(search_directory, file_path)
66+
67+
file_contents = []
68+
content_str = ""
69+
with open(file_path, 'r') as file:
70+
file_contents.append(file.readlines())
71+
for content in file_contents:
72+
content_str = ''.join(content)
73+
74+
version_macro = version_dict['macro']
75+
major_version = re.search(r'#define ' + version_macro["major"] + r' (\d+)', content_str)
76+
minor_version = re.search(r'#define ' + version_macro["minor"] + r' (\d+)', content_str)
77+
patch_version = re.search(r'#define ' + version_macro["patch"] + r' (\d+)', content_str)
78+
79+
if major_version and minor_version and patch_version:
80+
return {"file": version_dict['file'], "version": [major_version.group(1), minor_version.group(1), patch_version.group(1)]}
81+
82+
return None
83+
84+
85+
if __name__ == "__main__":
86+
if len(sys.argv) >= 3:
87+
search_directory = sys.argv[1]
88+
89+
# Extract internal versions
90+
internal_version_path = os.path.join(search_directory, internal_version_file)
91+
internal_versions = []
92+
for internal_version_macros in internal_version_macross:
93+
version = extract_version(internal_version_path, internal_version_macros)
94+
print(f"Internal version extracted from '{internal_version_path}")
95+
if version:
96+
print(f"Internal version: '{internal_version_macros['file']}': {version}")
97+
internal_versions.append(version)
98+
else:
99+
print(f"'{internal_version_macros['file']}' version not found")
100+
101+
is_version_mismatch = False
102+
for i in range(2, len(sys.argv)):
103+
file_path = sys.argv[i]
104+
src_file = os.path.join(search_directory, os.path.basename(file_path))
105+
for file_version in file_version_macros:
106+
versions = extract_version(src_file, file_version)
107+
if versions:
108+
print(f"File version extracted from '{src_file}': {versions}")
109+
for internal_version in internal_versions:
110+
if (internal_version['file'] == versions['file']) and (internal_version['version'] != versions['version']):
111+
print(f"Version mismatch: '{internal_version['file']}'")
112+
is_version_mismatch = True
113+
print(f"Version matched")
114+
115+
if is_version_mismatch:
116+
sys.exit(1)

.github/ci/sync_conf_files.py renamed to tools/sync_conf_files.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import sys
66
import shutil
77

8-
98
exclude_dirs = ["./build"]
109

1110

0 commit comments

Comments
 (0)