name: "CI"

on:
  push:
    branches:
      - "main"
    tags:
      - "v*"
  pull_request:
    branches:
      - "main"

jobs:
  ci:
    name: "CI & PyPI publish"
    runs-on: "ubuntu-latest"
    permissions:
      id-token: write
    steps:
      - name: "Checkout the repository"
        uses: "actions/checkout@v4.2.2"

      - name: "Set up Python"
        uses: actions/setup-python@v5.3.0
        with:
          python-version: "3.12"
          cache: "pip"

      - name: "Install requirements"
        run: python3 -m pip install -r requirements.txt

      - name: "Lint"
        run: python3 -m ruff check .

      - name: "Format"
        run: python3 -m ruff format . --check

      - name: Install package
        run: |
          python -m pip install -e .

      - name: Test package
        run: |
          python -m pytest --cov=src/py_netgear_plus tests

      - name: Build packages
        run: |
          python -m build
        if: contains(github.ref, 'refs/tags')

      - name: Publish package
        uses: pypa/gh-action-pypi-publish@v1.10.3
        if: contains(github.ref, 'refs/tags')
