name: CI
on: [push, pull_request]
jobs:
  build:
    if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name != github.repository
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os: [macos-latest, windows-latest, ubuntu-latest]
        python-version: ['3.10', '3.11', '3.12', '3.13', '3.14', pypy-3.11]
    steps:
      - uses: actions/checkout@v6
      - uses: actions/setup-python@v6
        with:
          python-version: ${{ matrix.python-version }}
          cache: pip
          cache-dependency-path: setup.py
      - run: pip install --ignore-installed .[test] coveralls
      - env:
          LANG: en_US.UTF-8
          PYTHONUTF8: 1
        run: pytest --cov csvkit
      # csvpy cannot accept input as piped data via STDIN.
      - name: Read from stdin
        if: matrix.os != 'windows-latest'
        run: |
          csvclean -a < examples/dummy.csv
          csvcut < examples/dummy.csv
          csvformat < examples/dummy.csv
          csvgrep -c1 -m1 < examples/dummy.csv
          csvjoin < examples/dummy.csv
          csvjson < examples/dummy.csv
          csvlook < examples/dummy.csv
          csvsort < examples/dummy.csv
          csvsql < examples/dummy.csv
          csvstack < examples/dummy.csv
          csvstat < examples/dummy.csv
          in2csv -f csv < examples/dummy.csv
          sql2csv < examples/test.sql
      - name: Read from pipe
        run: |
          printf 'a,b,c\n1,2,3' | csvclean -a
          printf 'a,b,c\n1,2,3' | csvcut
          printf 'a,b,c\n1,2,3' | csvformat
          printf 'a,b,c\n1,2,3' | csvgrep -c1 -m1
          printf 'a,b,c\n1,2,3' | csvjoin
          printf 'a,b,c\n1,2,3' | csvjson
          printf 'a,b,c\n1,2,3' | csvlook
          printf 'a,b,c\n1,2,3' | csvsort
          printf 'a,b,c\n1,2,3' | csvsql
          printf 'a,b,c\n1,2,3' | csvstack
          printf 'a,b,c\n1,2,3' | csvstat
          printf 'a,b,c\n1,2,3' | in2csv -f csv
          printf 'SELECT 1 AS a' | sql2csv
      - env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        run: coveralls --service=github
