diff --git a/.github/workflows/test-all.yaml b/.github/workflows/test-all.yaml index 162804863..d8eb6c6ed 100644 --- a/.github/workflows/test-all.yaml +++ b/.github/workflows/test-all.yaml @@ -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 @@ -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 }} diff --git a/cli/README.md b/cli/README.md index 4a3cd3bfc..31443b132 100644 --- a/cli/README.md +++ b/cli/README.md @@ -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` \ No newline at end of file + `python -m cli.cli update-readme -c master --asset functions --asset modules` \ No newline at end of file diff --git a/cli/common/update_readme.py b/cli/common/update_readme.py index 6bcab8d33..89b6aa094 100644 --- a/cli/common/update_readme.py +++ b/cli/common/update_readme.py @@ -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, @@ -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. @@ -50,7 +51,7 @@ 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) @@ -58,7 +59,7 @@ def update_readme(asset: Iterable[str], 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())) @@ -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 /src/*/item.yaml and return table rows.""" src = asset_dir / "src" if not src.exists(): @@ -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()) @@ -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 /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)