auto-sync #48
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: auto-sync | |
| on: | |
| push: | |
| branches: | |
| - main | |
| schedule: | |
| - cron: "0 19 * * *" # 每天 UTC 时间 19:00 (北京时间 3:00~4:15) 触发一次 | |
| workflow_dispatch: | |
| # 允许手动触发 | |
| permissions: | |
| contents: write | |
| jobs: | |
| job-on-push: | |
| if: github.event_name == 'push' || github.event_name == 'workflow_dispatch' | |
| runs-on: ubuntu-latest | |
| steps: | |
| # Step 1: 检出当前仓库代码 | |
| - name: Checkout repository | |
| uses: actions/checkout@v5 | |
| # Step 2: 同步至 HuggingFace | |
| - name: Sync Files to HuggingFace | |
| env: | |
| HF_TOKEN: ${{ secrets.HF_TOKEN }} | |
| GIT_NAME: ${{ secrets.GIT_NAME }} | |
| GIT_EMAIL: ${{ secrets.GIT_EMAIL }} | |
| run: | | |
| mv -f ./.github/restart.py ../ | |
| git clone https://oauth2:$HF_TOKEN@huggingface.co/spaces/ccmusic-database/bel_canto ../hf_repo | |
| rm -rf ./.git* ./LICENSE | |
| cp -rf ../hf_repo/README.md ../hf_repo/requirements.txt ../hf_repo/.git ./ | |
| if [ -n "$(git status --porcelain)" ]; then | |
| echo "Files are different, committing changes..." | |
| git config --global user.name "$GIT_NAME" | |
| git config --global user.email "$GIT_EMAIL" | |
| git add . | |
| git commit -m "Auto sync at $(date '+%Y-%m-%d %H:%M:%S')" | |
| git push | |
| else | |
| echo "Files are the same, no changes." | |
| fi | |
| # Step 3: 同步至 ModelScope | |
| - name: Sync Files to ModelScope | |
| env: | |
| MS_TOKEN: ${{ secrets.MS_TOKEN }} | |
| GIT_NAME: ${{ secrets.GIT_NAME }} | |
| GIT_EMAIL: ${{ secrets.GIT_EMAIL }} | |
| run: | | |
| git clone https://oauth2:$MS_TOKEN@www.modelscope.cn/studios/ccmusic-database/bel_canto.git ../ms_repo | |
| rm -rf ./.git ./README.md | |
| cp -rf ../ms_repo/requirements.txt ../ms_repo/.git ./ | |
| if [ -n "$(git status --porcelain)" ]; then | |
| echo "Files are different, committing changes..." | |
| git config --global user.name "$GIT_NAME" | |
| git config --global user.email "$GIT_EMAIL" | |
| git add . | |
| git commit -m "Auto sync at $(date '+%Y-%m-%d %H:%M:%S')" | |
| git push | |
| pip install modelscope | |
| python ../restart.py --token $MS_TOKEN | |
| else | |
| echo "Files are the same, no changes." | |
| fi | |
| job-on-schedule: | |
| if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Check HuggingFace SDK Update | |
| env: | |
| HF_TOKEN: ${{ secrets.HF_TOKEN }} | |
| GIT_NAME: ${{ secrets.GIT_NAME }} | |
| GIT_EMAIL: ${{ secrets.GIT_EMAIL }} | |
| MD_URL: ${{ vars.MD_URL }} | |
| run: | | |
| GIT_LFS_SKIP_SMUDGE=1 git clone https://oauth2:$HF_TOKEN@huggingface.co/spaces/ccmusic-database/bel_canto ./hf_repo | |
| cd ./hf_repo | |
| LATEST_VER=$(curl -s "$MD_URL" | tr -d '\n' | grep -oP '(?<=<code>).*?(?=</code>)') | |
| if [ -n "$LATEST_VER" ]; then | |
| sed -i "s/^\(sdk_version: \)[0-9.]*/\1$LATEST_VER/" README.md | |
| if [ -n "$(git status --porcelain)" ]; then | |
| echo "Files are different, committing changes..." | |
| git config --global user.name "$GIT_NAME" | |
| git config --global user.email "$GIT_EMAIL" | |
| git add . | |
| git commit -m "Update SDK at $(date '+%Y-%m-%d %H:%M:%S')" | |
| git push | |
| else | |
| echo "Files are the same, no changes." | |
| fi | |
| else | |
| echo "Failed to obtain latest sdk version." | |
| fi |