name: Code Style

on:
  push:
    branches: [ master ]
    paths-ignore:
      - 'src/pretix/locale/**'
      - 'src/pretix/static/**'
  pull_request:
    branches: [ master ]
    paths-ignore:
      - 'src/pretix/locale/**'
      - 'src/pretix/static/**'

jobs:
  isort:
    name: isort
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: Set up Python 3.8
        uses: actions/setup-python@v1
        with:
          python-version: 3.8
      - uses: actions/cache@v1
        with:
          path: ~/.cache/pip
          key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
          restore-keys: |
            ${{ runner.os }}-pip-
      - name: Install Dependencies
        run: pip3 install -e ".[dev]" mysqlclient psycopg2-binary
        working-directory: ./src
      - name: Run isort
        run: isort -c .
        working-directory: ./src
  flake:
    name: flake8
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: Set up Python 3.8
        uses: actions/setup-python@v1
        with:
          python-version: 3.8
      - uses: actions/cache@v1
        with:
          path: ~/.cache/pip
          key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
          restore-keys: |
            ${{ runner.os }}-pip-
      - name: Install Dependencies
        run: pip3 install -e ".[dev]" mysqlclient psycopg2-binary
        working-directory: ./src
      - name: Run flake8
        run: flake8 .
        working-directory: ./src
  licenseheader:
    name: licenseheaders
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - name: Set up Python 3.8
        uses: actions/setup-python@v1
        with:
          python-version: 3.8
      - name: Install Dependencies
        run: pip3 install licenseheaders
      - name: Run licenseheaders
        run: licenseheaders -t ../.licenseheader -E .py -x "*/migrations/*.py"
        working-directory: ./src
      - name: Check for changes
        run: git diff --exit-code
        working-directory: ./src
