Skip to content

Check and Update Hugging Face Space #188

Check and Update Hugging Face Space

Check and Update Hugging Face Space #188

name: Check and Update Hugging Face Space
on:
schedule:
- cron: '0 0 * * *'
workflow_dispatch:
inputs:
space_id:
description: 'Hugging Face Space ID (format: username/spacename)'
required: true
default: 'drewThomasson/ebook2audiobook'
type: string
workflow_run:
workflows: ["Docker Build"]
types:
- completed
jobs:
check-space:
runs-on: ubuntu-latest
outputs:
is_running: ${{ steps.check-status.outputs.is_running }}
space_status: ${{ steps.check-status.outputs.space_status }}
steps:
- name: Check out repository
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.10'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install requests
- name: Check Space Status
id: check-status
run: |
python - <<'EOF'
import requests
import os
def check_space_status(space_id):
url = f"https://huggingface.co/api/spaces/{space_id}/runtime"
response = requests.get(url)
if response.status_code == 200:
data = response.json()
status = data.get("stage", "UNKNOWN")
print(f"Space status: {status}")
return status
else:
print(f"Error: {response.status_code}")
return "ERROR"
space_id = "${{ github.event.inputs.space_id }}"
status = check_space_status(space_id)
# Set output variables
is_running = "true" if status == "RUNNING" else "false"
print(f"::set-output name=is_running::{is_running}")
print(f"::set-output name=space_status::{status}")
EOF
- name: Report Status
run: |
echo "Space: ${{ github.event.inputs.space_id }}"
echo "Status: ${{ steps.check-status.outputs.space_status }}"
echo "Is Running: ${{ steps.check-status.outputs.is_running }}"
update-huggingface:
runs-on: ubuntu-latest
needs: check-space
if: ${{ needs.check-space.outputs.space_status != 'RUNNING' }}
steps:
- name: Checkout self repository for VERSION.txt
uses: actions/checkout@v4
with:
path: source
- name: Set up Git
run: |
git config --global user.name "GitHub Action"
git config --global user.email "[email protected]"
- name: Install Git LFS
run: |
curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.deb.sh | sudo bash
sudo apt-get install git-lfs
git lfs install
- name: Configure Hugging Face credentials
run: |
echo "machine hf-prod.huggingface.co login api password ${{ secrets.HUGGINGFACE_TOKEN }}" > ~/.netrc
echo "machine huggingface.co login api password ${{ secrets.HUGGINGFACE_TOKEN }}" >> ~/.netrc
- name: Clone Hugging Face space repository
run: |
git clone https://huggingface.co/spaces/drewThomasson/ebook2audiobook
- name: Update README and updates.txt in Hugging Face space
run: |
# Read version from the source repository's VERSION.txt
VERSION=$(cat source/VERSION.txt | tr -d ' \t\n')
echo "Updating README with version $VERSION"
cd ebook2audiobook
# Update updates.txt (append or create if it doesn't exist)
if [ ! -f updates.txt ]; then
echo "update" > updates.txt
else
echo "update" >> updates.txt
fi
# Update the version in the README file using sed
sed -i "s/^title: Ebook2audiobook v[0-9.]\+/title: Ebook2audiobook v$VERSION/" README.md
git add updates.txt README.md
git commit -m "Update version in README to $VERSION and add update entry to updates.txt"
git push