name: Python-Lint

on:
  push:
    paths:
    - '*.py'
    - poetry.lock
    - pyproject.toml
  pull_request:

jobs:
  run-linters:
    name: Black & mypy
    runs-on: ubuntu-latest
    steps:
    - name: Set up python
      id: setup-python
      uses: actions/setup-python@v4
      with:
        python-version: '3.11'
    - name: Check out Git repository
      uses: actions/checkout@v3
    - name: Install and configure Poetry
      uses: snok/install-poetry@v1
      with:
        version: 1.4.2
        virtualenvs-create: false
        virtualenvs-path: ~/local/share/virtualenvs
    - run: poetry install --without develop,doc,test
    - name: Run linters
      uses: wearerequired/lint-action@v2
      with:
        black: true
        mypy: true

  ruff:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v3
    - uses: chartboost/ruff-action@v1
      with:
        version: 0.0.277

  python-requirements:
    name: Check Python Requirements
    runs-on: ubuntu-latest
    steps:
    - name: Set up python
      id: setup-python
      uses: actions/setup-python@v4
      with:
        python-version: '3.11'
    - name: Install and configure Poetry
      uses: snok/install-poetry@v1
      with:
        version: 1.4.2
        virtualenvs-path: ~/local/share/virtualenvs
    - name: Cache pipenv
      id: cache-pipenv
      uses: actions/cache@v3
      with:
        path: ~/.local/share/virtualenvs
        key: venv
    - name: Check out Git repository
      uses: actions/checkout@v3
    - name: Poetry export
      run: poetry export -f requirements.txt --output requirements.txt
    - name: Check license
      run: |
        poetry run pip install pip-licenses
        poetry run pip-licenses --format=markdown --output-file=license-summary.md
    - name: Archive license summary
      uses: actions/upload-artifact@v3
      with:
        name: license-summary
        path: |
          license-summary.md
          requirements.txt
    - name: Check requirements security with pip-audit
      uses: pypa/gh-action-pip-audit@v1.0.0
      with:
        inputs: requirements.txt
