name: Build API docs
on:
  repository_dispatch:
    types: [ trigger-changelog-workflow ]
  workflow_dispatch:
    inputs:
      commit_message:
        description: "Commit message"
        required: false

jobs:
  package:
    runs-on: ubuntu-latest
    steps:
      -   name: Checkout repo
          uses: actions/checkout@v2
          with:
            fetch-depth: 0
            submodules: recursive
      - uses: actions/checkout@v2
      - name: build doctum docs
        uses: sudo-bot/action-doctum@v5
        with:
          config-file: "documentation/doctum.config.php"
          # parse, render or update
          method: "update"
          # (optional) defaults to '--output-format=github --no-ansi --no-progress -v'
          cli-args: "--output-format=github --no-ansi --no-progress -v"
      -   uses: oleksiyrudenko/gha-git-credentials@v2-latest
          with:
            token: '${{ secrets.GITHUB_TOKEN }}'
      -   run: "git commit -m \"docs: 📝 Updated API docs for commit ${{ github.sha }}\" -a"
          if: ${{ !github.event.inputs.commit_message && !github.event.inputs.next_version }}
      -  run: "git commit -m \"${{ github.event.inputs.commit_message }}\" -a"
         if: ${{ github.event.inputs.commit_message }}
      -   name: Push changes
          uses: ad-m/github-push-action@master
          with:
            github_token: ${{ secrets.GITHUB_TOKEN }}
            branch: ${{ github.ref }}
