name: Python application test

on:
  pull_request:
    branches: [ main ]

jobs:
  build:

    runs-on: ubuntu-latest

    strategy:
      matrix:
        python-version: ['3.10']

    steps:
    - uses: actions/checkout@v2
    - name: Set up Python ${{ matrix.python-version }}
      uses: actions/setup-python@v2
      with:
        python-version: ${{ matrix.python-version }}

    - name: Handle secrets
      run: |
        echo -n "${{ secrets.SECRET1 }}" > Zelda/custom_integrations/Zelda-NES/rom.nes.bz2.part1.base64
        echo -n "${{ secrets.SECRET2 }}" > Zelda/custom_integrations/Zelda-NES/rom.nes.bz2.part2.base64
        base64 --decode Zelda/custom_integrations/Zelda-NES/rom.nes.bz2.part1.base64 > Zelda/custom_integrations/Zelda-NES/rom.nes.bz2.part1
        base64 --decode Zelda/custom_integrations/Zelda-NES/rom.nes.bz2.part2.base64 > Zelda/custom_integrations/Zelda-NES/rom.nes.bz2.part2
        cat Zelda/custom_integrations/Zelda-NES/rom.nes.bz2.part1 Zelda/custom_integrations/Zelda-NES/rom.nes.bz2.part2 > Zelda/custom_integrations/Zelda-NES/rom.nes.bz2
        bzip2 -d Zelda/custom_integrations/Zelda-NES/rom.nes.bz2

    - name: Install dependencies
      run: |
        python -m pip install --upgrade pip
        pip install pytest
        pip install -r requirements.txt

    - name: Test with pytest
      run: |
        pytest

    - name: Lint with pylint
      run: |
        pylint Zelda/ evaluate.py run.py train.py
