Skip to content

Commit

Permalink
Add script to auto-update the root readme
Browse files Browse the repository at this point in the history
  • Loading branch information
dbirks committed Jun 5, 2024
1 parent 48bf5ed commit fd57e90
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
45 changes: 45 additions & 0 deletions .github/scripts/update_root_readme.py
Original file line number Diff line number Diff line change
@@ -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"<!-- START_FEATURES -->.*<!-- END_FEATURES -->",
f"<!-- START_FEATURES -->{new_content}<!-- END_FEATURES -->",
root_readme,
flags=re.DOTALL,
)

# Write the updated root readme
with open("README.md", "w") as f:
f.write(root_readme)
3 changes: 3 additions & 0 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down

0 comments on commit fd57e90

Please sign in to comment.