From 0b7a0d7cbd20772582520d2c3c2ee8c9b969493b Mon Sep 17 00:00:00 2001 From: Fu Hanxi Date: Tue, 12 Oct 2021 10:47:28 +0800 Subject: [PATCH] ci: move check_tools_files_patterns to pre-commit --- .gitlab/ci/pre_check.yml | 9 ----- .pre-commit-config.yaml | 8 +++++ tools/ci/check_copyright_ignore.txt | 1 - tools/ci/check_tools_files_patterns.py | 46 ++++++++++++-------------- 4 files changed, 29 insertions(+), 35 deletions(-) diff --git a/.gitlab/ci/pre_check.yml b/.gitlab/ci/pre_check.yml index 676ef0a44b..22bac105c4 100644 --- a/.gitlab/ci/pre_check.yml +++ b/.gitlab/ci/pre_check.yml @@ -193,12 +193,3 @@ check_commit_msg: - git log -n10 --oneline # commit start with "WIP: " need to be squashed before merge - 'git log --pretty=%s master.. -- | grep "^WIP: " && exit 1 || exit 0' - -check_tools_file_patterns: - extends: .pre_check_job_template - image: $CI_DOCKER_REGISTRY/ubuntu-test-env$BOT_DOCKER_IMAGE_TAG - variables: - PYTHON_VER: 3.7.7 - script: - - python tools/ci/check_tools_files_patterns.py - allow_failure: true diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 0fa2a43527..6519087baf 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -108,6 +108,14 @@ repos: language: python files: \.(py|c|h|cpp|hpp|ld)$ require_serial: true + - id: check-tools-files-patterns + name: Check tools dir files patterns + entry: tools/ci/check_tools_files_patterns.py + language: python + files: '^tools/.+' + additional_dependencies: + - PyYAML == 5.3.1 + pass_filenames: false - repo: https://github.com/pre-commit/pre-commit-hooks rev: v4.0.1 hooks: diff --git a/tools/ci/check_copyright_ignore.txt b/tools/ci/check_copyright_ignore.txt index 303ae6bee5..96e7a7b04e 100644 --- a/tools/ci/check_copyright_ignore.txt +++ b/tools/ci/check_copyright_ignore.txt @@ -3974,7 +3974,6 @@ tools/ci/check_public_headers.py tools/ci/check_readme_links.py tools/ci/check_rules_yml.py tools/ci/check_soc_struct_headers.py -tools/ci/check_tools_files_patterns.py tools/ci/check_type_comments.py tools/ci/checkout_project_ref.py tools/ci/ci_fetch_submodule.py diff --git a/tools/ci/check_tools_files_patterns.py b/tools/ci/check_tools_files_patterns.py index 35d1372935..b6bd762de9 100755 --- a/tools/ci/check_tools_files_patterns.py +++ b/tools/ci/check_tools_files_patterns.py @@ -1,18 +1,7 @@ #!/usr/bin/env python # -# Copyright 2021 Espressif Systems (Shanghai) CO LTD -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. +# SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD +# SPDX-License-Identifier: Apache-2.0 import argparse import fnmatch @@ -35,9 +24,9 @@ def _ishidden(path): # pylint: disable=W0613 fnmatch.translate = translate -glob.magic_check = magic_check -glob.magic_check_bytes = magic_check_bytes -glob._ishidden = _ishidden # pylint: disable=W0212 +glob.magic_check = magic_check # type: ignore +glob.magic_check_bytes = magic_check_bytes # type: ignore +glob._ishidden = _ishidden # type: ignore # pylint: disable=W0212 # ends here @@ -80,15 +69,22 @@ if __name__ == '__main__': res = 0 not_included_files, dup_patterns = check(args.pattern_yml, args.exclude_list) - if not_included_files: - print('Missing Files: (please add to tools/ci/exclude_check_tools_files.txt') - for file in not_included_files: - print(file) - res = 1 - if dup_patterns: - print('Duplicated Patterns: (please check .gitlab/ci/rules.yml and tools/ci/exclude_check_tools_files.txt') - for pattern in dup_patterns: - print(pattern) + if not_included_files or dup_patterns: res = 1 + print('This test is used for making sure of all the tools dir files are recorded in .gitlab/ci/rules.yml to ' + 'trigger the related tests, except those files should be excluded.') + if not_included_files: + print('Missing Files:') + for file in not_included_files: + print('\t' + file) + print('Please add these files or glob patterns to ".gitlab/ci/rules.yml" and put related files under ' + '".patterns-" block to trigger related tests.\n' + 'Or add them to "tools/ci/exclude_check_tools_files.txt" to exclude them.') + + if dup_patterns: + print('Duplicated Patterns:') + for pattern in dup_patterns: + print('\t' + pattern) + print('Please remove them from tools/ci/exclude_check_tools_files.txt') sys.exit(res)