From 5894292bf004de09da889f9243ff0bc676d05ab0 Mon Sep 17 00:00:00 2001 From: CarlGao4 Date: Sat, 17 Aug 2024 10:45:42 +0800 Subject: [PATCH] Fix toc script --- .github/workflows/generate-toc.yml | 4 ++++ .github/workflows/update-gh-page.yml | 5 +---- gh-actions-generate-toc.py | 7 +++++-- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/.github/workflows/generate-toc.yml b/.github/workflows/generate-toc.yml index 13a48d4..15f9a73 100644 --- a/.github/workflows/generate-toc.yml +++ b/.github/workflows/generate-toc.yml @@ -49,3 +49,7 @@ jobs: if: ${{ steps.generate-toc.outputs.continue_commit != 'false' }} with: commit-message: ${{ steps.generate-toc.outputs.commit_message }} + + trigger-gh-pages-update: + needs: generate-instrument-toc + uses: ./.github/workflows/update-gh-page.yml \ No newline at end of file diff --git a/.github/workflows/update-gh-page.yml b/.github/workflows/update-gh-page.yml index 74e1573..9f843a4 100644 --- a/.github/workflows/update-gh-page.yml +++ b/.github/workflows/update-gh-page.yml @@ -7,10 +7,7 @@ on: - "*.md" - "*.py" workflow_dispatch: - workflow_run: - workflows: ["Generate Instrument Table of Contents"] - types: - - completed + workflow_call: concurrency: group: ${{ github.workflow }} diff --git a/gh-actions-generate-toc.py b/gh-actions-generate-toc.py index bc73129..14eb4ec 100644 --- a/gh-actions-generate-toc.py +++ b/gh-actions-generate-toc.py @@ -84,6 +84,8 @@ name = name.split(".", 1)[0] if catagory not in instruments: instruments[catagory] = {} + if catagory not in download_size: + download_size[catagory] = {} if name not in instruments[catagory]: instruments[catagory][name] = {} if name not in download_size[catagory]: @@ -142,8 +144,8 @@ def human_readable_size(size): with open("instruments.md", mode="wt", encoding="utf-8") as f: f.write(markdown) # Find out what instrument changed to set commit message - old_markdown_insts = dict((i[1], i[0]) for i in re.findall(r"(- \[(.*)\].*\r?\n( - .*\r?\n?)*)", old_markdown)) - new_markdown_insts = dict((i[1], i[0]) for i in re.findall(r"(- \[(.*)\].*\r?\n( - .*\r?\n?)*)", markdown)) + old_markdown_insts = dict((i[1], i[2]) for i in re.findall(r"(- \[?([^\[\]`\r\n]+)\]?.*\r?\n( - .*\r?\n?)*)", old_markdown)) + new_markdown_insts = dict((i[1], i[2]) for i in re.findall(r"(- \[?([^\[\]`\r\n]+)\]?.*\r?\n( - .*\r?\n?)*)", markdown)) added = set(new_markdown_insts.keys()) - set(old_markdown_insts.keys()) removed = set(old_markdown_insts.keys()) - set(new_markdown_insts.keys()) modified = {} @@ -168,6 +170,7 @@ def human_readable_size(size): message += " Removed: " + modified[i][0][j] + "\n" elif modified[i][0][j] != modified[i][1][j]: message += f" Renamed: {modified[i][0][j]} -> {modified[i][1][j]}\n" + message = message.replace("\_", "_").replace("\\\\", "\\") print("-" * 80) print("Commit message:") print(message)