name: Update xiaosa
on:
  workflow_dispatch:
  schedule:
    - cron: "30 3 * * *"
  push:
    branches:
      - master
    paths-ignore:
      - "**/README.md"
jobs:
  build:
    runs-on: ubuntu-latest      
    steps:
      - name: Checkout the branch
        uses: actions/checkout@v6

      - name: wget the xiaosa 
        run: |
           pwd
           cd xiaosa/
           wget https://github.com/PizazzGY/NewTVBox/raw/main/%E5%8D%95%E7%BA%BF%E8%B7%AF.zip -O xiaosa.zip
           unzip xiaosa.zip
           \cp -pdr TVBoxOSC/tvbox/* ./
           rm -rf xiaosa.zip TVBoxOSC
           cd ../
        shell: bash
      - name: tools
        run: |
          pwd 
          cd tools/
          pip install demjson3 --break-system-packages
          python fty.py
          python hebing.py dianshi.json tvbox_cleaned.json
          python hebing.py jsm.json tvbox_cleaned.json
          python xiao.py ../xiaosa/api.json dianshi_merged.json
          python xiao.py ../xiaosa/api.json jsm_merged.json
          \cp -pdr dianshi_merged_with_app_sites.json ../dianshi.json
          \cp -pdr jsm_merged_with_app_sites.json ../jsm.json
          \cp -pdr fan.txt ../jar/fan.txt
          rm -rf dianshi_merged_with_app_sites.json jsm_merged_with_app_sites.json dianshi_merged.json jsm_merged.json tvbox_cleaned.json fan.txt
          cd ../
        shell: bash
      - name: Git push assets to "release" branch
        run: |
          git config --local user.name "github-actions[bot]"
          git config --local user.email "87984115+github-actions[bot]@users.noreply.github.com"
          git add .
          if ! git diff-index --quiet HEAD --; then
            git commit -m "更新源 $(date +%Y%m%d%H%M)"
            git push -f origin master
          else
            echo "没有文件更新，不执行 git push"
          fi
