name: CI

env:
  PKG_CONFIG_PATH: /usr/local/opt/icu4c/lib/pkgconfig
  LC_COLLATE: en_US.UTF-8
on:
  pull_request:
  push:
    branches:
      - '**'
    tags-ignore:
      - '**'
jobs:
  lint:
    permissions:
      checks: write
      contents: read
      pull-requests: write
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        python-version: [3.9]
        os: [ubuntu-latest]

    steps:
      - uses: actions/checkout@v3
        with:
          fetch-depth: 0

      - name: Set up Python ${{ matrix.python-version }}
        uses: actions/setup-python@v3
        with:
          python-version: ${{ matrix.python-version }}

      - name: Install build dependencies
        run: |
          python -m pip install flake8

      - uses: reviewdog/action-setup@v1
        with:
          reviewdog_version: nightly
      - run: flake8 | reviewdog -f=flake8 -reporter=github-pr-review -tee -level=error -fail-on-error
        env:
          REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}

  build-and-test:
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        python-version: [3.9]
        os: [ubuntu-latest, macos-11, windows-latest]

    steps:
      - uses: actions/checkout@v3
        with:
          fetch-depth: 0

      - name: Set up Python ${{ matrix.python-version }}
        uses: actions/setup-python@v3
        with:
          python-version: ${{ matrix.python-version }}

      - name: Install tox
        run: |
          python -m pip install --upgrade --upgrade-strategy eager tox

      - name: Install macos dependencies
        run: |
          brew install icu4c pkg-config
          # export PKG_CONFIG_PATH="/usr/local/opt/icu4c/lib/pkgconfig";
          # export PATH="/usr/local/opt/icu4c/bin:/usr/local/opt/icu4c/sbin:$PATH"
        if: runner.os == 'macOS'

      - name: Install linux dependencies
        run: |
          sudo apt-get update && sudo apt-get upgrade && sudo apt-get install pkg-config libicu-dev libqt5gui5 libfuse2
          # export PKG_CONFIG_PATH="/usr/local/opt/icu4c/lib/pkgconfig";
          # export PATH="/usr/local/opt/icu4c/bin:/usr/local/opt/icu4c/sbin:$PATH"
        if: runner.os == 'Linux'

      - name: Build and install PyPi packages
        run: |
          python -m tox r -m build

      - name: Archive production artifacts
        uses: actions/upload-artifact@v3
        with:
          name: "${{ format('ComicTagger-{0}', runner.os) }}"
          path: |
            dist/*.zip
            dist/*.AppImage

      - name: PyTest
        run: |
          python -m tox r
