Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/pip/yaspin-3.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ArzelaAscoIi authored May 7, 2024
2 parents 1d0f0f5 + 9ddb28e commit 6281d8d
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 10 deletions.
56 changes: 56 additions & 0 deletions .github/utils/add-category-id.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import os
import re
from typing import List


def read_file(file_path: str) -> List[str]:
"""Reads the content of a markdown file and returns it as a list of lines."""
with open(file_path, "r", encoding="utf-8") as file:
content = file.readlines()
return content


def modify_header(content: List[str], category_id: str) -> List[str]:
"""Modifies the YAML front matter in the markdown content to include the category."""
in_header = False
new_content = []
category_added = False
end_header_pattern = r"^---$"
start_header_found = False

for line in content:
if re.match(end_header_pattern, line) and start_header_found:
in_header = False
if not category_added:
new_content.append(f"category: {category_id}\n")
new_content.append(line)
elif in_header:
if line.startswith("category:"):
new_content.append(f"category: {category_id}\n")
category_added = True
else:
new_content.append(line)
else:
if line.strip() == "---":
in_header = True
start_header_found = True
new_content.append(line)
return new_content


def update_markdown_files(directory: str, category_id: str) -> None:
"""Updates all markdown files in a given directory by modifying their headers."""
for filename in os.listdir(directory):
if filename.endswith(".md"):
file_path = os.path.join(directory, filename)
content = read_file(file_path)
modified_content = modify_header(content, category_id)
with open(file_path, "w", encoding="utf-8") as file:
file.writelines(modified_content)


# Example usage
if __name__ == "__main__":
directory = os.getenv("MARKDOWN_FILES_DIRECTORY", "default_directory")
category_id = os.getenv("CATEGORY_ID", "default_category_id")
update_markdown_files(directory, category_id)
30 changes: 21 additions & 9 deletions .github/workflows/api-docs.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
name: API Docs

# on:
# push:
# branches:
# - <your-branch>
on:
release:
types:
- published

env:
CATEGORY_ID: ${{ secrets.CATEGORY_ID }}

permissions:
contents: write
Expand All @@ -17,12 +15,16 @@ jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup python
uses: actions/setup-python@v5
with:
python-version: 3.x

- uses: actions/cache@v4
- name: Setup cache
uses: actions/cache@v4
with:
key: ${{ github.ref }}
path: .cache
Expand All @@ -37,7 +39,6 @@ jobs:
- name: Generate API docs
run: ./.github/utils/pydoc-markdown.sh


- name: Configure git to push docs
run: |
git config --global user.name docs-bot
Expand All @@ -48,7 +49,18 @@ jobs:
- name: Install dependencies for doc deployment
run: pip install mkdocs-material mkdocstrings[python] mkdocs-mermaid2-plugin mike

- name: Publish docs
- name: Publish docs to pages
run: |
mike deploy --push --update-aliases ${{github.ref_name}} && \
mike set-default --push ${{github.ref_name}}
- name: Add Category ID to all API docs
run: python ./.github/utils/add-category-id.py
env:
MARKDOWN_FILES_DIRECTORY: docs/_pydoc/temp/
CATEGORY_ID: ${{env.CATEGORY_ID}}

- name: Run `docs` command 🚀
uses: readmeio/rdme@v8
with:
rdme: docs docs/_pydoc/temp --key=${{ secrets.README_API_KEY }} --version=1.0
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ dependencies = [
"aiohttp==3.9.5",
"aiofiles==23.2.1",
"tabulate==0.9.0",
"tqdm==4.66.2",
"tqdm==4.66.4",
"yaspin==3.0.0",
"pyrate-limiter==3.6.0",
]
Expand Down

0 comments on commit 6281d8d

Please sign in to comment.