S-Dreamer commited on
Commit
842e66c
·
verified ·
1 Parent(s): 26f5f33

Create hf-sync-dev.yml

Browse files
Files changed (1) hide show
  1. .github/workflows/hf-sync-dev.yml +56 -0
.github/workflows/hf-sync-dev.yml ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: Sync PR to Hugging Face Dev Space
2
+
3
+ on:
4
+ pull_request:
5
+ types:
6
+ - opened
7
+ - reopened
8
+ - synchronize
9
+ - ready_for_review
10
+
11
+ jobs:
12
+ sync-to-hf-dev:
13
+ if: github.event.pull_request.head.repo.full_name == github.repository
14
+ runs-on: ubuntu-latest
15
+
16
+ env:
17
+ HF_SPACE_ID: S-Dreamer/ThtratLandscapeChat-dev
18
+
19
+ steps:
20
+ - name: Checkout
21
+ uses: actions/checkout@v4
22
+
23
+ - name: Setup Python
24
+ uses: actions/setup-python@v5
25
+ with:
26
+ python-version: "3.10"
27
+
28
+ - name: Install HF Hub
29
+ run: |
30
+ pip install --upgrade pip
31
+ pip install huggingface_hub
32
+
33
+ - name: Sync to HF
34
+ env:
35
+ HF_TOKEN: ${{ secrets.HF_TOKEN }}
36
+ GITHUB_REF_NAME: ${{ github.ref_name }}
37
+ GITHUB_PR_NUMBER: ${{ github.event.pull_request.number }}
38
+ run: |
39
+ python - << 'EOF'
40
+ import os
41
+ from huggingface_hub import upload_folder, HfApi
42
+
43
+ token = os.getenv("HF_TOKEN")
44
+ repo_id = os.getenv("HF_SPACE_ID")
45
+
46
+ api = HfApi()
47
+ api.whoami(token)
48
+
49
+ upload_folder(
50
+ repo_id=repo_id,
51
+ repo_type="space",
52
+ folder_path=".",
53
+ token=token,
54
+ commit_message=f"Sync PR #{os.getenv('GITHUB_PR_NUMBER')} ({os.getenv('GITHUB_REF_NAME')})"
55
+ )
56
+ EOF