Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion .github/workflows/test-all.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ jobs:
permissions:
contents: write
steps:
- name: Get the current branch name
shell: bash
run: echo "branch=${GITHUB_REF#refs/heads/}" >> $GITHUB_OUTPUT
id: branch
- uses: actions/checkout@v4
with:
fetch-depth: 0
Expand All @@ -128,7 +132,9 @@ jobs:
pip install --upgrade pip
pip install -r requirements.txt
- name: Regenerate README tables
run: python -m cli.cli update-readme --asset functions --asset modules
env:
CHANNEL: ${{ steps.branch.outputs.branch }}
run: python -m cli.cli update-readme -c $CHANNEL --asset functions --asset modules
- name: Commit & push (if changed)
env:
USERNAME: ${{ secrets.USERNAME }}
Expand Down
4 changes: 2 additions & 2 deletions cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ Example:
Regenerate the `README.md` files in each of the asset directories (functions/modules).

Usage:
`python -m cli.cli update-readme --asset TYPE`
`python -m cli.cli update-readme -c CHANNEL --asset TYPE`

Example:
`python -m cli.cli update-readme --asset functions --asset modules`
`python -m cli.cli update-readme -c master --asset functions --asset modules`
17 changes: 10 additions & 7 deletions cli/common/update_readme.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
COLUMNS = ("Name", "Description", "Kind", "Categories")

@click.command("update-readme")
@click.option("-c", "--channel", default="master", help="Name of build channel")
@click.option(
"--asset",
multiple=True,
Expand All @@ -34,7 +35,7 @@
)
@click.option("--check", is_flag=True,
help="Do not write; exit non‑zero if README(s) would change.")
def update_readme(asset: Iterable[str],
def update_readme(channel: str, asset: Iterable[str],
check: bool) -> None:
"""
Regenerate the README tables for asset types from their item.yaml files.
Expand All @@ -50,15 +51,15 @@ def update_readme(asset: Iterable[str],
root = Path(".").resolve()
asset_dir = root / t
readme = asset_dir / "README.md"
rows = _rows_for_asset_type(asset_dir)
rows = _rows_for_asset_type(channel, asset_dir)
table_md = _build_table_md(rows)
old = readme.read_text() if readme.exists() else f"# {t.title()}\n\n"
new = _replace_block(old, table_md)
if new != old:
changed_any = True
touched.append(str(readme))
else:
if _update_one(t):
if _update_one(channel, t):
changed_any = True
touched.append(str((Path(t) / "README.md").as_posix()))

Expand All @@ -78,7 +79,7 @@ def update_readme(asset: Iterable[str],
click.echo("No README changes.")


def _rows_for_asset_type(asset_dir: Path) -> List[Tuple[str, str, str, str]]:
def _rows_for_asset_type(channel: str, asset_dir: Path) -> List[Tuple[str, str, str, str]]:
"""Scan <asset>/src/*/item.yaml and return table rows."""
src = asset_dir / "src"
if not src.exists():
Expand All @@ -97,7 +98,9 @@ def _rows_for_asset_type(asset_dir: Path) -> List[Tuple[str, str, str, str]]:
cats = data.get("categories") or []
cats_str = ", ".join(c.strip() for c in cats) if isinstance(cats, list) else str(cats).strip()
# Link the name to its source directory
link = f"[{asset_name}]({(asset_dir / 'src' / asset_name).as_posix()})"
# Construct the relative path from the repo root for the asset
rel_path = asset_dir.relative_to(Path(".").resolve())
link = f"[{asset_name}](https://github.com/mlrun/functions/tree/{channel}/{rel_path}/src/{asset_name})"
rows.append((link, desc, kind, cats_str))

rows.sort(key=lambda r: r[0].lower())
Expand Down Expand Up @@ -140,13 +143,13 @@ def _replace_block(readme_text: str, new_block: str) -> str:
return readme_text[:start_close] + "\n" + new_block + "\n" + readme_text[ei:]


def _update_one(asset_type: str) -> bool:
def _update_one(channel: str, asset_type: str) -> bool:
"""Generate/replace the table in <asset_type>/README.md. Return True if changed."""
root = Path(".").resolve()
asset_dir = root / asset_type
readme = asset_dir / "README.md"

rows = _rows_for_asset_type(asset_dir)
rows = _rows_for_asset_type(channel, asset_dir)
table_md = _build_table_md(rows)
old = readme.read_text() if readme.exists() else f"# {asset_type.title()}\n\n"
new = _replace_block(old, table_md)
Expand Down