Fadhil commited on
Commit
c0d6864
Β·
unverified Β·
1 Parent(s): 476d234

Update main.yml

Browse files
Files changed (1) hide show
  1. .github/workflows/main.yml +51 -7
.github/workflows/main.yml CHANGED
@@ -1,19 +1,63 @@
1
- name: Sync to Hugging Face hub
 
2
  on:
3
  push:
4
- branches: [main]
5
- # to run this workflow manually from the Actions tab
6
- workflow_dispatch:
7
 
8
  jobs:
9
  sync-to-hub:
10
  runs-on: ubuntu-latest
 
 
 
 
 
 
 
 
 
 
 
 
11
  steps:
12
- - uses: actions/checkout@v3
 
13
  with:
14
  fetch-depth: 0
15
  lfs: true
16
- - name: Push to hub
 
 
 
 
 
 
 
17
  env:
 
 
18
  HF_TOKEN: ${{ secrets.HF_TOKEN }}
19
- run: git push https://fahmiaziz:$HF_TOKEN@huggingface.co/spaces/fahmiaziz/api-embedding master:main
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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."