name: 自动生成 label

# main 分支推送
on:
  push:
    branches:
      - main

jobs:
  Generate-label:
    runs-on: node-21
    steps:
      - name: 获取仓库
        uses: http://shenjack.top:5100/gitea-server/checkout@v4

      - name: pip
        run: |
          cd ..
          git clone http://shenjack.top:5100/gitea-server/python-packs.git
          cd python-packs
          python3 -m ensurepip
          cd ../ARS-docs

      - name: 安装依赖
        run: |
          python3 -m pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
          python3 -m pip install -U pip
          python3 -m pip install -U -r scripts/requirement.txt
          ls . -la
          ls scripts

      - name: 生成 label
        run: |
          python3 scripts/parse-label.py
          cp build/tags.toml modules/tags.toml
      
      - name: 检查是否有改动
        run: |
          git config user.name gitea-actions
          git config user.email gitea-action@shenjack.top
          if [ -n "$(git status --porcelain)" ]; then
            git add .
            git commit -m "gen by python script"
            # 创建并切换到deploy分支
            git checkout -b deploy
            # 将更改添加到deploy分支的最新提交
            git commit --amend --no-edit
            # 推送到deploy分支
            git push origin HEAD --force
          else
            echo "工作区没有改动"
          fi

# https://gitea.com/actions/gitea-release-action
