name: "Tests"

on:
  push:
    paths:
      - ".github/**/*"
      - "owlmixin/*"
      - "owlmixin/**/*"
      - "tests/*"
      - "tests/**/*"
      - "uv.lock"
      - ".codeclimate.yml"
  pull_request:
    branches:
      - master
  schedule:
    - cron: "0 0 * * *"

jobs:
  test:
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os: [ubuntu-latest, macos-latest, windows-latest]
        python: ["3.9", "3.10", "3.11", "3.12", "3.13"]
    name: Python ${{ matrix.python }} on ${{ matrix.os }}

    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-python@v5
        with:
          python-version: ${{ matrix.python }}

      - name: Install dependencies
        run: |
          pipx install uv
          uv sync

      - run: make test
      - uses: codecov/codecov-action@v3
        if: matrix.python == 3.13 && matrix.os == 'ubuntu-latest' && success()

      - name: "Discord notification (not success)"
        uses: rjstone/discord-webhook-notify@v1
        if: "! success()"
        with:
          description: "⚠ Owlmixin Tests failed!"
          footer: "Python v${{ matrix.python }} on ${{ matrix.os }})"
          severity: error
          avatarUrl: https://www.suruga-ya.jp/database/pics_light/game/871005085.jpg
          webhookUrl: ${{ secrets.DISCORD_WEBHOOK }}

  notify:
    needs: test
    runs-on: ubuntu-latest

    steps:
      - name: "Discord notification (success)"
        uses: rjstone/discord-webhook-notify@v1
        if: always()
        with:
          description: "✅ Owlmixin Tests passed!"
          footer: "Python v3.9/3.10/3.11/3.12/3.13"
          severity: info
          avatarUrl: https://www.suruga-ya.jp/database/pics_light/game/871005085.jpg
          webhookUrl: ${{ secrets.DISCORD_WEBHOOK }}
