Spaces:
Running
Running
| name: Sync to HuggingFace and ModelScope | |
| on: | |
| push: | |
| branches: [main] | |
| workflow_dispatch: | |
| jobs: | |
| sync: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout GitHub repo | |
| uses: actions/checkout@v4 | |
| with: | |
| lfs: false | |
| - name: Install Dependencies | |
| run: pip install huggingface_hub | |
| - name: Sync to HuggingFace Space | |
| env: | |
| HF_TOKEN: ${{ secrets.HF_TOKEN }} | |
| run: | | |
| python - << 'PYEOF' | |
| import os | |
| from huggingface_hub import HfApi | |
| api = HfApi(token=os.environ["HF_TOKEN"]) | |
| repo_id = "SAkizuki/DanbooruSearch" | |
| api.upload_folder( | |
| folder_path=".", | |
| repo_id=repo_id, | |
| repo_type="space", | |
| ignore_patterns=[ | |
| "tags_embedding/*", | |
| "origin_database/*", | |
| ".git/*", | |
| "__pycache__/*", | |
| "*.pyc", | |
| "*.parquet", | |
| "*.csv" | |
| ], | |
| commit_message="Auto-sync from GitHub Actions" | |
| ) | |
| print("HF sync done") | |
| PYEOF | |
| - name: Sync to ModelScope Studio | |
| env: | |
| MS_TOKEN: ${{ secrets.MS_TOKEN }} | |
| run: | | |
| git config --global user.name "github-actions[bot]" | |
| git config --global user.email "github-actions[bot]@users.noreply.github.com" | |
| export GIT_LFS_SKIP_SMUDGE=1 | |
| git clone https://oauth2:${MS_TOKEN}@www.modelscope.cn/studios/SAkizuki/DanbooruSearchOnline.git ms_repo | |
| # 拷贝根目录下的 .py 文件、依赖文件及 README.md | |
| cp *.py ms_repo/ 2>/dev/null || true | |
| cp requirements.txt ms_repo/ 2>/dev/null || true | |
| cp README.md ms_repo/ 2>/dev/null || true | |
| # 拷贝 core 目录下的 .py 文件 | |
| mkdir -p ms_repo/core | |
| cp core/*.py ms_repo/core/ 2>/dev/null || true | |
| cd ms_repo | |
| git add . | |
| if ! git diff --staged --quiet; then | |
| git commit -m "Auto-sync from GitHub Actions" | |
| git push origin master | |
| echo "MS sync done" | |
| else | |
| echo "No code changes to sync to MS." | |
| fi |