##============================================================================
##  The contents of this file are covered by the Viskores license. See
##  LICENSE.txt for details.
##
##  By contributing to this file, all contributors agree to the Developer
##  Certificate of Origin Version 1.1 (DCO 1.1) as stated in DCO.txt.
##============================================================================

name: Doxygen
on:
  push:
    branches:
      - main
      - 'release**'
  pull_request:

concurrency:
  group: doxygen-${{ github.head_ref || github.run_id }}
  cancel-in-progress: true

jobs:
  user_guide:
    runs-on: ubuntu-latest
    container:
      image: "kitware/vtkm:ci-doxygen-20231020"
    env:
      CMAKE_BUILD_TYPE: Release
      CMAKE_GENERATOR: 'Ninja'
      VISKORES_SETTINGS: "shared+docs"
    steps:
      - uses: actions/checkout@v4
        with:
          submodules: recursive

      - if: github.event_name == 'pull_request'
        run: echo ${{ github.event.pull_request.head.sha }} > ORIGINAL_COMMIT_SHA

      - run: cmake -V -P .github/ci/github_adaptor.cmake
      - run: cmake -V -P .gitlab/ci/config/gitlab_ci_setup.cmake
      - run: ctest -VV -S .gitlab/ci/ctest_configure.cmake
      - run: cmake --build ./build --target  ViskoresUsersGuideHTML
      - uses: actions/upload-artifact@v4
        with:
          name: doxygen-pages-${{ github.sha }}
          path: build/docs/doxygen/html
          overwrite: true
  push:
    if: github.ref_name == 'release'
    needs: [user_guide]
    runs-on: ubuntu-latest
    container:
      image: "kitware/vtkm:ci-doxygen-20231020"
    environment:
      name: doxygen
      url: https://viskores.github.io/viskores-doxygen/
    steps:
      - uses: actions/checkout@v4
        with:
          repository: "Viskores/viskores-doxygen"
          token: ${{ secrets.DOXYGEN_TOKEN }}

      - uses: actions/download-artifact@v4
        with:
          name: doxygen-pages-${{ github.sha }}
      - run: |
          git config --global --add safe.directory "${PWD}"
          git config --global user.name viskores-robot
          git config --global user.email "${GITHUB_ACTOR}+github-actions[bot]@users.noreply.github.com"
          git add -A
          git commit --allow-empty --all --message "${GITHUB_SHA}"
          git push
