mirror of https://github.com/TheAlgorithms/C
chore: use the `DIRECTORY.md` workflow from the `scripts` repository (#1096)
* updating DIRECTORY.md * chore: use the scripts repository for... ...the `DIRECTORY.md` workflow. The code is much shorter now as well. * updating DIRECTORY.md Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
This commit is contained in:
parent
1a6ed6bf1c
commit
8fa62620c2
|
@ -42,54 +42,10 @@ jobs:
|
|||
done
|
||||
git commit -am "formatting filenames ${GITHUB_SHA::8}" || true
|
||||
- name: Update DIRECTORY.md
|
||||
shell: python
|
||||
run: |
|
||||
import os
|
||||
from typing import Iterator
|
||||
|
||||
URL_BASE = "https://github.com/TheAlgorithms/C/blob/master"
|
||||
g_output = []
|
||||
|
||||
def good_filepaths(top_dir: str = ".") -> Iterator[str]:
|
||||
cpp_exts = tuple(".c .c++ .cc .cpp .cu .cuh .cxx .h .h++ .hh .hpp .hxx".split())
|
||||
for dirpath, dirnames, filenames in os.walk(top_dir):
|
||||
dirnames[:] = [d for d in dirnames if d[0] not in "._"]
|
||||
for filename in filenames:
|
||||
if os.path.splitext(filename)[1].lower() in cpp_exts:
|
||||
yield os.path.join(dirpath, filename).lstrip("./")
|
||||
|
||||
def md_prefix(i):
|
||||
return f"{i * ' '}*" if i else "\n##"
|
||||
|
||||
def print_path(old_path: str, new_path: str) -> str:
|
||||
global g_output
|
||||
old_parts = old_path.split(os.sep)
|
||||
for i, new_part in enumerate(new_path.split(os.sep)):
|
||||
if i + 1 > len(old_parts) or old_parts[i] != new_part:
|
||||
if new_part:
|
||||
g_output.append(f"{md_prefix(i)} {new_part.replace('_', ' ').title()}")
|
||||
return new_path
|
||||
|
||||
def build_directory_md(top_dir: str = ".") -> str:
|
||||
global g_output
|
||||
old_path = ""
|
||||
for filepath in sorted(good_filepaths(), key=str.lower):
|
||||
filepath, filename = os.path.split(filepath)
|
||||
if filepath != old_path:
|
||||
old_path = print_path(old_path, filepath)
|
||||
indent = (filepath.count(os.sep) + 1) if filepath else 0
|
||||
url = "/".join((URL_BASE, filepath, filename)).replace(" ", "%20")
|
||||
filename = os.path.splitext(filename.replace("_", " ").title())[0]
|
||||
g_output.append(f"{md_prefix(indent)} [{filename}]({url})")
|
||||
return "# List of all files\n" + "\n".join(g_output)
|
||||
|
||||
with open("DIRECTORY.md", "w") as out_file:
|
||||
out_file.write(build_directory_md(".") + "\n")
|
||||
- name: Commit DIRECTORY.md
|
||||
run: |
|
||||
git diff DIRECTORY.md
|
||||
git add DIRECTORY.md
|
||||
git commit -m "updating DIRECTORY.md" || true
|
||||
wget https://raw.githubusercontent.com/TheAlgorithms/scripts/main/build_directory_md.py
|
||||
python3 build_directory_md.py C . .c,.h > DIRECTORY.md
|
||||
git commit -m "updating DIRECTORY.md" DIRECTORY.md || true
|
||||
- name: Get file changes
|
||||
run: |
|
||||
git remote -v
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
# List of all files
|
||||
|
||||
## Audio
|
||||
* [Alaw](https://github.com/TheAlgorithms/C/blob/master/audio/alaw.c)
|
||||
|
@ -170,6 +169,7 @@
|
|||
* [11](https://github.com/TheAlgorithms/C/blob/master/leetcode/src/11.c)
|
||||
* [110](https://github.com/TheAlgorithms/C/blob/master/leetcode/src/110.c)
|
||||
* [112](https://github.com/TheAlgorithms/C/blob/master/leetcode/src/112.c)
|
||||
* [118](https://github.com/TheAlgorithms/C/blob/master/leetcode/src/118.c)
|
||||
* [1184](https://github.com/TheAlgorithms/C/blob/master/leetcode/src/1184.c)
|
||||
* [1189](https://github.com/TheAlgorithms/C/blob/master/leetcode/src/1189.c)
|
||||
* [12](https://github.com/TheAlgorithms/C/blob/master/leetcode/src/12.c)
|
||||
|
@ -193,6 +193,7 @@
|
|||
* [203](https://github.com/TheAlgorithms/C/blob/master/leetcode/src/203.c)
|
||||
* [206](https://github.com/TheAlgorithms/C/blob/master/leetcode/src/206.c)
|
||||
* [21](https://github.com/TheAlgorithms/C/blob/master/leetcode/src/21.c)
|
||||
* [2130](https://github.com/TheAlgorithms/C/blob/master/leetcode/src/2130.c)
|
||||
* [215](https://github.com/TheAlgorithms/C/blob/master/leetcode/src/215.c)
|
||||
* [217](https://github.com/TheAlgorithms/C/blob/master/leetcode/src/217.c)
|
||||
* [226](https://github.com/TheAlgorithms/C/blob/master/leetcode/src/226.c)
|
||||
|
@ -226,6 +227,7 @@
|
|||
* [561](https://github.com/TheAlgorithms/C/blob/master/leetcode/src/561.c)
|
||||
* [6](https://github.com/TheAlgorithms/C/blob/master/leetcode/src/6.c)
|
||||
* [617](https://github.com/TheAlgorithms/C/blob/master/leetcode/src/617.c)
|
||||
* [62](https://github.com/TheAlgorithms/C/blob/master/leetcode/src/62.c)
|
||||
* [647](https://github.com/TheAlgorithms/C/blob/master/leetcode/src/647.c)
|
||||
* [66](https://github.com/TheAlgorithms/C/blob/master/leetcode/src/66.c)
|
||||
* [674](https://github.com/TheAlgorithms/C/blob/master/leetcode/src/674.c)
|
||||
|
|
Loading…
Reference in New Issue