name: Build and deploy Roxygen2|pkgdown documentation site
run-name: Documentation Build on push to main branch
on:
  push:
    branches:
      - main

jobs:
  build-and-deploy-documentation:
    runs-on: linux_amd64
    steps:
      - name: Checkout repository
        uses: actions/checkout@v4

      # - name: Install package dependencies
      #   run: |
      #     Rscript -e 'remotes::install_deps(dependencies = TRUE)'

      - name: Call to roxygen2::roxygenise()
        run: |
          Rscript -e 'roxygen2::roxygenise()'

      - name: Call to pkgdown::build_site()
        run: |
          Rscript -e 'pkgdown::build_site()'

      - name: Deploy to WEBROOT
        env:
          WEBROOT: ${{ vars.WEBROOT }}
        run: |
          test -n "$WEBROOT"
          mkdir -p "$WEBROOT"
          rsync -av --delete docs/* "$WEBROOT"
          
