You've already forked devops-exercises
scripts/run_ci.sh to cover directories in the exercises and topics dir (#315)
* Smoother practice experience * update ci to check all md files * fix some syntax * fix README-zh_CN.md * update syntax_lint accorging to PEP8 * Temporarily delete this question 'Explain the sidecar container pattern' to pass the workflow --------- Co-authored-by: zhangzhen <zhangzhen@nao.cas.cn> Co-authored-by: Arie Bregman <bregman.arie@gmail.com>
This commit is contained in:
@@ -11,12 +11,10 @@ $ python tests/syntax_lint.py
|
||||
|
||||
"""
|
||||
|
||||
import pathlib
|
||||
import sys
|
||||
|
||||
p = pathlib.Path(__file__).parent.parent.joinpath('README.md')
|
||||
p = sys.argv[1]
|
||||
|
||||
with open(p, 'rb') as f:
|
||||
file_list = [line.rstrip() for line in f.readlines()]
|
||||
|
||||
errors = []
|
||||
|
||||
@@ -31,9 +29,9 @@ def count_details(file_list):
|
||||
details_count = 0
|
||||
|
||||
for line_number, line in enumerate(file_list):
|
||||
if b'<details>' in line:
|
||||
if b"<details>" in line:
|
||||
details_count += 1
|
||||
if b'</details>' in line:
|
||||
if b"</details>" in line:
|
||||
details_final_count += 1
|
||||
|
||||
return details_count == details_final_count
|
||||
@@ -49,9 +47,9 @@ def count_summary(file_list):
|
||||
details_count = 0
|
||||
|
||||
for line_number, line in enumerate(file_list):
|
||||
if b'<summary>' in line:
|
||||
if b"<summary>" in line:
|
||||
details_count += 1
|
||||
if b'</summary>' in line:
|
||||
if b"</summary>" in line:
|
||||
details_final_count += 1
|
||||
|
||||
return details_count == details_final_count
|
||||
@@ -70,22 +68,22 @@ def check_details_tag(file_list):
|
||||
|
||||
after_detail = False
|
||||
error = False
|
||||
err_message = ''
|
||||
err_message = ""
|
||||
for line_number, line in enumerate(file_list):
|
||||
if b'<details>' in line and b'</details>' in line:
|
||||
if b"<details>" in line and b"</details>" in line:
|
||||
pass
|
||||
else:
|
||||
if b'<details>' in line and after_detail:
|
||||
err_message = f'Missing closing detail tag round line {line_number - 1}'
|
||||
if b"<details>" in line and after_detail:
|
||||
err_message = f"Missing closing detail tag round line {line_number - 1}"
|
||||
error = True
|
||||
if b'</details>' in line and not after_detail:
|
||||
err_message = f'Missing opening detail tag round line {line_number - 1}'
|
||||
if b"</details>" in line and not after_detail:
|
||||
err_message = f"Missing opening detail tag round line {line_number - 1}"
|
||||
error = True
|
||||
|
||||
if b'<details>' in line:
|
||||
if b"<details>" in line:
|
||||
after_detail = True
|
||||
|
||||
if b'</details>' in line and after_detail:
|
||||
if b"</details>" in line and after_detail:
|
||||
after_detail = False
|
||||
|
||||
if error:
|
||||
@@ -107,36 +105,48 @@ def check_summary_tag(file_list):
|
||||
|
||||
after_summary = False
|
||||
error = False
|
||||
err_message = ''
|
||||
for line_number, line in enumerate(file_list):
|
||||
if b'<summary>' in line and b'</summary>' in line:
|
||||
pass
|
||||
else:
|
||||
if b'<summary>' in line and after_summary:
|
||||
err_message = f'Missing closing summary tag around line {line_number}'
|
||||
error = True
|
||||
if b'</summary>' in line and not after_summary:
|
||||
err_message = f'Missing opening summary tag around line {line_number}'
|
||||
err_message = ""
|
||||
for idx, line in enumerate(file_list):
|
||||
line_number = idx + 1
|
||||
if b"<summary>" in line and b"</summary>" in line:
|
||||
if after_summary:
|
||||
err_message = f"Missing closing summary tag around line {line_number}"
|
||||
error = True
|
||||
|
||||
if b'<summary>' in line:
|
||||
else:
|
||||
if b"<summary>" in line and after_summary:
|
||||
err_message = f"Missing closing summary tag around line {line_number}"
|
||||
error = True
|
||||
if b"</summary>" in line and not after_summary:
|
||||
err_message = f"Missing opening summary tag around line {line_number}"
|
||||
error = True
|
||||
|
||||
if b"<summary>" in line:
|
||||
after_summary = True
|
||||
|
||||
if b'</summary>' in line and after_summary:
|
||||
if b"</summary>" in line and after_summary:
|
||||
after_summary = False
|
||||
|
||||
if error:
|
||||
errors.append(err_message)
|
||||
if error:
|
||||
errors.append(err_message)
|
||||
|
||||
error = False
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
def check_md_file(file_name):
|
||||
with open(p, "rb") as f:
|
||||
file_list = [line.rstrip() for line in f.readlines()]
|
||||
check_details_tag(file_list)
|
||||
check_summary_tag(file_list)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
print(f"..........Checking {p}..........")
|
||||
check_md_file(p)
|
||||
if errors:
|
||||
print(f"{p} failed", file=sys.stderr)
|
||||
for error in errors:
|
||||
print(error)
|
||||
print(error, file=sys.stderr)
|
||||
exit(1)
|
||||
|
||||
print("Tests passed successfully.")
|
||||
|
||||
Reference in New Issue
Block a user