---
name: External Use

on:
  push:
    branches:
      - "main"
      - "dev"
  pull_request:
    branches:
      - "main"
      - "dev"
  workflow_dispatch:

permissions: read-all

jobs:
  tima-test:
    name: tima-${{ matrix.os }}
    runs-on: ${{ matrix.os }}
    env:
      GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
    strategy:
      matrix:
        os:
          - "ubuntu-latest"
          - "macos-latest"
          - "windows-latest"
    defaults:
      run:
        shell: bash
    steps:
      - uses: actions/checkout@v4
      - name: Get number of CPU cores
        uses: SimenB/github-actions-cpu-cores@v2
        id: cpu-cores
      - uses: r-lib/actions/setup-r@v2
        with:
          use-public-rspm: true
          Ncpus: ${{ steps.cpu-cores.outputs.count }}
      - name: Install dependencies on Ubuntu
        if: matrix.os == 'ubuntu-latest'
        run: |
          sudo apt-get update && sudo apt-get install -y --no-install-recommends libcurl4-openssl-dev libharfbuzz-dev libfribidi-dev \
          && sudo apt-get clean \
          && sudo rm -rf /var/lib/apt/lists/*
      - name: Install
        run: |
          install.packages("tima", repos = c("https://taxonomicallyinformedannotation.r-universe.dev", "https://bioc.r-universe.dev", "https://cloud.r-project.org"))
          tima::install()
        shell: Rscript {0}
      - name: Get example files
        run: |
          tima::get_example_files()
        shell: Rscript {0}
      - name: Run pipeline
        run: |
          tima::tima_full()
          # Check if targets works correctly
          tima::tima_full()
        shell: Rscript {0}
