Skip to content

Commit 01e1ddd

Browse files
MengDanzzZhangZhen-Naocbregman-arie
authored
scripts/run_ci.sh to cover directories in the exercises and topics dir (bregman-arie#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 <[email protected]> Co-authored-by: Arie Bregman <[email protected]>
1 parent 50c9714 commit 01e1ddd

File tree

5 files changed

+61
-45
lines changed

5 files changed

+61
-45
lines changed

README-zh_CN.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@
289289
</b></details>
290290

291291
<details>
292-
<summary>你是如何实施从某个阶段而不是从最开始构建的选项?<summary><br><b>
292+
<summary>你是如何实施从某个阶段而不是从最开始构建的选项?</summary><br><b>
293293
</b></details>
294294

295295
<details>
@@ -924,7 +924,7 @@ Zombie(假死态)
924924
</b></details>
925925

926926
<details>
927-
<summary>你能解释一下网络进程/连接如何建立以及如何终止?><br></b>
927+
<summary>你能解释一下网络进程/连接如何建立以及如何终止?</summary><br></b>
928928
</b></details>
929929

930930
<details>
@@ -1385,6 +1385,7 @@ Terraform与其他工具相比的优势:
13851385
* Provider
13861386
* Resource
13871387
* Provisioner
1388+
</summary>
13881389
</b></details>
13891390

13901391
<details>
@@ -1656,7 +1657,7 @@ Docker Cloud构建在Docker Hub之上,因此Docker Cloud提供了
16561657
</b></details>
16571658

16581659
<details>
1659-
<summary>解释一下递归</summary<br><b>
1660+
<summary>解释一下递归</summary><br><b>
16601661
</b></details>
16611662

16621663
<details>
@@ -1951,11 +1952,11 @@ with open('file.txt', 'w') as file:
19511952
</b></details>
19521953

19531954
<details>
1954-
<summay>如何用 "blue" 替换字符串 "green"?</summary><br><b>
1955+
<summary>如何用 "blue" 替换字符串 "green"?</summary><br><b>
19551956
</b></details>
19561957

19571958
<details>
1958-
<summay>如何找到一个变量中的所有IP地址? 如何在文件中找到它们?</summary><br><b>
1959+
<summary>如何找到一个变量中的所有IP地址? 如何在文件中找到它们?</summary><br><b>
19591960
</b></details>
19601961

19611962
<details>
@@ -2072,6 +2073,7 @@ def reverse_string(string):
20722073
* Mergesort
20732074
* Bucket Sort
20742075
* Radix Sort
2076+
</summary>
20752077
</b></details>
20762078

20772079
<a name="python-advanced"></a>
@@ -2110,7 +2112,7 @@ def reverse_string(string):
21102112
</b></details>
21112113

21122114
<details>
2113-
<summary>你可以在Python中实现链接链表吗?<br><b>
2115+
<summary>你可以在Python中实现链接链表吗?</summary><br><b>
21142116
</b></details>
21152117

21162118
<details>
@@ -2832,7 +2834,7 @@ where c.Customer_ID in (Select Customer_ID from cat_food);
28322834
</b></details>
28332835

28342836
<details>
2835-
<summmary>详细描述如何使用可以从云外部访问的IP来启动实例</summary><br><b>
2837+
<summary>详细描述如何使用可以从云外部访问的IP来启动实例</summary><br><b>
28362838
</b></details>
28372839

28382840
<details>

scripts/run_ci.sh

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
#!/bin/bash
22
# These are the same steps we are running in Travis CI
33

4-
python $(dirname "$0")/../tests/syntax_lint.py
4+
5+
find . -name "*.md" -not -path "./tests/*" | \
6+
xargs -I {} \
7+
python $(dirname "$0")/../tests/syntax_lint.py {} > /dev/null
8+
mdPassed=$?
59
flake8 --max-line-length=100 . && echo "PEP8 Passed"
10+
pyPassed=$?
11+
if [ $pyPassed -eq 0 ] && [ $mdPassed -eq 0 ];then
12+
exit 0
13+
else
14+
exit 1
15+
fi

tests/syntax_lint.py

Lines changed: 40 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,10 @@
1111
1212
"""
1313

14-
import pathlib
14+
import sys
1515

16-
p = pathlib.Path(__file__).parent.parent.joinpath('README.md')
16+
p = sys.argv[1]
1717

18-
with open(p, 'rb') as f:
19-
file_list = [line.rstrip() for line in f.readlines()]
2018

2119
errors = []
2220

@@ -31,9 +29,9 @@ def count_details(file_list):
3129
details_count = 0
3230

3331
for line_number, line in enumerate(file_list):
34-
if b'<details>' in line:
32+
if b"<details>" in line:
3533
details_count += 1
36-
if b'</details>' in line:
34+
if b"</details>" in line:
3735
details_final_count += 1
3836

3937
return details_count == details_final_count
@@ -49,9 +47,9 @@ def count_summary(file_list):
4947
details_count = 0
5048

5149
for line_number, line in enumerate(file_list):
52-
if b'<summary>' in line:
50+
if b"<summary>" in line:
5351
details_count += 1
54-
if b'</summary>' in line:
52+
if b"</summary>" in line:
5553
details_final_count += 1
5654

5755
return details_count == details_final_count
@@ -70,22 +68,22 @@ def check_details_tag(file_list):
7068

7169
after_detail = False
7270
error = False
73-
err_message = ''
71+
err_message = ""
7472
for line_number, line in enumerate(file_list):
75-
if b'<details>' in line and b'</details>' in line:
73+
if b"<details>" in line and b"</details>" in line:
7674
pass
7775
else:
78-
if b'<details>' in line and after_detail:
79-
err_message = f'Missing closing detail tag round line {line_number - 1}'
76+
if b"<details>" in line and after_detail:
77+
err_message = f"Missing closing detail tag round line {line_number - 1}"
8078
error = True
81-
if b'</details>' in line and not after_detail:
82-
err_message = f'Missing opening detail tag round line {line_number - 1}'
79+
if b"</details>" in line and not after_detail:
80+
err_message = f"Missing opening detail tag round line {line_number - 1}"
8381
error = True
8482

85-
if b'<details>' in line:
83+
if b"<details>" in line:
8684
after_detail = True
8785

88-
if b'</details>' in line and after_detail:
86+
if b"</details>" in line and after_detail:
8987
after_detail = False
9088

9189
if error:
@@ -107,36 +105,48 @@ def check_summary_tag(file_list):
107105

108106
after_summary = False
109107
error = False
110-
err_message = ''
111-
for line_number, line in enumerate(file_list):
112-
if b'<summary>' in line and b'</summary>' in line:
113-
pass
108+
err_message = ""
109+
for idx, line in enumerate(file_list):
110+
line_number = idx + 1
111+
if b"<summary>" in line and b"</summary>" in line:
112+
if after_summary:
113+
err_message = f"Missing closing summary tag around line {line_number}"
114+
error = True
115+
114116
else:
115-
if b'<summary>' in line and after_summary:
116-
err_message = f'Missing closing summary tag around line {line_number}'
117+
if b"<summary>" in line and after_summary:
118+
err_message = f"Missing closing summary tag around line {line_number}"
117119
error = True
118-
if b'</summary>' in line and not after_summary:
119-
err_message = f'Missing opening summary tag around line {line_number}'
120+
if b"</summary>" in line and not after_summary:
121+
err_message = f"Missing opening summary tag around line {line_number}"
120122
error = True
121123

122-
if b'<summary>' in line:
124+
if b"<summary>" in line:
123125
after_summary = True
124126

125-
if b'</summary>' in line and after_summary:
127+
if b"</summary>" in line and after_summary:
126128
after_summary = False
127129

128-
if error:
129-
errors.append(err_message)
130+
if error:
131+
errors.append(err_message)
130132

131133
error = False
132134

133135

134-
if __name__ == '__main__':
136+
def check_md_file(file_name):
137+
with open(p, "rb") as f:
138+
file_list = [line.rstrip() for line in f.readlines()]
135139
check_details_tag(file_list)
136140
check_summary_tag(file_list)
141+
142+
143+
if __name__ == "__main__":
144+
print(f"..........Checking {p}..........")
145+
check_md_file(p)
137146
if errors:
147+
print(f"{p} failed", file=sys.stderr)
138148
for error in errors:
139-
print(error)
149+
print(error, file=sys.stderr)
140150
exit(1)
141151

142152
print("Tests passed successfully.")

topics/kubernetes/README.md

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2349,14 +2349,7 @@ The pod is automatically assigned with the default service account (in the names
23492349
23502350
### Patterns
23512351
2352-
<details>
2353-
<summary>Explain the sidecar container pattern</summary><br><b>
2354-
ion container, there is a sidecar container.
2355-
</b></details>
2356-
r, the application would not exist. In addition to the application container, there is a sidecar container.
23572352
2358-
In simpler words, when you have a Pod and there is more than one container running in that Pod that supports or complements the application container, it means you use the sidecar pattern.
2359-
</b></details>
23602353
23612354
### CronJob
23622355

topics/security/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ True. It is only used during the key exchange algorithm of symmetric encryption.
253253
Hashing is a mathematical function for mapping data of arbitrary sizes to fixed-size values. This function produces a "digest" of the data that can be used for verifying that the data has not been modified (amongst other uses)
254254
</b></details>
255255

256+
<details>
256257
<summary>How is hashing different from encryption?</summary><br><b>
257258

258259
Encrypted data can be decrypted to its original value. Hashed data cannot be reversed to view the original data - hashing is a one-way function.

0 commit comments

Comments
 (0)