From acfa2890a4f1fba2f56e7aca0e863d0ecb6e9f84 Mon Sep 17 00:00:00 2001 From: JarZombie Date: Sun, 2 Apr 2023 02:43:47 +0800 Subject: [PATCH] Fix DIRECTORY.md formatting (closes #3922) (#4124) --- .github/workflows/update_directory.yml | 31 +++++++++++++++++--------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/.github/workflows/update_directory.yml b/.github/workflows/update_directory.yml index 7eec51558..0530a0c26 100644 --- a/.github/workflows/update_directory.yml +++ b/.github/workflows/update_directory.yml @@ -1,18 +1,25 @@ -# This GitHub Action updates the DIRECTORY.md file (if needed) when doing a git push +# This GitHub Action updates the DIRECTORY.md file (if needed) when doing a git push or pull_request name: Update Directory +permissions: + contents: write on: push: paths: - 'src/**' - - '**.yml' - - '**.xml' - - '**.Dockerfile' pull_request: paths: - 'src/**' - - '**.yml' - - '**.xml' - - '**.Dockerfile' + workflow_dispatch: + inputs: + logLevel: + description: 'Log level' + required: true + default: 'info' + type: choice + options: + - info + - warning + - debug jobs: update_directory_md: runs-on: ubuntu-latest @@ -46,8 +53,12 @@ jobs: 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: + mid_diff = False + new_parts = new_path.split(os.sep) + for i, new_part in enumerate(new_parts): + if i + 1 > len(old_parts) or old_parts[i] != new_part or mid_diff: + if i + 1 < len(new_parts): + mid_diff = True if new_part: g_output.append(f"{md_prefix(i)} {new_part.replace('_', ' ')}") return new_path @@ -56,7 +67,7 @@ jobs: def build_directory_md(top_dir: str = ".") -> str: global g_output old_path = "" - for filepath in sorted(good_filepaths(), key=str.lower): + for filepath in sorted(good_filepaths(top_dir), key=str.lower): filepath, filename = os.path.split(filepath) if filepath != old_path: old_path = print_path(old_path, filepath)