Skip to content

Commit 45bf766

Browse files
imp2002github-actionssiriak
authored
fix(action): the build directory_md workflow (TheAlgorithms#213)
Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Co-authored-by: Andrii Siriak <siryaka@gmail.com>
1 parent 8f8ad15 commit 45bf766

File tree

3 files changed

+58
-46
lines changed

3 files changed

+58
-46
lines changed
Lines changed: 4 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: directory_md
1+
name: build_directory_md
22
on: [push, pull_request]
33

44
jobs:
@@ -14,45 +14,11 @@ jobs:
1414
git config --global user.email '${GITHUB_ACTOR}@users.noreply.github.com'
1515
git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY
1616
- name: Update DIRECTORY.md
17-
shell: python
1817
run: |
19-
import os
20-
from typing import Iterator
21-
URL_BASE = "https://github.com/TheAlgorithms/Rust/blob/master"
22-
g_output = []
23-
def good_filepaths(top_dir: str = ".") -> Iterator[str]:
24-
fs_exts = tuple(".rs".split())
25-
for dirpath, dirnames, filenames in os.walk(top_dir):
26-
dirnames[:] = [d for d in dirnames if d[0] not in "._"]
27-
for filename in filenames:
28-
if os.path.splitext(filename)[1].lower() in fs_exts:
29-
yield os.path.join(dirpath, filename).lstrip("./")
30-
def md_prefix(i):
31-
return f"{i * ' '}*" if i else "\n##"
32-
def print_path(old_path: str, new_path: str) -> str:
33-
global g_output
34-
old_parts = old_path.split(os.sep)
35-
for i, new_part in enumerate(new_path.split(os.sep)):
36-
if i + 1 > len(old_parts) or old_parts[i] != new_part:
37-
if new_part:
38-
g_output.append(f"{md_prefix(i)} {new_part.replace('_', ' ').title()}")
39-
return new_path
40-
def build_directory_md(top_dir: str = ".") -> str:
41-
global g_output
42-
old_path = ""
43-
for filepath in sorted(good_filepaths(), key=str.lower):
44-
filepath, filename = os.path.split(filepath)
45-
if filepath != old_path:
46-
old_path = print_path(old_path, filepath)
47-
indent = (filepath.count(os.sep) + 1) if filepath else 0
48-
url = "/".join((URL_BASE, filepath, filename)).replace(" ", "%20")
49-
filename = os.path.splitext(filename.replace("_", " ").title())[0]
50-
g_output.append(f"{md_prefix(indent)} [{filename}]({url})")
51-
return "# List of all files\n" + "\n".join(g_output)
52-
with open("DIRECTORY.md", "w") as out_file:
53-
out_file.write(build_directory_md(".") + "\n")
18+
python .github/workflows/scripts/build_directory_md.py
5419
- name: Commit DIRECTORY.md
5520
run: |
56-
git commit -m "updating DIRECTORY.md" DIRECTORY.md || true
21+
git add DIRECTORY.md
22+
git commit -m "updating DIRECTORY.md" || true
5723
git diff DIRECTORY.md
5824
git push --force origin HEAD:$GITHUB_REF || true
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import os
2+
3+
from typing import Iterator
4+
5+
URL_BASE = "https://github.com/TheAlgorithms/Rust/blob/master"
6+
7+
g_output = []
8+
9+
10+
def good_filepaths(top_dir: str = ".") -> Iterator[str]:
11+
fs_exts = tuple(".rs".split())
12+
for dirpath, dirnames, filenames in os.walk(top_dir):
13+
dirnames[:] = [d for d in dirnames if d[0] not in "._"]
14+
for filename in filenames:
15+
if filename != "mod.rs" and os.path.splitext(filename)[1].lower() in fs_exts:
16+
yield os.path.join(dirpath, filename).lstrip("./")
17+
18+
19+
def md_prefix(i):
20+
return f"{i * ' '}*" if i else "\n##"
21+
22+
23+
def print_path(old_path: str, new_path: str) -> str:
24+
global g_output
25+
old_parts = old_path.split(os.sep)
26+
for i, new_part in enumerate(new_path.split(os.sep)):
27+
if i + 1 > len(old_parts) or old_parts[i] != new_part:
28+
if new_part:
29+
print(f"{md_prefix(i)} {new_part.replace('_', ' ').title()}")
30+
g_output.append(f"{md_prefix(i)} {new_part.replace('_', ' ').title()}")
31+
return new_path
32+
33+
34+
def build_directory_md(top_dir: str = ".") -> str:
35+
global g_output
36+
old_path = ""
37+
for filepath in sorted(good_filepaths(), key=str.lower):
38+
filepath, filename = os.path.split(filepath)
39+
if filepath != old_path:
40+
old_path = print_path(old_path, filepath)
41+
indent = (filepath.count(os.sep) + 1) if filepath else 0
42+
url = "/".join((URL_BASE, filepath, filename)).replace(" ", "%20")
43+
filename = os.path.splitext(filename.replace("_", " ").title())[0]
44+
print((f"{md_prefix(indent)} [{filename}]({url})"))
45+
g_output.append(f"{md_prefix(indent)} [{filename}]({url})")
46+
47+
return "# List of all files\n" + "\n".join(g_output)
48+
49+
50+
with open("DIRECTORY.md", "w") as out_file:
51+
out_file.write(build_directory_md(".") + "\n")

DIRECTORY.md

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,14 @@
33
## Src
44
* Ciphers
55
* [Caesar](https://github.com/TheAlgorithms/Rust/blob/master/src/ciphers/caesar.rs)
6-
* [Mod](https://github.com/TheAlgorithms/Rust/blob/master/src/ciphers/mod.rs)
6+
* [Morse Code](https://github.com/TheAlgorithms/Rust/blob/master/src/ciphers/morse_code.rs)
77
* [Rot13](https://github.com/TheAlgorithms/Rust/blob/master/src/ciphers/rot13.rs)
88
* [Vigenere](https://github.com/TheAlgorithms/Rust/blob/master/src/ciphers/vigenere.rs)
9-
* [Morse Code](https://github.com/TheAlgorithms/Rust/blob/master/src/ciphers/morse_code.rs)
109
* Data Structures
1110
* [B Tree](https://github.com/TheAlgorithms/Rust/blob/master/src/data_structures/b_tree.rs)
1211
* [Binary Search Tree](https://github.com/TheAlgorithms/Rust/blob/master/src/data_structures/binary_search_tree.rs)
1312
* [Heap](https://github.com/TheAlgorithms/Rust/blob/master/src/data_structures/heap.rs)
1413
* [Linked List](https://github.com/TheAlgorithms/Rust/blob/master/src/data_structures/linked_list.rs)
15-
* [Mod](https://github.com/TheAlgorithms/Rust/blob/master/src/data_structures/mod.rs)
1614
* Dynamic Programming
1715
* [Coin Change](https://github.com/TheAlgorithms/Rust/blob/master/src/dynamic_programming/coin_change.rs)
1816
* [Edit Distance](https://github.com/TheAlgorithms/Rust/blob/master/src/dynamic_programming/edit_distance.rs)
@@ -21,28 +19,25 @@
2119
* [Knapsack](https://github.com/TheAlgorithms/Rust/blob/master/src/dynamic_programming/knapsack.rs)
2220
* [Longest Common Subsequence](https://github.com/TheAlgorithms/Rust/blob/master/src/dynamic_programming/longest_common_subsequence.rs)
2321
* [Maximum Subarray](https://github.com/TheAlgorithms/Rust/blob/master/src/dynamic_programming/maximum_subarray.rs)
24-
* [Mod](https://github.com/TheAlgorithms/Rust/blob/master/src/dynamic_programming/mod.rs)
2522
* General
2623
* [Convex Hull](https://github.com/TheAlgorithms/Rust/blob/master/src/general/convex_hull.rs)
2724
* [Hanoi](https://github.com/TheAlgorithms/Rust/blob/master/src/general/hanoi.rs)
2825
* [Kmeans](https://github.com/TheAlgorithms/Rust/blob/master/src/general/kmeans.rs)
29-
* [Mod](https://github.com/TheAlgorithms/Rust/blob/master/src/general/mod.rs)
3026
* [Lib](https://github.com/TheAlgorithms/Rust/blob/master/src/lib.rs)
3127
* Searching
3228
* [Binary Search](https://github.com/TheAlgorithms/Rust/blob/master/src/searching/binary_search.rs)
3329
* [Linear Search](https://github.com/TheAlgorithms/Rust/blob/master/src/searching/linear_search.rs)
34-
* [Mod](https://github.com/TheAlgorithms/Rust/blob/master/src/searching/mod.rs)
3530
* Sorting
3631
* [Bubble Sort](https://github.com/TheAlgorithms/Rust/blob/master/src/sorting/bubble_sort.rs)
3732
* [Counting Sort](https://github.com/TheAlgorithms/Rust/blob/master/src/sorting/counting_sort.rs)
3833
* [Heap Sort](https://github.com/TheAlgorithms/Rust/blob/master/src/sorting/heap_sort.rs)
3934
* [Insertion Sort](https://github.com/TheAlgorithms/Rust/blob/master/src/sorting/insertion_sort.rs)
4035
* [Merge Sort](https://github.com/TheAlgorithms/Rust/blob/master/src/sorting/merge_sort.rs)
41-
* [Mod](https://github.com/TheAlgorithms/Rust/blob/master/src/sorting/mod.rs)
4236
* [Quick Sort](https://github.com/TheAlgorithms/Rust/blob/master/src/sorting/quick_sort.rs)
4337
* [Radix Sort](https://github.com/TheAlgorithms/Rust/blob/master/src/sorting/radix_sort.rs)
4438
* [Selection Sort](https://github.com/TheAlgorithms/Rust/blob/master/src/sorting/selection_sort.rs)
4539
* [Shell Sort](https://github.com/TheAlgorithms/Rust/blob/master/src/sorting/shell_sort.rs)
4640
* String
4741
* [Knuth Morris Pratt](https://github.com/TheAlgorithms/Rust/blob/master/src/string/knuth_morris_pratt.rs)
48-
* [Mod](https://github.com/TheAlgorithms/Rust/blob/master/src/string/mod.rs)
42+
* [Manacher](https://github.com/TheAlgorithms/Rust/blob/master/src/string/manacher.rs)
43+
* [Rabin Karp](https://github.com/TheAlgorithms/Rust/blob/master/src/string/rabin_karp.rs)

0 commit comments

Comments
 (0)