github-actions[bot] commited on
Commit
1529cd0
·
1 Parent(s): bde5fc0

ci: remove CI config before sync

Browse files
.cnb.yml DELETED
@@ -1,66 +0,0 @@
1
-
2
- $:
3
- vscode:
4
- - runner:
5
- cpus: 4
6
- tags: cnb:arch:amd64
7
- docker:
8
- image: cnbcool/default-dev-env:latest
9
- imports:
10
- - https://cnb.cool/maikebuke/Tools/Huggingface/AccessToken/-/blob/main/key.yml
11
- env:
12
- HF_SPACE_URL: "https://huggingface.co/spaces/ServiceX/PDF"
13
- services:
14
- - vscode
15
- - docker
16
- stages:
17
- - name: vscode go
18
- type: vscode:go
19
-
20
- main:
21
- push:
22
- - runner:
23
- cpus: 1
24
- docker:
25
- image: cnbcool/default-dev-env:latest
26
- imports:
27
- - https://cnb.cool/maikebuke/Tools/Huggingface/AccessToken/-/blob/main/key.yml
28
- env:
29
- HF_SPACE_URL: "https://huggingface.co/spaces/ServiceX/PDF"
30
- HF_SPACE_SECRET_KEY: "BASIC_AUTH_USERS"
31
- BASIC_AUTH_FILE: "basic_auth_users.txt"
32
- HF_EXCLUDE_FILES: ".cnb.yml basic_auth_users.txt src/scripts"
33
- stages:
34
- - name: Update HF Space Secret
35
- script: |
36
- set -euo pipefail
37
-
38
- HF_TOKEN="${HF_TOKEN_FULL}" uvx --from huggingface_hub hf auth whoami >/dev/null
39
- HF_TOKEN_FULL="${HF_TOKEN_FULL}" \
40
- HF_SPACE_URL="${HF_SPACE_URL}" \
41
- HF_SPACE_SECRET_KEY="${HF_SPACE_SECRET_KEY}" \
42
- BASIC_AUTH_FILE="${BASIC_AUTH_FILE}" \
43
- uvx --from huggingface_hub python src/scripts/update_space_secret.py
44
-
45
- - name: Push Git To Huggingface Spaces
46
- script: |
47
- set -euo pipefail
48
-
49
- # 从 HF_SPACE_URL 提取 owner/repo 路径用于构造带认证的 git remote
50
- HF_REPO_PATH=$(echo "$HF_SPACE_URL" | sed 's|https://huggingface.co/spaces/||')
51
- HF_REMOTE="https://user:${HF_TOKEN_FULL}@huggingface.co/spaces/${HF_REPO_PATH}"
52
-
53
- # 删除不应同步到 Spaces 的文件(空格分隔)
54
- for exclude in ${HF_EXCLUDE_FILES}; do
55
- rm -rf "$exclude"
56
- done
57
-
58
- git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
59
- git config user.name "github-actions[bot]"
60
-
61
- # 将删除操作提交(基于当前 HEAD)
62
- git add -A
63
- git diff --cached --quiet || git commit -m "ci: remove CI config before sync"
64
-
65
- # 强制推送到 Huggingface Space
66
- git push "$HF_REMOTE" HEAD:main --force
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
basic_auth_users.txt DELETED
@@ -1,3 +0,0 @@
1
- # 每行一个账号,格式:username:password
2
- alice:change_me_please
3
- bob:change_me_too
 
 
 
 
src/scripts/update_space_secret.py DELETED
@@ -1,58 +0,0 @@
1
- #!/usr/bin/env python3
2
- """Update Hugging Face Space secret from a local credential file."""
3
-
4
- from __future__ import annotations
5
-
6
- import os
7
- from pathlib import Path
8
- from urllib.parse import urlparse
9
-
10
- from huggingface_hub import HfApi
11
-
12
-
13
- def _require_env(name: str) -> str:
14
- value = os.environ.get(name, "").strip()
15
- if not value:
16
- raise SystemExit(f"[ERROR] Missing required environment variable: {name}")
17
- return value
18
-
19
-
20
- def _parse_space_repo_id(space_url: str) -> str:
21
- prefix = "https://huggingface.co/spaces/"
22
- if space_url.startswith(prefix):
23
- repo_id = space_url[len(prefix) :].strip("/")
24
- else:
25
- parsed = urlparse(space_url)
26
- parts = [part for part in parsed.path.split("/") if part]
27
- # 期望路径格式: /spaces/{owner}/{repo}
28
- if len(parts) >= 3 and parts[0] == "spaces":
29
- repo_id = f"{parts[1]}/{parts[2]}"
30
- else:
31
- raise SystemExit(f"[ERROR] Invalid HF_SPACE_URL: {space_url}")
32
-
33
- if "/" not in repo_id:
34
- raise SystemExit(f"[ERROR] Invalid Space repo id: {repo_id}")
35
- return repo_id
36
-
37
-
38
- def main() -> None:
39
- token = _require_env("HF_TOKEN_FULL")
40
- space_url = _require_env("HF_SPACE_URL")
41
- secret_key = os.environ.get("HF_SPACE_SECRET_KEY", "BASIC_AUTH_USERS").strip()
42
- auth_file = os.environ.get("BASIC_AUTH_FILE", "basic_auth_users.txt").strip()
43
-
44
- auth_path = Path(auth_file)
45
- if not auth_path.is_file():
46
- raise SystemExit(f"[ERROR] Auth file not found: {auth_file}")
47
-
48
- secret_value = auth_path.read_text(encoding="utf-8").strip()
49
- if not secret_value:
50
- raise SystemExit(f"[ERROR] Auth file is empty: {auth_file}")
51
-
52
- repo_id = _parse_space_repo_id(space_url)
53
- HfApi(token=token).add_space_secret(repo_id=repo_id, key=secret_key, value=secret_value)
54
- print(f"[INFO] Updated Space secret '{secret_key}' for '{repo_id}'.")
55
-
56
-
57
- if __name__ == "__main__":
58
- main()