name: render-dashboard

on:
  push:
    branches: [main, master]
  pull_request:
    branches: [main, master]
  schedule:
    # every day, every 8 hours
    - cron: '0 0/8 * * *'

concurrency:
  group: ${{ github.workflow }}-${{ github.head_ref }}
  cancel-in-progress: true

jobs:
  build:
    runs-on: macos-latest
    env:
      GITHUB_PAT: ${{ secrets.ETIENNE_TOKEN_DASHBOARD }}
    steps:
      - uses: actions/checkout@v6

      - uses: r-lib/actions/setup-r@v2

      - uses: r-lib/actions/setup-pandoc@v2
      
      - uses: r-lib/actions/setup-r-dependencies@v2

      - name: Render Rmarkdown files
        run: |
          rmarkdown::render("dashboard.Rmd", output_dir = "public")
        shell: Rscript {0}

      - name: Deploy
        uses: peaceiris/actions-gh-pages@v4.0.0
        with:
          github_token: ${{ secrets.ETIENNE_TOKEN_DASHBOARD }}
          publish_dir: ./public
          force_orphan: true
