|
6 | 6 | runs-on: ubuntu-latest
|
7 | 7 | steps:
|
8 | 8 | - uses: actions/checkout@master
|
9 |
| - - uses: actions/setup-python@master |
10 |
| - - name: update_directory_md |
11 |
| - shell: python |
12 |
| - run: | |
13 |
| - import os |
14 |
| - from typing import Iterator |
15 |
| -
|
16 |
| - URL_BASE = "https://github.com/TheAlgorithms/Javascript/blob/master" |
17 |
| - g_output = [] |
18 |
| -
|
19 |
| -
|
20 |
| - def good_filepaths(top_dir: str = ".") -> Iterator[str]: |
21 |
| - for dirpath, dirnames, filenames in os.walk(top_dir): |
22 |
| - dirnames[:] = [d for d in dirnames if d[0] not in "._"] |
23 |
| - for filename in filenames: |
24 |
| - if os.path.splitext(filename)[1].lower() == ".js": |
25 |
| - yield os.path.join(dirpath, filename).lstrip("./") |
26 |
| -
|
27 |
| -
|
28 |
| - def md_prefix(i): |
29 |
| - return f"{i * ' '}*" if i else "\n##" |
30 |
| -
|
31 |
| -
|
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('_', ' ')}") |
39 |
| - return new_path |
40 |
| -
|
41 |
| -
|
42 |
| - def build_directory_md(top_dir: str = ".") -> str: |
43 |
| - global g_output |
44 |
| - old_path = "" |
45 |
| - for filepath in sorted(good_filepaths(), key=str.lower): |
46 |
| - filepath, filename = os.path.split(filepath) |
47 |
| - if filepath != old_path: |
48 |
| - old_path = print_path(old_path, filepath) |
49 |
| - indent = (filepath.count(os.sep) + 1) if filepath else 0 |
50 |
| - url = "/".join((URL_BASE, filepath, filename)).replace(" ", "%20") |
51 |
| - filename = os.path.splitext(filename.replace("_", " "))[0] |
52 |
| - g_output.append(f"{md_prefix(indent)} [{filename}]({url})") |
53 |
| - return "\n".join(g_output) |
54 |
| -
|
55 |
| -
|
56 |
| - with open("DIRECTORY.md", "w") as out_file: |
57 |
| - out_file.write(build_directory_md(".") + "\n") |
58 |
| -
|
59 |
| - - name: Update DIRECTORY.md |
60 |
| - run: | |
| 9 | + - uses: actions/setup-node@v1 |
| 10 | + - run: | |
| 11 | + node .github/workflows/UpdateDirectory.js |
61 | 12 | cat DIRECTORY.md
|
62 | 13 | git config --global user.name github-actions
|
63 | 14 | git config --global user.email '${GITHUB_ACTOR}@users.noreply.github.com'
|
|
0 commit comments