name: Run Pipeline Tests

on:
  workflow_dispatch

env:
  NEXTFLOW_VERSION: 23.10.1
  NF_TEST_VERSION: 0.8.3
  AWS_CLI_VERSION: 2.15.19
  AWS_ACCESS_KEY_ID: ${{ secrets.AWS_PUBLIC_KEY }}
  AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_KEY }}
  AWS_DEFAULT_REGION: 'us-east-1'

jobs:

  build:

    runs-on: ubuntu-latest

    steps:
    - name: Clean workspace before start
      run: rm -rf $GITHUB_WORKSPACE/*

    - uses: actions/checkout@v4.1.1

    - name: Set up JDK 11
      uses: actions/setup-java@v4.0.0
      with:
        java-version: '11'
        distribution: 'adopt'

    - name: Install nextflow
      run: sudo bash; cd /opt; wget "https://github.com/nextflow-io/nextflow/releases/download/v${NEXTFLOW_VERSION}/nextflow"; chmod +x nextflow;

    - name: Install nf-test
      run: sudo bash; cd /opt; wget "https://github.com/askimed/nf-test/releases/download/v${NF_TEST_VERSION}/nf-test-${NF_TEST_VERSION}.tar.gz"; tar -xvf "nf-test-${NF_TEST_VERSION}.tar.gz"; chmod +x nf-test; rm "/opt/nf-test-${NF_TEST_VERSION}.tar.gz"

    - name: Install aws cli
      run: curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64-${AWS_CLI_VERSION}.zip" -o "awscliv2.zip"; unzip awscliv2.zip; sudo ./aws/install --update

    - name: Add software to path
      run: echo "/opt" >> $GITHUB_PATH;

    - name: Run ncbi_download test
      run: nf-test test tests/modules/local/download_ncbi.nf.test

    - name: Run gffread test
      run: nf-test test tests/modules/local/gffread.nf.test

    - name: Run get data test
      run: nf-test test tests/modules/local/getdata.nf.test

    - name: Run orthofinder test
      run: nf-test test tests/modules/local/orthofinder.nf.test

    - name: Run cafe test
      run: nf-test test tests/modules/local/cafe.nf.test

    - name: Run cafe_go test
      run: nf-test test tests/modules/local/cafe_go.nf.test

    #- name: Run chromo_go test (Not needed as this module is not in final pipeline [for now])
    #  run: nf-test test tests/modules/local/chromo_go.nf.test

    - name: Run go assign test
      run: nf-test test tests/modules/local/go_assign.nf.test

    #- name: Run go expansion test (Not needed as this module is not in final pipeline [for now])
    #  run: nf-test test tests/modules/local/go_expansion.nf.test

    #- name: Download aws module test cds files
    #  run:  aws s3 cp s3://excon/data/Insect_data/fasta/* data/; aws s3 cp s3://excon/data/Insect_data/gofiles/* data/

    - name: Clean workspace after finish
      run: rm -rf $GITHUB_WORKSPACE/*
