
jobs:
  - job: 'Documentation'
    pool:
      vmImage: 'ubuntu-16.04'
    container:
      image: osgeo/proj-docs
      options: --privileged
    steps:
      - script: |
          python3 --version
          sphinx-build --version
        displayName: 'Sphinx version'
      - script: |
          cd docs
          if find . -name '*.rst' | xargs grep -P '\t'; then echo 'Tabs are bad, please use four spaces in .rst files.'; false; fi
        displayName: 'Lint .rst files'
      - script: |
          cd docs
          make doxygen
          make html
          make latexpdf
        displayName: 'Build Doxygen, HTML, and PDF'
      - task: DownloadSecureFile@1
        inputs:
          secureFile: 'pdal-docs-ssh-key'
        displayName: 'Get the deploy key'
      - script: |
          mkdir ~/.ssh && mv $DOWNLOADSECUREFILE_SECUREFILEPATH ~/.ssh/id_rsa
          chmod 700 ~/.ssh && chmod 600 ~/.ssh/id_rsa
          ssh-keyscan -t rsa github.com >> ~/.ssh/known_hosts
        displayName: 'Deploy the key'
      - script: |
          git config --global user.email "proj4bot@proj4.bot"
          git config --global user.name "PDAL Doc Bot"
          git clone git@github.com:libspatialindex/libspatialindex.github.com.git ../libspatialindex-docs
          cp -r docs/build/html/* ../libspatialindex-docs
          cp -r docs/build/latex/libspatialindex.pdf ../libspatialindex-docs/
          cp -r docs/doxygen/html/* ../libspatialindex-docs/doxygen/

          cd ../libspatialindex-docs
          git add -A
          git commit -m "Update with https://github.com/libspatialindex/libspatialindex/commit/$BUILD_SOURCEVERSION"
          git push origin master
        displayName: 'Deploy the docs'

    dependsOn:
          - win
          - osx
          - linux

    condition: and(notin(variables['Build.Reason'], 'PullRequest'), succeeded())
