name: Tests

on:
  push:
    branches:
      - master
      - "release/*"
  pull_request:
    branches:
      - master
      - "release/*"
  workflow_dispatch:

jobs:
  mypy:
    runs-on: ubuntu-latest

    name: 'typecheck: mypy'

    steps:
      - uses: actions/checkout@v2
      - uses: actions/setup-python@v2
        with:
          python-version: '3.9'
      - name: Install
        run: |
          set -euo pipefail
          pip install mypy
          pip install -r requirements.txt
          pip install -r build-requirements.txt
      - name: Typecheck
        run: |
          python -m mypy --config mypy.ini -p snikket_web

  linting:
    runs-on: ubuntu-latest

    name: 'lint: flake8'

    steps:
      - uses: actions/checkout@v2
      - uses: actions/setup-python@v2
        with:
          python-version: '3.9'
      - name: Install
        run: |
          set -euo pipefail
          pip install flake8 flake8-print
      - name: Linting
        run: |
          python -m flake8 snikket_web

  translation-check:
    runs-on: ubuntu-latest

    name: 'lint: i18n'

    steps:
      - uses: actions/checkout@v2
      - uses: actions/setup-python@v2
        with:
          python-version: '3.9'
      - name: Install
        run: |
          set -euo pipefail
          pip install flask-babel
      - name: Linting
        run: |
          sed -ri '/^"POT-Creation-Date: /d;/^"Generated-By: /d' snikket_web/translations/messages.pot
          git add snikket_web/translations/messages.pot
          make extract_translations
          sed -ri '/^"POT-Creation-Date: /d;/^"Generated-By: /d' snikket_web/translations/messages.pot
          git diff --exit-code --color -- snikket_web/translations/messages.pot


  build:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v2
      - name: Build the Docker image
        run: >-
          docker build .
