name: Update README

on:
  pull_request:
    branches: [main]
    paths:
      - 'src/datamodel_code_generator/**'
      - 'README.md'
      - 'docs/index.md'
      - 'docs/presets.md'
      - 'scripts/build_preset_docs.py'
      - 'tests/data/jsonschema/tutorial_pet.json'

permissions:
  contents: read

jobs:
  update-readme:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
        with:
          fetch-depth: 0
          ref: ${{ github.event.pull_request.head.sha }}
          repository: ${{ github.event.pull_request.head.repo.full_name }}
          persist-credentials: false
      - name: Install the latest version of uv
        uses: astral-sh/setup-uv@fac544c07dec837d0ccb6301d7b5580bf5edae39 # v8.2.0
      - name: Install tox
        run: uv tool install --python-preference only-managed --python 3.13 tox --with tox-uv
      - name: Setup environment
        run: tox run -vv --notest --skip-missing-interpreters false -e readme
        env:
          UV_PYTHON_PREFERENCE: "only-managed"
      - name: Setup preset docs environment
        run: tox run -vv --notest --skip-missing-interpreters false -e preset-docs
        env:
          UV_PYTHON_PREFERENCE: "only-managed"
      - name: Update README
        run: .tox/readme/bin/python scripts/update_command_help_on_markdown.py
      - name: Check preset docs
        run: .tox/preset-docs/bin/python scripts/build_preset_docs.py --check
