name: Python package

on: [push]

jobs:
  build:

    runs-on: ubuntu-latest
    strategy:
      matrix:
        python-version: [3.8]

    steps:
    - uses: actions/checkout@v2
    - name: Set up Python ${{ matrix.python-version }}
      uses: actions/setup-python@v2
      with:
        python-version: ${{ matrix.python-version }}
    - name: Install dependencies
      run: |
        sudo apt-get install graphviz
        python -m pip install --upgrade pip
        pip install flake8 pytest pep8-naming
        if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
    - name: Lint with flake8
      run: |
        # stop the build if there are Python syntax errors or undefined names
        flake8 --ignore "N801, E203, E266, E501, W503, F812, F401, F841, F811, F821, E741, N803, N802, N806" minitorch/ tests/ project/

  test_0:
    if: github.ref_name == 'task_0'
    runs-on: ubuntu-latest
    needs: build
    strategy:
      matrix:
        python-version: [ 3.8 ]

    steps:
    - uses: actions/checkout@v2
    - name: Set up Python ${{ matrix.python-version }}
      uses: actions/setup-python@v2
      with:
        python-version: ${{ matrix.python-version }}
    - name: Install dependencies
      run: |
        sudo apt-get install graphviz
        python -m pip install --upgrade pip
        pip install flake8 pytest pep8-naming
        if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
    - name: Test Module 0 with pytest
      run: |
        echo "Module 0"
        pytest tests -x -m task0_1
        pytest tests -x -m task0_2
        pytest tests -x -m task0_3
        pytest tests -x -m task0_4

  test_1:

    if: github.ref_name == 'task_1'
    runs-on: ubuntu-latest
    needs: build
    strategy:
      matrix:
        python-version: [ 3.8 ]

    steps:
    - uses: actions/checkout@v2
    - name: Set up Python ${{ matrix.python-version }}
      uses: actions/setup-python@v2
      with:
        python-version: ${{ matrix.python-version }}
    - name: Install dependencies
      run: |
        sudo apt-get install graphviz
        python -m pip install --upgrade pip
        pip install flake8 pytest pep8-naming
        if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
    - name: Test Module 1 with pytest
      run: |
        echo "Module 1"
        pytest tests -x -m task1_1
        pytest tests -x -m task1_2
        pytest tests -x -m task1_3
        pytest tests -x -m task1_4

  test_2:
    if: github.ref_name == 'task_2'
    runs-on: ubuntu-latest
    needs: build
    strategy:
      matrix:
        python-version: [ 3.8 ]

    steps:
    - uses: actions/checkout@v2
    - name: Set up Python ${{ matrix.python-version }}
      uses: actions/setup-python@v2
      with:
        python-version: ${{ matrix.python-version }}
    - name: Install dependencies
      run: |
        sudo apt-get install graphviz
        python -m pip install --upgrade pip
        pip install flake8 pytest pep8-naming
        if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
    - name: Test Module 2 with pytest
      run: |
        echo "Module 2"
        pytest tests -x -m task2_1
        pytest tests -x -m task2_2
        pytest tests -x -m task2_3
        pytest tests -x -m task2_4

  test_3:
    if: github.ref_name == 'task_3'
    runs-on: ubuntu-latest
    needs: build
    strategy:
      matrix:
        python-version: [ 3.8 ]

    steps:
    - uses: actions/checkout@v2
    - name: Set up Python ${{ matrix.python-version }}
      uses: actions/setup-python@v2
      with:
        python-version: ${{ matrix.python-version }}
    - name: Install dependencies
      run: |
        sudo apt-get install graphviz
        python -m pip install --upgrade pip
        pip install flake8 pytest pep8-naming
        if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
    - name: Test Module 3 with pytest
      run: |
        echo "Module 3"
        pytest tests -x -m task3_1
        pytest tests -x -m task3_2
        pytest tests -x -m task3_3
        pytest tests -x -m task3_4

  test_4:

    if: github.ref_name == 'task_4'
    runs-on: ubuntu-latest
    needs: build
    strategy:
      matrix:
        python-version: [ 3.8 ]

    steps:
    - uses: actions/checkout@v2
    - name: Set up Python ${{ matrix.python-version }}
      uses: actions/setup-python@v2
      with:
        python-version: ${{ matrix.python-version }}
    - name: Install dependencies
      run: |
        sudo apt-get install graphviz
        python -m pip install --upgrade pip
        pip install flake8 pytest pep8-naming
        if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
    - name: Test Module 4 with pytest
      run: |
        echo "Module 4"
        pytest tests -x -m task4_1
        pytest tests -x -m task4_2
        pytest tests -x -m task4_3
        pytest tests -x -m task4_4
