credit-scoring-mlops / .github /workflows /deploy-assets.yml
GitHub Actions
Auto-deploy from GitHub Actions
decf87a
name: deploy-assets
on:
workflow_dispatch:
inputs:
repo_id:
description: "HF repo id (e.g. stephmnt/assets-credit-scoring-mlops)"
required: true
default: "stephmnt/assets-credit-scoring-mlops"
repo_type:
description: "HF repo type (dataset or model)"
required: true
default: "dataset"
push:
branches: ["main"]
paths:
- "data/*_final_model.pkl"
jobs:
upload-assets:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install huggingface_hub
- name: Upload assets to Hugging Face Hub
env:
HF_TOKEN: ${{ secrets.HF_TOKEN }}
HF_REPO_ID: ${{ inputs.repo_id || 'stephmnt/assets-credit-scoring-mlops' }}
HF_REPO_TYPE: ${{ inputs.repo_type || 'dataset' }}
run: |
python - <<'PY'
import os
from pathlib import Path
from huggingface_hub import HfApi
repo_id = os.environ["HF_REPO_ID"]
repo_type = os.environ["HF_REPO_TYPE"]
token = os.environ["HF_TOKEN"]
candidates = sorted(Path("data").glob("*_final_model.pkl"))
if not candidates:
raise SystemExit("Missing model file: data/*_final_model.pkl")
if len(candidates) > 1:
names = ", ".join(path.name for path in candidates)
raise SystemExit(f"Multiple *_final_model.pkl files found: {names}")
model_path = candidates[0]
api = HfApi()
existing = api.list_repo_files(
repo_id=repo_id,
repo_type=repo_type,
token=token,
)
to_delete = [
name
for name in existing
if name.endswith("_final_model.pkl") and name != model_path.name
]
for name in to_delete:
api.delete_file(
path_in_repo=name,
repo_id=repo_id,
repo_type=repo_type,
token=token,
commit_message=f"Remove {name}",
)
for path in [model_path]:
api.upload_file(
path_or_fileobj=str(path),
path_in_repo=path.name,
repo_id=repo_id,
repo_type=repo_type,
token=token,
commit_message=f"Update {path.name}",
)
print("Assets uploaded.")
PY