name: 自动生成README.md

# 定义触发条件，这里设置为当有新的发布创建时触发
on:
  release:
    types: [created]

jobs:
  create-readme:
    runs-on: ubuntu-latest

    if: "!contains(github.event.head_commit.message, 'AutoRelease.md')"
    
    steps:
      - name: 检出仓库
        uses: https://gitee.com/actions-mirror/checkout@v4
        with:
          fetch-depth: 0
          # 启用子模块支持
          submodules: true

      - name: 设置环境变量
        env:
          CURRENT_USER_NAME: "iorebuild"
          CURRENT_USER_EMAIL: "liyepan@linuxacme.com"
          GITEA_REPO_URL: ${{ github.server_url }}/${{ github.repository }}
          REPO_NAME: ${{ github.event.repository.name }}
        run: |
          git config user.name "$CURRENT_USER_NAME"
          git config user.email "$CURRENT_USER_EMAIL"
          echo "Name = $CURRENT_USER_NAME"
          echo "Email = $CURRENT_USER_EMAIL"

          
#       - name: 检出仓库
#         env:
#           GITEA_TOKEN: ${{ secrets.AUTOGENERATE }}
#           GITEA_REPO_URL: ${{ github.server_url }}/${{ github.repository }}
#           CLEAN_REPO_URL: ${{ github.server_url }}/${{ github.repository }}
#         run: |
#           CLEAN_REPO_URL="${CLEAN_REPO_URL#https://}"
#           git clone "https://${GITEA_TOKEN}@${CLEAN_REPO_URL}" .

#       - name: 生成版本号
#         id: version
#         run: |
#           VERSION=$(date +'%Y%m%d%H%M%S')
#           echo "version=$VERSION" >> $GITHUB_OUTPUT

#       - name: 创建 Release
#         run: |
#           gh release create v${{ steps.version.outputs.version }} --generate-notes
          
#       - name: 重新提交仓库
#         env:
#           GITEA_TOKEN: ${{ secrets.AUTOGENERATE }}
#           GITEA_REPO_URL: ${{ github.server_url }}/${{ github.repository }}
#           CLEAN_REPO_URL: ${{ github.server_url }}/${{ github.repository }}
#         run: |
#           CLEAN_REPO_URL="${CLEAN_REPO_URL#https://}"
#           git config --local user.email "liyepan@linuxacme.com"
#           git config --local user.name "iorebuild"
#           git add README.md
#           if git diff --staged --quiet; then
#             echo "No changes to commit."
#           else
#             git commit -m "AutoRelease.md"
#             git push "https://${GITEA_TOKEN}@${CLEAN_REPO_URL}"
#           fi