From fd57e905b6b08e82a96fb14926dd899c3b0b3551 Mon Sep 17 00:00:00 2001 From: David Birks Date: Wed, 5 Jun 2024 15:49:07 -0400 Subject: [PATCH] Add script to auto-update the root readme --- .github/scripts/update_root_readme.py | 45 +++++++++++++++++++++++++++ .github/workflows/publish.yaml | 3 ++ 2 files changed, 48 insertions(+) create mode 100755 .github/scripts/update_root_readme.py diff --git a/.github/scripts/update_root_readme.py b/.github/scripts/update_root_readme.py new file mode 100755 index 0000000..578e086 --- /dev/null +++ b/.github/scripts/update_root_readme.py @@ -0,0 +1,45 @@ +#!/usr/bin/env python + +# Takes the generated readme files for each feature, adjusts the markdown headings, and updates the root readme with the new content. + +import os +import re + +# Get the list of subdirs in src +feature_names = [d for d in os.listdir("src")] + +print(f"Found {len(feature_names)} features: {', '.join(feature_names)}") + +# Read the root readme +with open("README.md", "r") as f: + root_readme = f.read() + +new_content = "" + +# Update the root readme with the new content +for feature_name in feature_names: + # Read the feature readme + with open(f"src/{feature_name}/README.md", "r") as f: + feature_readme = f.read() + + # Adjust the markdown headings + feature_readme = re.sub(r"^#", "###", feature_readme, flags=re.MULTILINE) + + # Remove everything after the --- to the end of the file + feature_readme = re.sub(r"\n---.*", "", feature_readme, flags=re.DOTALL) + + new_content += f"\n{feature_readme}" + +print(f"New readme content to add: {new_content}") + +# Replace the old content with the new content +root_readme = re.sub( + r".*", + f"{new_content}", + root_readme, + flags=re.DOTALL, +) + +# Write the updated root readme +with open("README.md", "w") as f: + f.write(root_readme) diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index 3b72d32..2ca9772 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -23,6 +23,9 @@ jobs: base-path-to-features: "./src" generate-docs: "true" + - name: Update the root readme + run: .github/scripts/update_root_readme.sh + - name: Commit changes to the docs env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}