name: test-mysql

on:
  push:
    branches:
      - main
  pull_request:
    branches:
      - main

jobs:
  test-mysql:
    runs-on: ubuntu-24.04
    strategy:
      max-parallel: 4
      matrix:
        python-version: [3.12]
        django-version: [4.2.9, 5.0.1]
        include:
          - python-version: "3.9"
            django-version: "2.2.13"
          - python-version: "3.9"
            django-version: "3.2.4"

    env:
      MYSQL_PASSWORD: mysql
      MYSQL_USER: mysql
      MYSQL_DATABASE: test_db
      MYSQL_HOST: 127.0.0.1
      TEST_WITH_MYSQL: true

    services:
      mysql:
        image: mysql
        ports: ["3306:3306"]
        env:
          MYSQL_PASSWORD: mysql
          MYSQL_ROOT_PASSWORD: mysql
          MYSQL_USER: mysql
          MYSQL_DATABASE: test_db
        options: >-
          --health-cmd "mysqladmin ping"
          --health-interval 10s
          --health-timeout 10s
          --health-retries 5

    steps:
      - uses: actions/checkout@v1
      - name: Set up Python ${{ matrix.python-version }}
        uses: actions/setup-python@v2
        with:
          python-version: ${{ matrix.python-version }}
      - name: Install tooling
        run: |
          python -mpip install poetry codecov
      - name: Install dependencies
        run: |
          poetry install --with testmysql,dev
      - name: Setup Django ${{ matrix.django-version }}
        run: |
          poetry run pip install django==${{ matrix.django-version }}
      - name: Test with pytest
        run: |
          poetry run py.test --cov=./django_hashids/ --no-migrations
      - name: Upload coverage to codecov
        run: |
          codecov
        env:
          CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
