From 8fa62620c2106b96973384ad225c2f3de50192a3 Mon Sep 17 00:00:00 2001 From: David Leal Date: Mon, 24 Oct 2022 14:48:49 -0500 Subject: [PATCH] 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> --- .github/workflows/awesome_workflow.yml | 50 ++------------------------ DIRECTORY.md | 4 ++- 2 files changed, 6 insertions(+), 48 deletions(-) diff --git a/.github/workflows/awesome_workflow.yml b/.github/workflows/awesome_workflow.yml index 582bc9c6..8b70b04c 100644 --- a/.github/workflows/awesome_workflow.yml +++ b/.github/workflows/awesome_workflow.yml @@ -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 diff --git a/DIRECTORY.md b/DIRECTORY.md index fa52f96f..a6e53d03 100644 --- a/DIRECTORY.md +++ b/DIRECTORY.md @@ -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)