name: Update documentation after merge

on:
  push:
    branches:
      - 3.x

jobs:
  update-documentation:
    runs-on: ubuntu-22.04

    strategy:
      matrix:
        node-version: [ 20.x ]

    steps:
      - name: Check out the repo
        uses: actions/checkout@v4

      - name: Use Node.js ${{ matrix.node-version }}
        uses: actions/setup-node@v4
        with:
          node-version: ${{ matrix.node-version }}

      - name: Install Dependencies
        run: npm i --force

      - name: Configure git user
        run: |
          git config --local user.email "action@github.com"
          git config --local user.name "GitHub Action"

      - name: Update contributor faces
        run: |
          npm run update-contributor-faces
          git add README.md
          if ! git diff --cached --quiet; then
            git commit -m "DOC: Update contributor faces" --no-verify
          fi

      - name: Generate and update documentation
        run: |
          npm run def && npm run docs
          git add docs/**/*.md
          if ! git diff --cached --quiet; then
            git commit -m "DOC: Autogenerate and update documentation" --no-verify
          fi

      - name: Push to the repo
        run: git push --no-verify
