Sync to Hugging Face hub workflow (xiaosu-zhu/McQuic)
The Sync to Hugging Face hub workflow from xiaosu-zhu/McQuic, explained and optimized by Latchkey.
A
CI health: A - excellent
Point runs-on at Latchkey and get job timeouts, self-healing for flaky steps, and up to 58% lower cost, applied automatically.
What it does
This is the Sync to Hugging Face hub workflow from the xiaosu-zhu/McQuic repository, a real project running GitHub Actions. It is shown here with attribution under its Apache-2.0 license.
Below, Latchkey shows a faster, safer version produced by its optimization engine.
The workflow
workflow (.yml)
name: Sync to Hugging Face hub
on:
workflow_run:
workflows: [Bump version]
types:
- completed
jobs:
sync-to-hub:
runs-on: ubuntu-latest
env:
HF_TOKEN: ${{ secrets.HF_TOKEN }}
steps:
- name: Delay 300 seconds (wait for pypi package online)
run: sleep 300s
- uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Clone HF
run: |
git clone https://xiaosu-zhu:$HF_TOKEN@huggingface.co/spaces/xiaosu-zhu/McQuic.git hfSpace
cp mcquic/service/stCompressService.py hfSpace/
python ci/pre_commit/update_hf_space_require.py mcquic/__init__.py hfSpace/requirements.txt
cd hfSpace
git add .
git config --global user.email "xiaosu.zhu@outlook.com"
git config --global user.name "Xiaosu Zhu"
git commit -m "Auto deploy"
git push
The same workflow, on Latchkey
Removes redundant runs and caps runaway jobs. Added and changed lines are highlighted.
name: Sync to Hugging Face hub on: workflow_run: workflows: [Bump version] types: - completed jobs: sync-to-hub: timeout-minutes: 30 runs-on: latchkey-small env: HF_TOKEN: ${{ secrets.HF_TOKEN }} steps: - name: Delay 300 seconds (wait for pypi package online) run: sleep 300s - uses: actions/checkout@v3 with: fetch-depth: 0 - name: Clone HF run: | git clone https://xiaosu-zhu:$HF_TOKEN@huggingface.co/spaces/xiaosu-zhu/McQuic.git hfSpace cp mcquic/service/stCompressService.py hfSpace/ python ci/pre_commit/update_hf_space_require.py mcquic/__init__.py hfSpace/requirements.txt cd hfSpace git add . git config --global user.email "xiaosu.zhu@outlook.com" git config --global user.name "Xiaosu Zhu" git commit -m "Auto deploy" git push
What changed
- Run on Latchkey managed runners with one line (
runs-on), which apply the fixes below automatically and self-heal transient failures. This example useslatchkey-small; pick the runner size that fits the job. - Add a job timeout so a hung step cannot burn hours of runner time.
This workflow runs 1 job per trigger. On Latchkey the same minutes cost up to 58% less than GitHub-hosted, with zero queue time.