Spaces:
Running
Running
Fadhil
commited on
Update main.yml
Browse files- .github/workflows/main.yml +51 -7
.github/workflows/main.yml
CHANGED
|
@@ -1,19 +1,63 @@
|
|
| 1 |
-
name: Sync to Hugging Face
|
|
|
|
| 2 |
on:
|
| 3 |
push:
|
| 4 |
-
branches: [main]
|
| 5 |
-
#
|
| 6 |
-
workflow_dispatch:
|
| 7 |
|
| 8 |
jobs:
|
| 9 |
sync-to-hub:
|
| 10 |
runs-on: ubuntu-latest
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
steps:
|
| 12 |
-
-
|
|
|
|
| 13 |
with:
|
| 14 |
fetch-depth: 0
|
| 15 |
lfs: true
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
env:
|
|
|
|
|
|
|
| 18 |
HF_TOKEN: ${{ secrets.HF_TOKEN }}
|
| 19 |
-
run:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
name: Sync to Hugging Face Space (force-by-default)
|
| 2 |
+
|
| 3 |
on:
|
| 4 |
push:
|
| 5 |
+
branches: ["main", "master"]
|
| 6 |
+
# Optional manual trigger
|
| 7 |
+
workflow_dispatch: {}
|
| 8 |
|
| 9 |
jobs:
|
| 10 |
sync-to-hub:
|
| 11 |
runs-on: ubuntu-latest
|
| 12 |
+
concurrency:
|
| 13 |
+
group: hf-space-sync-canonical
|
| 14 |
+
cancel-in-progress: false
|
| 15 |
+
|
| 16 |
+
# Set these as Repository Variables:
|
| 17 |
+
# Settings β Secrets and variables β Actions β Variables
|
| 18 |
+
# HF_USERNAME = your HF username (e.g. ruslanmv)
|
| 19 |
+
# SPACE_NAME = your Space name (e.g. matrix-ai)
|
| 20 |
+
env:
|
| 21 |
+
HF_USERNAME: ${{ vars.HF_USERNAME }}
|
| 22 |
+
SPACE_NAME: ${{ vars.SPACE_NAME }}
|
| 23 |
+
|
| 24 |
steps:
|
| 25 |
+
- name: Checkout (with LFS)
|
| 26 |
+
uses: actions/checkout@v4
|
| 27 |
with:
|
| 28 |
fetch-depth: 0
|
| 29 |
lfs: true
|
| 30 |
+
|
| 31 |
+
- name: Prepare Git + LFS
|
| 32 |
+
run: |
|
| 33 |
+
git config user.name "github-actions[bot]"
|
| 34 |
+
git config user.email "github-actions[bot]@users.noreply.github.com"
|
| 35 |
+
git lfs install --local
|
| 36 |
+
|
| 37 |
+
- name: Force push GitHub HEAD β Space main (GitHub is canonical)
|
| 38 |
env:
|
| 39 |
+
# Add this as a Repository Secret:
|
| 40 |
+
# Settings β Secrets and variables β Actions β New repository secret β HF_TOKEN
|
| 41 |
HF_TOKEN: ${{ secrets.HF_TOKEN }}
|
| 42 |
+
run: |
|
| 43 |
+
set -e
|
| 44 |
+
if [ -z "$HF_USERNAME" ] || [ -z "$SPACE_NAME" ]; then
|
| 45 |
+
echo "β Missing HF_USERNAME or SPACE_NAME repo Variables."
|
| 46 |
+
echo " Add them under: Settings β Secrets and variables β Actions β Variables."
|
| 47 |
+
exit 1
|
| 48 |
+
fi
|
| 49 |
+
if [ -z "$HF_TOKEN" ]; then
|
| 50 |
+
echo "β Missing HF_TOKEN secret (write token for Spaces)."
|
| 51 |
+
echo " Add it under: Settings β Secrets and variables β Actions β New repository secret."
|
| 52 |
+
exit 1
|
| 53 |
+
fi
|
| 54 |
+
|
| 55 |
+
REMOTE_URL="https://${HF_USERNAME}:${HF_TOKEN}@huggingface.co/spaces/${HF_USERNAME}/${SPACE_NAME}"
|
| 56 |
+
|
| 57 |
+
echo "π Forcing GitHub HEAD β Space main..."
|
| 58 |
+
git push --force "$REMOTE_URL" HEAD:main
|
| 59 |
+
|
| 60 |
+
# Best-effort push for LFS objects (if any)
|
| 61 |
+
git lfs push --all "$REMOTE_URL" main || true
|
| 62 |
+
|
| 63 |
+
echo "β
Sync complete: Space 'main' now matches GitHub HEAD."
|