name: qbic-pipelines CI
# This workflow runs the pipeline with the minimal test dataset to check that it completes without any syntax errors
on:
  push:
    branches:
      - dev
  pull_request:
  release:
    types: [published]

jobs:
  test:
    name: Run workflow tests
    # Only run on push if this is the qbic-pipelines dev branch (merged PRs)
    runs-on: ubuntu-latest
    env:
      NXF_VER: ${{ matrix.nxf_ver }}
      NXF_ANSI_LOG: false
    strategy:
      matrix:
        # Nextflow versions: check pipeline minimum and current latest
        nxf_ver: ['20.04.1', '']
        config: ['test_chr','test_bai','test_cram']
    steps:
      - name: Check out pipeline code
        uses: actions/checkout@v2

      - name: Check if Dockerfile or Conda environment changed
        uses: technote-space/get-diff-action@v4
        with:
          FILES: |
            Dockerfile
            environment.yml
      - name: Build new docker image
        if: env.MATCHED_FILES
        run: docker build --no-cache . -t qbicpipelines/bamtofastq:1.2.0

      - name: Pull docker image
        if: ${{ !env.MATCHED_FILES }}
        run: |
          docker pull qbicpipelines/bamtofastq:1.2.0
          docker tag qbicpipelines/bamtofastq:1.2.0 qbicpipelines/bamtofastq:1.2.0
      - name: Install Nextflow
        run: |
          wget -qO- get.nextflow.io | bash
          sudo mv nextflow /usr/local/bin/
      - name: Run pipeline with test data
        # TODO nf-core: You can customise CI pipeline run tests as required
        # For example: adding multiple test runs with different parameters
        # Remember that you can parallelise this by using strategy.matrix
        run: |
          nextflow run ${GITHUB_WORKSPACE} -profile test,docker
      - name: Run pipeline with test data, only obtain reads mapping to chrX and chrY
        run: |
          nextflow run ${GITHUB_WORKSPACE} -profile ${{ matrix.config }},docker
