name: Update docs

permissions: {}

on:
  push:
    branches:
      - main

concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

jobs:
  update-docs:
    timeout-minutes: 10
    runs-on: ubuntu-latest
    permissions:
      contents: write
      pull-requests: write
    steps:
      - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
        with:
          persist-credentials: false
      - uses: ./.github/actions/setup

      - name: Update docs
        id: update-docs
        run: |
          go run ./docs/update.go
          git add .
          if git diff --staged --exit-code --quiet; then
            echo "No changes."
          else
            echo "Changes detected."
            echo "diff=true" >> "${GITHUB_OUTPUT}"
          fi
      - uses: peter-evans/create-pull-request@271a8d0340265f705b14b6d32b9829c1cb33d45e # v7.0.8
        if: ${{ steps.update-docs.outputs.diff == 'true' }}
        with:
          token: ${{ github.token }}
          title: "chore: Update docs"
          body: ${{ github.sha }}
          branch: docs/update
