name: Tasks Modified

on:
  push:
    branches:
      - big-refactor
  pull_request:
    branches:
      - big-refactor
  workflow_dispatch:

jobs:
  changed_files:
    runs-on: ubuntu-latest  # windows-latest || macos-latest
    name: Scan for changed tasks
    steps:
      - name: checkout
        uses: actions/checkout@v3
        with:
          fetch-depth: 0  # OR "2" -> To retrieve the preceding commit.

      # Example 1
      - name: Check task folders
        id: changed-tasks
        uses: tj-actions/changed-files@v37.1.2
        with:
          files_yaml: |
            tasks:
              - lm_eval/tasks/**
            api:
              - lm_eval/api/**
          write_output_files: true

      - name: Run Tests
        if: steps.changed-tasks.outputs.tasks_any_modified == 'true' || steps.changed-tasks.outputs.api_any_modified == 'true'
        run: |
          echo .github/outputs/tasks_all_changed_and_modified_files.txt >> 'GITHUB_ENV'
          echo "One or more test file(s) has changed."
          echo "List of all the files that have changed: ${{ steps.changed-tasks.outputs.tasks_all_modified_files }}"
      - name: Set up Python 3.9
        if: steps.changed-tasks.outputs.tasks_any_modified == 'true' || steps.changed-tasks.outputs.api_any_modified == 'true'
        uses: actions/setup-python@v4
        with:
          python-version: 3.9
          cache: 'pip'
      - name: Install dependencies
        if: steps.changed-tasks.outputs.tasks_any_modified == 'true' || steps.changed-tasks.outputs.api_any_modified == 'true'
        run: |
            python -m pip install --upgrade pip
            pip install -e '.[testing]' --extra-index-url https://download.pytorch.org/whl/cpu
            #         Install optional git dependencies
    #                pip install bleurt@https://github.com/google-research/bleurt/archive/b610120347ef22b494b6d69b4316e303f5932516.zip#egg=bleurt
    #        if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
      - name: Test with pytest
        if: steps.changed-tasks.outputs.tasks_any_modified == 'true'
        run: python -m pytest tests/test_tasks.py -s -vv -n=auto --new_task
      - name: Test more tasks with pytest
        env:
          API: true
        if: steps.changed-tasks.outputs.api_any_modified == 'true'
        run: python -m pytest tests/test_api.py -s -vv -n=auto --new_task
