Skip to content

Commit 1fbb2f5

Browse files
committed
ci: add pre-commit check
1 parent 412d95a commit 1fbb2f5

File tree

3 files changed

+77
-15
lines changed

3 files changed

+77
-15
lines changed

.gitlab/ci/pre_check.yml

+37-14
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,53 @@
1-
check_readme_links:
2-
extends:
3-
- .rules:pre_check:readme
1+
.pre_check_template:
42
stage: pre_check
53
image: python:3.9
64
tags: ["build", "amd64", "internet"]
7-
allow_failure: true
8-
script:
9-
- python ${CI_PROJECT_DIR}/tools/ci/check_readme_links.py
5+
dependencies: []
106

117
check_copyright:
12-
stage: pre_check
13-
image: python:3.9
14-
tags: ["build", "amd64", "internet"]
15-
allow_failure: true
8+
extends:
9+
- .pre_check_template
10+
allow_failure: false
1611
before_script:
1712
- pip install git+https://github.com/espressif/[email protected]
1813
script:
1914
- python -m check_copyright --verbose --dry-run --ignore tools/ci/ignore_list_copyright.txt --config tools/ci/check_copyright_config.yaml .
2015

2116
check_example_paths:
2217
extends:
18+
- .pre_check_template
2319
- .rules:pre_check:components
24-
stage: pre_check
25-
image: python:3.9
26-
tags: ["build", "amd64", "internet"]
2720
script:
2821
- pip install --upgrade pip
2922
- pip install pyyaml
30-
- python ${CI_PROJECT_DIR}/tools/ci/check_components.py
23+
- python ${CI_PROJECT_DIR}/tools/ci/check_components.py
24+
25+
check_pre_commit:
26+
extends:
27+
- .pre_check_template
28+
before_script:
29+
- pip install pre-commit
30+
script:
31+
- |
32+
# merged results pipelines, by default
33+
if [[ -n $CI_MERGE_REQUEST_SOURCE_BRANCH_SHA ]]; then
34+
MODIFIED_FILES=$(git diff --name-only $CI_MERGE_REQUEST_DIFF_BASE_SHA $CI_MERGE_REQUEST_SOURCE_BRANCH_SHA)
35+
# merge request pipelines, when the mr got conflicts
36+
elif [[ -n $CI_MERGE_REQUEST_DIFF_BASE_SHA ]]; then
37+
MODIFIED_FILES=$(git diff --name-only $CI_MERGE_REQUEST_DIFF_BASE_SHA $CI_COMMIT_SHA)
38+
# other pipelines, like the protected branches pipelines
39+
else
40+
MODIFIED_FILES=$(git diff --name-only $CI_COMMIT_BEFORE_SHA $CI_COMMIT_SHA)
41+
fi
42+
# print the MODIFIED_FILES
43+
echo "MODIFIED_FILES: $MODIFIED_FILES"
44+
- pre-commit install --allow-missing-config -t pre-commit -t commit-msg
45+
- pre-commit run --files $MODIFIED_FILES
46+
47+
check_readme_links:
48+
extends:
49+
- .pre_check_template
50+
- .rules:pre_check:readme
51+
allow_failure: true
52+
script:
53+
- python ${CI_PROJECT_DIR}/tools/ci/check_readme_links.py

.pre-commit-config.yaml

+38-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,41 @@ repos:
66
rev: v1.0.3
77
hooks:
88
- id: check-copyright
9-
args: ['--config', 'tools/ci/check_copyright_config.yaml', '--ignore', 'tools/ci/ignore_list_copyright.txt']
9+
args: ['--config', 'tools/ci/check_copyright_config.yaml', '--ignore', 'tools/ci/ignore_list_copyright.txt']
10+
- repo: https://github.com/pre-commit/pre-commit-hooks
11+
rev: v4.0.1
12+
hooks:
13+
- id: file-contents-sorter
14+
files: 'tools\/ci\/(executable-list\.txt|mypy_ignore_list\.txt|check_copyright_ignore\.txt)'
15+
- repo: https://github.com/pre-commit/pre-commit-hooks
16+
rev: v4.0.1
17+
hooks:
18+
- id: trailing-whitespace
19+
# note: whitespace exclusions use multiline regex, see https://pre-commit.com/#regular-expressions
20+
# items are:
21+
# 1 - some file extensions
22+
# 2 - any file matching *test*/*expected* (for host tests, if possible use this naming pattern always)
23+
# 3 - any directory named 'testdata'
24+
# 4 - protobuf auto-generated files
25+
exclude: &whitespace_excludes |
26+
(?x)^(
27+
.+\.(md|rst|map|bin)|
28+
.+test.*\/.*expected.*|
29+
.+\/testdata\/.+|
30+
.*_pb2.py|
31+
.*.pb-c.h|
32+
.*.pb-c.c|
33+
.*.yuv
34+
)$
35+
- id: end-of-file-fixer
36+
exclude: *whitespace_excludes
37+
- id: check-executables-have-shebangs
38+
- id: mixed-line-ending
39+
args: ['-f=lf']
40+
- id: double-quote-string-fixer
41+
- id: no-commit-to-branch
42+
name: Do not use more than one slash in the branch name
43+
args: ['--pattern', '^[^/]*/[^/]*/']
44+
- id: no-commit-to-branch
45+
name: Do not use uppercase letters in the branch name
46+
args: ['--pattern', '^[^A-Z]*[A-Z]']

CONTRIBUTING.rst

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ Before sending us a Pull Request, please consider this list of points:
1717

1818
* Does any new code conform to the esp-idf : :doc:`Style Guide <style-guide>` ?
1919

20+
* Have you installed the `pre-commit hook <https://docs.espressif.com/projects/esp-idf/en/stable/esp32/contribute/install-pre-commit-hook.html>`_ for the esp-iot-solution project?
21+
2022
* Does the code documentation follow requirements in `Documenting-code <http://docs.espressif.com/projects/esp-idf/en/stable/contribute/documenting-code.html>`_ ?
2123

2224
* Is the code adequately commented for people to understand how it is structured?

0 commit comments

Comments
 (0)