uxoxo/eb2ab
0
1name: Check and Update Hugging Face Space2 3on:4 schedule:5 - cron: '0 0 * * *'6 workflow_dispatch:7 inputs:8 space_id:9 description: 'Hugging Face Space ID (format: username/spacename)'10 required: true11 default: 'drewThomasson/ebook2audiobook'12 type: string13 workflow_run:14 workflows: ["Docker Build"]15 types:16 - completed17 18jobs:19 check-space:20 runs-on: ubuntu-latest21 outputs:22 is_running: ${{ steps.check-status.outputs.is_running }}23 space_status: ${{ steps.check-status.outputs.space_status }}24 steps:25 - name: Check out repository26 uses: actions/checkout@v427 28 - name: Set up Python29 uses: actions/setup-python@v430 with:31 python-version: '3.10'32 33 - name: Install dependencies34 run: |35 python -m pip install --upgrade pip36 pip install requests37 38 - name: Check Space Status39 id: check-status40 run: |41 python - <<'EOF'42 import requests43 import os44 45 def check_space_status(space_id):46 url = f"https://huggingface.co/api/spaces/{space_id}/runtime"47 response = requests.get(url)48 if response.status_code == 200:49 data = response.json()50 status = data.get("stage", "UNKNOWN")51 print(f"Space status: {status}")52 return status53 else:54 print(f"Error: {response.status_code}")55 return "ERROR"56 57 space_id = "${{ github.event.inputs.space_id }}"58 status = check_space_status(space_id)59 60 # Set output variables61 is_running = "true" if status == "RUNNING" else "false"62 print(f"::set-output name=is_running::{is_running}")63 print(f"::set-output name=space_status::{status}")64 EOF65 66 - name: Report Status67 run: |68 echo "Space: ${{ github.event.inputs.space_id }}"69 echo "Status: ${{ steps.check-status.outputs.space_status }}"70 echo "Is Running: ${{ steps.check-status.outputs.is_running }}"71 72 update-huggingface:73 runs-on: ubuntu-latest74 needs: check-space75 if: ${{ needs.check-space.outputs.space_status != 'RUNNING' }}76 steps:77 - name: Checkout self repository for VERSION.txt78 uses: actions/checkout@v479 with:80 path: source81 82 - name: Set up Git83 run: |84 git config --global user.name "GitHub Action"85 git config --global user.email "action@github.com"86 87 - name: Install Git LFS88 run: |89 curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.deb.sh | sudo bash90 sudo apt-get install git-lfs91 git lfs install92 93 - name: Configure Hugging Face credentials94 run: |95 echo "machine hf-prod.huggingface.co login api password ${{ secrets.HUGGINGFACE_TOKEN }}" > ~/.netrc96 echo "machine huggingface.co login api password ${{ secrets.HUGGINGFACE_TOKEN }}" >> ~/.netrc97 98 - name: Clone Hugging Face space repository99 run: |100 git clone https://huggingface.co/spaces/drewThomasson/ebook2audiobook101 102 - name: Update README and updates.txt in Hugging Face space103 run: |104 # Read version from the source repository's VERSION.txt105 VERSION=$(cat source/VERSION.txt | tr -d ' \t\n')106 echo "Updating README with version $VERSION"107 cd ebook2audiobook108 # Update updates.txt (append or create if it doesn't exist)109 if [ ! -f updates.txt ]; then110 echo "update" > updates.txt111 else112 echo "update" >> updates.txt113 fi114 # Update the version in the README file using sed115 sed -i "s/^title: Ebook2audiobook v[0-9.]\+/title: Ebook2audiobook v$VERSION/" README.md116 git add updates.txt README.md117 git commit -m "Update version in README to $VERSION and add update entry to updates.txt"118 git push119 