name: packer

on:
  push:
    branches:
      - master
      - main

jobs:
  check:

    env:
      R_REMOTES_NO_ERRORS_FROM_WARNINGS: true

    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v2

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

      - name: Install R dependencies
        run: |
          install.packages("remotes")
          saveRDS(remotes::dev_package_deps(dependencies = TRUE), ".github/depends.Rds", version = 2)
          writeLines(sprintf("R-%i.%i", getRversion()$major, getRversion()$minor), ".github/R-version")
        shell: Rscript {0}

      - name: Install system dependencies
        if: runner.os == 'Linux'
        run: |
          while read -r cmd
          do
            eval sudo $cmd
          done < <(Rscript -e 'writeLines(remotes::system_requirements("ubuntu", "20.04"))') 

      - name: Install Dependencies
        run: Rscript -e "remotes::install_deps(dependencies = TRUE)"

      - name: Install NPM Dependencies
        run: Rscript -e "packer:::engine_install()"

      - name: Check minification
        run: Rscript -e "packer:::are_minified('inst')"
