name: Format README.md

permissions:
  contents: read
  pull-requests: write

on:
  push:
    branches:
      - main

jobs:
  sync-assets:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - name: Run auto-doc
        uses: tj-actions/auto-doc@v3
        with:
          use_code_blocks: true
          use_major_version: true

      - name: Run remark
        uses: tj-actions/remark@v3

      - name: Verify Changed files
        uses: tj-actions/verify-changed-files@v17
        id: verify_changed_files
        with:
          files: |
            README.md

      - name: README.md changed
        if: steps.verify_changed_files.outputs.files_changed == 'true'
        run: |
          echo "README.md has uncommitted changes"
          exit 1

      - name: Create Pull Request
        if: failure()
        uses: peter-evans/create-pull-request@v6
        with:
          base: "main"
          labels: "merge when passing"
          title: "Updated README.md"
          branch: "chore/update-readme"
          commit-message: "Updated README.md"
          body: "Updated README.md"
          token: ${{ secrets.PAT_TOKEN }}
