name: Django CI

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

jobs:
  build:

    runs-on: ubuntu-latest
    strategy:
      max-parallel: 4
      matrix:
        python-version: [3.6, 3.7, 3.8]

    steps:
    - name: Start MySQL
      uses: samin/mysql-action@v1.3
      with:
        # The port of host
        host port: 3306 # optional, default is 3306
        # The port of container
        container port: 3306 # optional, default is 3306
        # --character-set-server - The character set of MySQL server
        character set server: utf8mb4 # optional, default is utf8mb4
        # --collation-server - The character collation of MySQL server
        collation server: utf8mb4_general_ci # optional, default is utf8mb4_general_ci
        # Version of MySQL to use
        mysql version: latest # optional, default is latest
        # MYSQL_ROOT_PASSWORD - root superuser password
        mysql root password: root # optional, default is 
        # MYSQL_DATABASE - name for the default database that is created
        mysql database: djangoblog # optional, default is 
        # MYSQL_USER - create the specified user with superuser power for created database
        mysql user: root # optional, default is 
        # MYSQL_PASSWORD - specified superuser password which user is power for created database
        mysql password: root # optional, default is 
    - uses: actions/checkout@v2
    - name: Set up Python ${{ matrix.python-version }}
      uses: actions/setup-python@v1
      with:
        python-version: ${{ matrix.python-version }}
    - name: Install Dependencies
      run: |
        python -m pip install --upgrade pip
        pip install -r requirements.txt
    - name: Run Tests
      env:
        DJANGO_MYSQL_PASSWORD:  root
        DJANGO_MYSQL_HOST: 127.0.0.1
      run: |
        python manage.py makemigrations
        python manage.py migrate
        python manage.py test
