-
Notifications
You must be signed in to change notification settings - Fork 753
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add conditional mark sort check to pre-commit hook (#8162)
What is the motivation for this PR? In conditional mark, testcases should be sorted from A to Z, and there is no support to check it in PR test. How did you do it? Add a pre-commit hook under sonic-mgmt repo to check conditional mark sort, if testcases are not sorted, pre-commit will fail, need to fix it before PR get merged.
- Loading branch information
1 parent
f8cdd33
commit b886f21
Showing
9 changed files
with
71 additions
and
47 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import re | ||
import sys | ||
|
||
|
||
def main(): | ||
stage_files = sys.argv[1:] | ||
retval = 0 | ||
for stage_file in stage_files: | ||
if "tests_mark_conditions" in stage_file: | ||
conditions = [] | ||
with open(stage_file, 'r') as f: | ||
file_contents = f.readlines() | ||
if not file_contents: | ||
continue | ||
for line in file_contents: | ||
if re.match('^[a-zA-Z]', line): | ||
conditions.append(line.strip().rstrip(":")) | ||
sorted_conditions = conditions[:] | ||
sorted_conditions.sort() | ||
if conditions != sorted_conditions: | ||
print("The entries in tests/common/plugins/conditional_mark/tests_mark_conditions*.yaml " | ||
"are not sorted in alphabetic order.") | ||
retval = 1 | ||
return retval | ||
|
||
|
||
if __name__ == "__main__": | ||
raise SystemExit(main()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
- id: check-conditional-mark-sort | ||
name: check conditional mark sort | ||
description: check conditional mark yaml file sort from A to Z. | ||
entry: check-conditional-mark-sort | ||
language: python | ||
types: [yaml] |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Local pre-commit hook config | ||
[project] | ||
name = "sonic-mgmt-pre-commit-hooks" | ||
version = "1.0.0+pre_commit" | ||
description = "Some hooks for pre-commit in sonic-mgmt repo." | ||
classifiers = [ | ||
"Programming Language :: Python :: 3", | ||
"Programming Language :: Python :: 3 :: Only", | ||
"Programming Language :: Python :: Implementation :: CPython", | ||
"Programming Language :: Python :: Implementation :: PyPy", | ||
] | ||
requires-python = ">=3.7" | ||
dependencies = ["tomli>=2.0.1;python_version<'4.0'"] | ||
|
||
[project.urls] | ||
Homepage = "https://github.com/sonic-net/sonic-mgmt" | ||
|
||
[tool.setuptools] | ||
package-dir = {"" = ".hooks"} | ||
|
||
[tool.setuptools.packages.find] | ||
where = [".hooks"] | ||
|
||
[project.scripts] | ||
check-conditional-mark-sort = 'pre_commit_hooks.check_conditional_mark_sort:main' | ||
|
||
[tool.black] | ||
exclude = ''' | ||
/( | ||
spytest/ | ||
)/ | ||
''' |