name: CI

on:
  pull_request:
  push:
    branches:
      - main

permissions:
  contents: read

jobs:
  test-linux:
    name: Test Linux app
    runs-on: ubuntu-24.04
    timeout-minutes: 15

    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Secret hygiene scan
        run: |
          patterns_file=.github/secret-scan-patterns.txt
          if [ ! -f "$patterns_file" ]; then
            echo "Missing $patterns_file"
            exit 1
          fi
          pattern="$(grep -vE '^[[:space:]]*(#|$)' "$patterns_file" | paste -sd'|' -)"
          if [ -z "$pattern" ]; then
            echo "No patterns loaded from $patterns_file"
            exit 1
          fi
          if grep -RInE \
              --exclude-dir=.git \
              --exclude=secret-scan-patterns.txt \
              "$pattern" .; then
            echo "Potential secret or private project reference found."
            exit 1
          fi

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

      - name: Install dependencies
        run: |
          sudo apt-get update
          sudo apt-get install -y python3-gi gir1.2-gtk-3.0 gir1.2-appindicator3-0.1 libgirepository1.0-dev libcairo2-dev python3-dev
          cd linux
          pip install -r requirements.txt
          pip install pytest ruff PyGObject

      - name: Syntax check
        run: |
          cd linux
          python -m py_compile blitztext/*.py

      - name: Run Pytest
        run: |
          cd linux
          PYTHONPATH=. pytest tests
