name: Build and Deploy Docs

on:
  workflow_dispatch:
    inputs:
        commitRef:
          description: 'Git SHA commit to use to build docs'
          required: true

jobs:
  push-docs:
    # 22.04 has broken deps for bison and flex, so reverted to 20.04 for docs build
    # until a more permanent fix is created.
    runs-on: ubuntu-20.04
    steps:
      - name: Checkout
        uses: actions/checkout@v2
        with:
          ref: ${{ github.event.inputs.commitRef }}

      - name: Remove Macro Util Wrapping
        run: |
          python3 .github/scripts/pre_doxygen.py ./iothub_client/inc ./doc-stage
          python3 .github/scripts/pre_doxygen.py ./provisioning_client/inc/azure_prov_client ./doc-stage

      - name: Install and Build Doxygen
        run: .github/scripts/build_doxygen.sh

      - name: Deploy
        uses: JamesIves/github-pages-deploy-action@4.1.3
        with:
          branch: gh-pages
          folder: doc/html
          clean: true
          ssh-key: ${{ secrets.DEPLOY_KEY }}
