Skip to content

Commit fd029ae

Browse files
maltejurgithub-actions
andauthored
feat: update awesome_workflow.yml to use build_directory_md.py from scripts repository (TheAlgorithms#1486)
* Update awesome_workflow.yml * Also include .h and .hpp in DIRECTORY.md * updating DIRECTORY.md Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
1 parent a41b707 commit fd029ae

File tree

2 files changed

+3
-45
lines changed

2 files changed

+3
-45
lines changed

.github/workflows/awesome_workflow.yml

Lines changed: 3 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -47,51 +47,10 @@ jobs:
4747
git commit -am "formatting filenames ${GITHUB_SHA::8}" || true
4848
4949
- name: Update DIRECTORY.md
50-
shell: python
5150
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
9554
- name: Get file changes
9655
run: |
9756
git remote -v

DIRECTORY.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# List of all files
21

32
## Backtracking
43
* [Graph Coloring](https://github.com/TheAlgorithms/C-Plus-Plus/blob/master/backtracking/graph_coloring.cpp)

0 commit comments

Comments
 (0)