ohtu2021-kvantti/WebMark

View on GitHub
.github/workflows/python-package.yml

Summary

Maintainability
Test Coverage
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions

name: Python package

on:
  push:
    branches: [ main ]
  pull_request:
    branches: [ main ]
    types: [opened, synchronize, review_requested]

jobs:
  build:

    runs-on: ubuntu-latest

    services:
      postgres:
        image: postgres:10.8
        env:
          POSTGRES_USER: postgres
          POSTGRES_PASSWORD: postgres
          POSTGRES_DB: github_actions
          POSTGRES_HOST: postgres
          POSTGRES_PORT: ${{ job.services.postgres.port[5432] }}
        ports:
          - 5432:5432
        # needed because the postgres container does not provide a healthcheck
        options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5

    steps:
    - uses: actions/checkout@v2
    - name: Set up Python
      uses: actions/setup-python@v2
      with:
        python-version: 3.7
    - name: Install dependencies
      run: |
        python -m pip install --upgrade pip
        if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
        pip install git+https://github.com/ohtu2021-kvantti/LibMark
    - name: Run migrations
      run: |
        touch .env
        echo DATABASE_NAME=github_actions >> .env
        echo DATABASE_USER=postgres >> .env
        echo DATABASE_PASSWORD=postgres >> .env
        echo DATABASE_HOST=127.0.0.1 >> .env
        echo DATABASE_PORT=5432 >> .env
        echo SECRET_KEY=secret >> .env
        python manage.py makemigrations WebCLI
        python manage.py migrate
    - name: Lint with flake8
      run: flake8 . --show-source --statistics
    - name: Lint with curlylint
      run: curlylint templates/
    - name: Test with Django
      run: |
        coverage erase
        coverage run manage.py test
    - name: "Upload coverage to Codecov"
      uses: codecov/codecov-action@v1
      with:
        fail_ci_if_error: true
    - name: Set up QEMU
      if: ${{ github.event_name == 'push'}}
      uses: docker/setup-qemu-action@v1
    - name: Set up Docker Buildx
      if: ${{ github.event_name == 'push'}}
      uses: docker/setup-buildx-action@v1
    - name: Login to DockerHub
      if: ${{ github.event_name == 'push'}}
      uses: docker/login-action@v1
      with:
        username: ${{ secrets.DOCKERHUB_USERNAME }}
        password: ${{ secrets.DOCKERHUB_TOKEN }}
    - name: Build WebMark and push
      if: ${{ github.event_name == 'push'}}
      uses: docker/build-push-action@v2
      with:
        push: true
        tags: tapanih/quantmark_web:latest
        build-args: LIBMARK_VERSION=main
    - name: Build BenchMark and push
      if: ${{ github.event_name == 'push'}}
      uses: docker/build-push-action@v2
      with:
        push: true
        context: BenchMark/
        tags: tapanih/quantmark_benchmark:latest
        build-args: LIBMARK_VERSION=main