name: Build PHP documentation

permissions:
  contents: read

on:
    repository_dispatch:
        types: run-build-docs
    workflow_dispatch:

jobs:
    run-sudo-bot-build-docs:
        environment:
            name: "sudo-bot"
            url: https://williamdes.github.io/mariadb-mysql-kbs/
        runs-on: ubuntu-latest
        steps:
            - uses: actions/checkout@v4
              with:
                  # To also fetch the gh-pages branch
                  fetch-depth: 0
            - name: build doctum docs
              uses: sudo-bot/action-doctum@dev
              with:
                  config-file: ./scripts/doctum-config.php
                  method: "update"
                  cli-args: "--output-format=github --no-ansi --no-progress -v --force"
            - uses: actions/setup-node@v4
              with:
                  node-version: 20
            - name: Get yarn cache directory path
              id: yarn-cache-dir-path
              run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT
            - name: yarn cache
              uses: actions/cache@v4
              with:
                  path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
                  key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
                  restore-keys: |
                      ${{ runner.os }}-yarn-
            - name: Install sudo-bot
              run: yarn global add sudo-bot
            - name: Run sudo-bot
              env:
                INSTALLATION_ID: ${{ secrets.INSTALLATION_ID }}
                GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }}
                GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
                GH_APP_JWT_PRIV_PEM_CONTENTS: ${{ secrets.GH_APP_JWT_PRIV_PEM_CONTENTS }}
                TARGET_BRANCH: "gh-pages"
                TEMPLATE_FILE: "template-docs.js"
              run: ./scripts/sudo-bot/create-pr.sh
