name: Reproducible Research

on:
  push:
    branches:
      - master
  pull_request:
    branches:
      - master
  schedule:
    - cron: 42 8 */21 * *

jobs:
  tcpdbench-ubuntu:
    name: Check TCPDBench (direct)
    runs-on: ubuntu-latest

    steps:
      - name: Install dependencies
        run: sudo apt-get update && sudo apt-get install build-essential latexmk texlive-latex-extra
        shell: bash

      - name: Install Python 3.8
        uses: actions/setup-python@v2
        with:
          python-version: '3.8'

      - name: Install R
        uses: r-lib/actions/setup-r@v2-branch
        with:
          r-version: 'release'

      - name: Install R dependencies
        run: |
          install.packages(c('argparse', 'exactRankTests'))
        shell: Rscript {0}

      - name: Checkout code
        uses: actions/checkout@v2
        with:
          submodules: true

      - name: Install Python dependencies
        run: pip install -r ./analysis/requirements.txt
        shell: bash

      - name: Clone TCPD
        run: git clone https://github.com/alan-turing-institute/TCPD ../TCPD
        shell: bash

      - name: Build TCPD
        run: cd ../TCPD && make export
        shell: bash

      - name: Copy datasets
        run: mkdir -p ./datasets && cp ../TCPD/export/*.json ./datasets/ && pwd && ls -1 .
        shell: bash

      - name: Skip annotation simulation p-values
        run: touch ./analysis/output/tables/annotation_simulation_pvalues.tex
        shell: bash

      - name: Make results
        run: make results
        shell: bash

      - name: Check results
        run: git checkout ./analysis/output/cd_diagrams/*.pdf && git checkout ./analysis/output/figures/anno_hist/histogram*.pdf && git diff --exit-code
        shell: bash

  tcpdbench-docker:
    name: Check TCPDBench (docker)
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v2

      - name: TCPDBench docker check
        run: ./.github/scripts/test_docker.sh
        shell: bash
