@@ -47,51 +47,10 @@ jobs:
47
47
git commit -am "formatting filenames ${GITHUB_SHA::8}" || true
48
48
49
49
- name : Update DIRECTORY.md
50
- shell : python
51
50
run : |
52
- import os
53
- from typing import Iterator
54
-
55
- URL_BASE = "https://github.com/TheAlgorithms/C-Plus-Plus/blob/master"
56
- g_output = []
57
-
58
- def good_filepaths(top_dir: str = ".") -> Iterator[str]:
59
- cpp_exts = tuple(".c .c++ .cc .cpp .cu .cuh .cxx .h .h++ .hh .hpp .hxx".split())
60
- for dirpath, dirnames, filenames in os.walk(top_dir):
61
- dirnames[:] = [d for d in dirnames if d[0] not in "._"]
62
- for filename in filenames:
63
- if os.path.splitext(filename)[1].lower() in cpp_exts:
64
- yield os.path.join(dirpath, filename).lstrip("./")
65
-
66
- def md_prefix(i):
67
- return f"{i * ' '}*" if i else "\n##"
68
-
69
- def print_path(old_path: str, new_path: str) -> str:
70
- global g_output
71
- old_parts = old_path.split(os.sep)
72
- for i, new_part in enumerate(new_path.split(os.sep)):
73
- if i + 1 > len(old_parts) or old_parts[i] != new_part:
74
- if new_part:
75
- g_output.append(f"{md_prefix(i)} {new_part.replace('_', ' ').title()}")
76
- return new_path
77
-
78
- def build_directory_md(top_dir: str = ".") -> str:
79
- global g_output
80
- old_path = ""
81
- for filepath in sorted(good_filepaths(), key=str.lower):
82
- filepath, filename = os.path.split(filepath)
83
- if filepath != old_path:
84
- old_path = print_path(old_path, filepath)
85
- indent = (filepath.count(os.sep) + 1) if filepath else 0
86
- url = "/".join((URL_BASE, filepath, filename)).replace(" ", "%20")
87
- filename = os.path.splitext(filename.replace("_", " ").title())[0]
88
- g_output.append(f"{md_prefix(indent)} [{filename}]({url})")
89
- return "# List of all files\n" + "\n".join(g_output)
90
-
91
- with open("DIRECTORY.md", "w") as out_file:
92
- out_file.write(build_directory_md(".") + "\n")
93
- - name : Commit DIRECTORY.md
94
- run : git commit -m "updating DIRECTORY.md" DIRECTORY.md || true
51
+ wget https://raw.githubusercontent.com/TheAlgorithms/scripts/main/build_directory_md.py
52
+ python3 build_directory_md.py C-Plus-Plus . .cpp,.hpp,.h > DIRECTORY.md
53
+ git commit -m "updating DIRECTORY.md" DIRECTORY.md || true
95
54
- name : Get file changes
96
55
run : |
97
56
git remote -v
0 commit comments