publish_model_catalog.sh
1 #!/usr/bin/env bash 2 # Publish model catalog JSON files as GitHub Release assets. 3 # 4 # Usage: 5 # bash dev/publish_model_catalog.sh [--repo OWNER/REPO] [--tag TAG] [--catalog-dir DIR] 6 # 7 # Defaults: 8 # --repo mlflow/mlflow 9 # --tag model-catalog/latest 10 # --catalog-dir mlflow/utils/model_catalog 11 # 12 # The script creates the release if it doesn't exist, then uploads 13 # every *.json file in the catalog directory as a release asset, 14 # overwriting any existing asset with the same name. 15 16 set -euo pipefail 17 18 REPO="mlflow/mlflow" 19 TAG="model-catalog/latest" 20 CATALOG_DIR="mlflow/utils/model_catalog" 21 22 while [[ $# -gt 0 ]]; do 23 case "$1" in 24 --repo) REPO="$2"; shift 2 ;; 25 --tag) TAG="$2"; shift 2 ;; 26 --catalog-dir) CATALOG_DIR="$2"; shift 2 ;; 27 *) echo "Unknown option: $1" >&2; exit 1 ;; 28 esac 29 done 30 31 echo "Repo: $REPO" 32 echo "Tag: $TAG" 33 echo "Catalog dir: $CATALOG_DIR" 34 35 # Count JSON files 36 file_count=$(find "$CATALOG_DIR" -maxdepth 1 -name '*.json' | wc -l | tr -d ' ') 37 if [[ "$file_count" -eq 0 ]]; then 38 echo "Error: no JSON files found in $CATALOG_DIR" >&2 39 exit 1 40 fi 41 echo "Files: $file_count" 42 43 # Create release if it doesn't exist 44 if ! gh release view "$TAG" --repo "$REPO" &>/dev/null; then 45 echo "Creating release $TAG ..." 46 gh release create "$TAG" \ 47 --repo "$REPO" \ 48 --title "Model Catalog" \ 49 --notes "Per-provider model catalog files. Updated weekly by CI." \ 50 --latest=false 51 fi 52 53 # Upload all JSON files as release assets. 54 # --clobber overwrites existing assets (delete + re-upload per file). 55 # There is a brief window where each asset is missing during the overwrite, 56 # but clients fall back to the bundled catalog so this is safe. 57 echo "Uploading $file_count files to release $TAG ..." 58 gh release upload "$TAG" \ 59 --repo "$REPO" \ 60 --clobber \ 61 "$CATALOG_DIR"/*.json 62 63 echo "Done. Assets available at:" 64 echo " https://github.com/$REPO/releases/tag/$(echo "$TAG" | sed 's|/|%2F|g')"