name: Test

on: [push, pull_request]

jobs:
  pytest-win:
    name: 'Python Windows'
    runs-on: windows-latest

    steps:
    - uses: actions/checkout@v4

    - name: Restore cached original binaries
      id: cache-original-binaries
      uses: actions/cache/restore@v3
      with:
        enableCrossOsArchive: true
        path: legobin
        key: legobin

    - name: Download original island binares
      if: ${{ !steps.cache-original-binaries.outputs.cache-hit }}
      run: |
        C:\msys64\usr\bin\wget.exe https://legoisland.org/download/ISLE.EXE --directory-prefix=legobin
        C:\msys64\usr\bin\wget.exe https://legoisland.org/download/LEGO1.DLL --directory-prefix=legobin

    - name: Cache original binaries
      if: ${{ !steps.cache-original-binaries.outputs.cache-hit }}
      uses: actions/cache/save@v3
      with:
        enableCrossOsArchive: true
        path: legobin
        key: legobin

    - name: Install python libraries
      shell: bash
      run: |
        pip install pytest -r tools/requirements.txt

    - name: Run python unit tests (Windows)
      shell: bash
      run: |
        pytest tools/isledecomp --lego1=legobin/LEGO1.DLL

  pytest-ubuntu:
    name: 'Python Linux'
    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v4

    - name: Restore cached original binaries
      id: cache-original-binaries
      uses: actions/cache/restore@v3
      with:
        enableCrossOsArchive: true
        path: legobin
        key: legobin

    - name: Download original island binares
      if: ${{ !steps.cache-original-binaries.outputs.cache-hit }}
      run: |
        wget https://legoisland.org/download/ISLE.EXE --directory-prefix=legobin
        wget https://legoisland.org/download/LEGO1.DLL --directory-prefix=legobin

    - name: Cache original binaries
      if: ${{ !steps.cache-original-binaries.outputs.cache-hit }}
      uses: actions/cache/save@v3
      with:
        enableCrossOsArchive: true
        path: legobin
        key: legobin

    - name: Install python libraries
      shell: bash
      run: |
        pip install pytest -r tools/requirements.txt

    - name: Run python unit tests (Ubuntu)
      shell: bash
      run: |
        pytest tools/isledecomp --lego1=legobin/LEGO1.DLL
