From a68748b6e86210bca775912d1eda73e2cf2c542c Mon Sep 17 00:00:00 2001 From: Chen Yudong Date: Fri, 15 Sep 2023 18:30:11 +0800 Subject: [PATCH 1/2] fix(ci): target test wifi rules should include esp-wifi component --- .gitlab/ci/rules.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.gitlab/ci/rules.yml b/.gitlab/ci/rules.yml index b7586016bf..2d5d8ac48e 100644 --- a/.gitlab/ci/rules.yml +++ b/.gitlab/ci/rules.yml @@ -111,11 +111,11 @@ - "examples/openthread/**/*" .patterns-target_test-wifi: &patterns-target_test-wifi - - "components/{esp_netif,lwip,esp_phy,wpa_supplicant,esp_coex}/???[!t]*/**/*" - - "components/{esp_netif,lwip,esp_phy,wpa_supplicant,esp_coex}/??[!s]?*/**/*" - - "components/{esp_netif,lwip,esp_phy,wpa_supplicant,esp_coex}/???/**/*" - - "components/{esp_netif,lwip,esp_phy,wpa_supplicant,esp_coex}/??/**/*" - - "components/{esp_netif,lwip,esp_phy,wpa_supplicant,esp_coex}/*" + - "components/{esp_wifi,esp_netif,lwip,esp_phy,wpa_supplicant,esp_coex}/???[!t]*/**/*" + - "components/{esp_wifi,esp_netif,lwip,esp_phy,wpa_supplicant,esp_coex}/??[!s]?*/**/*" + - "components/{esp_wifi,esp_netif,lwip,esp_phy,wpa_supplicant,esp_coex}/???/**/*" + - "components/{esp_wifi,esp_netif,lwip,esp_phy,wpa_supplicant,esp_coex}/??/**/*" + - "components/{esp_wifi,esp_netif,lwip,esp_phy,wpa_supplicant,esp_coex}/*" .patterns-component_ut-wifi: &patterns-component_ut-wifi - "components/esp_wifi/**/*" From 1ce30750c92ff3230bd294f1b229c6810238c1f9 Mon Sep 17 00:00:00 2001 From: Chen Yudong Date: Fri, 15 Sep 2023 18:31:57 +0800 Subject: [PATCH 2/2] fix(pre-commit): ignore files not in git repo --- tools/ci/check_rules_components_patterns.py | 38 ++++++++++++--------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/tools/ci/check_rules_components_patterns.py b/tools/ci/check_rules_components_patterns.py index f45fece470..8c5794d4aa 100755 --- a/tools/ci/check_rules_components_patterns.py +++ b/tools/ci/check_rules_components_patterns.py @@ -8,6 +8,8 @@ Check patterns-build_components including all components files except 'test*/' import glob import os +import subprocess +from functools import lru_cache from typing import List, Set import yaml @@ -16,19 +18,30 @@ from idf_ci_utils import IDF_PATH RULES_FILE = os.path.join(IDF_PATH, '.gitlab', 'ci', 'rules.yml') +@lru_cache(1) +def get_component_git_files() -> Set[str]: + output = subprocess.check_output(['git', 'ls-files', 'components/'], cwd=IDF_PATH).decode() + component_git_files = set((_l.strip() for _l in output.strip().splitlines())) + assert component_git_files, 'Can not list git files' + return component_git_files + + def get_component_files_from_patterns(patterns: List[str]) -> Set[str]: files: Set[str] = set() for pattern in patterns: + # NOTE: version 3.11: Added the include_hidden parameter. # NOTE: version 3.10: Added the root_dir and dir_fd parameters. - files = files | set(glob.iglob(pattern, recursive=True)) + try: + _files = set(glob.iglob(pattern, root_dir=IDF_PATH, recursive=True, include_hidden=True)) # type: ignore + except TypeError: + _files = set(glob.iglob(pattern, recursive=True)) + files = files | _files + + # ignore files not in git repo + files &= get_component_git_files() return files -def get_components_submodule_files(submodules: List[str]) -> Set[str]: - patterns = [f'{submodule}/**/*' for submodule in submodules] - return get_component_files_from_patterns(patterns) - - def get_components_test_files() -> Set[str]: patterns = [ 'components/*/test/**/*', @@ -62,18 +75,9 @@ def main() -> None: patterns_components = [f'{p}/**/*' if p in submodules else p for p in patterns_components] # get different components files - submodule_files = get_components_submodule_files(submodules) rules_files = get_component_files_from_patterns(patterns_components) - - # first check submodules in rules_files - if check_submodule_res := submodule_files.difference(rules_files): - # only show one file in the failure message - print(f'Found submodule should in .patterns-build_components but not: {check_submodule_res.pop()}') - exit(1) - - rules_files = rules_files.difference(submodule_files) - components_test_files = get_components_test_files().difference(submodule_files) - components_build_files = get_all_components_files().difference(submodule_files).difference(components_test_files) + components_test_files = get_components_test_files() + components_build_files = get_all_components_files().difference(components_test_files) if check_test_files := components_test_files & rules_files: # rules should not include test files