# vim: et ts=2 sw=2
---
name: Python build and package

on: [push]

jobs:
  build:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        # python-version: ['3.9', '3.10', '3.11', '3.12', '3.13']
        python-version: ['3.9']

    steps:
      - uses: actions/checkout@v4

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

      - name: Install dependencies
        run: |
          sudo apt-get install sqlite3
          python -m pip install wheel
          python -m pip install -U pip flake8
          python -m pip install -r requirements.txt

      - name: Lint Python code
        run: |
          flake8 src tests --config=.flake8 --select=E9,F63,F7,F82 --show-source
          flake8 src tests --config=.flake8 --exit-zero --max-complexity=10 --max-line-length=127

      - name: Run unit tests
        env:
          NETWORK_TESTS: 0
          PYTHONPATH: '.:src'
        run: |
          mkdir -p /tmp/fangfrisch/unittest
          sqlite3 /tmp/fangfrisch/unittest/db.sqlite < tests/tests.sql
          python -m unittest discover tests/ -v

      - name: Build
        run: python -m build

      - name: Upload artifacts
        uses: actions/upload-artifact@v4
        with:
          name: ffdist-py${{ matrix.python-version }}
          path: dist/*
