Skip to content

Commit 71b9193

Browse files
committed
ディレクトリ構造の検査を追加
1 parent fe17c89 commit 71b9193

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ jobs:
3535
# SKIP_BUILD=true bundle exec rake test
3636
# NOTE: サイトが仕上がったら、上記テストを走らせると自動検知できる。
3737
# ただ初期は自動検知の通知が多すぎるので手動で実行するのが吉。
38+
python test-directory-structure.py
3839
3940
# Deploy job is triggered only pushed to main branch && CI passed
4041
deploy:
@@ -86,4 +87,3 @@ jobs:
8687
with:
8788
personal_token: ${{ secrets.GITHUB_TOKEN }}
8889
publish_dir: ./_site
89-

test-directory-structure.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/usr/bin/python
2+
from pathlib import Path
3+
4+
"""
5+
すべてのページが index.html として生成されているか検査するスクリプト
6+
7+
foobar/baz/index.html
8+
-> /foobar/baz/ と /foobar/baz の双方がルーティングできる
9+
10+
foobar/baz.html
11+
-> /foobar/baz/ がルーティングできない
12+
"""
13+
14+
15+
def main() -> int:
16+
allowed_names = ["index.html", "404.html"]
17+
errors = list[str]()
18+
19+
for cwd, _dirs, files in Path("_site").walk():
20+
for file in files:
21+
if not file.endswith(".html"):
22+
continue
23+
24+
if file in allowed_names:
25+
continue
26+
27+
path = cwd.joinpath(file).as_posix()
28+
errors.append(path)
29+
30+
if 0 < len(errors):
31+
print("index.html でない HTML ファイルが生成されました:")
32+
for i in errors:
33+
print(f"- {i}")
34+
return 1
35+
36+
return 0
37+
38+
39+
if __name__ == "__main__":
40+
import sys
41+
42+
sys.exit(main())

0 commit comments

Comments
 (0)