vbudovski/django-tree

View on GitHub
.github/workflows/django.yml

Summary

Maintainability
Test Coverage
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.8"
          - "3.9"
          - "3.10"
        django-version:
          - "3.2"
          - "4.1"

    services:
      # Label used to access the service container
      postgres:
        # Docker Hub image
        image: postgres
        # Provide the password for postgres
        env:
          POSTGRES_USER: postgres
          POSTGRES_PASSWORD: postgres
          POSTGRES_DB: postgres
        # Set health checks to wait until postgres has started
        options: >-
          --health-cmd pg_isready
          --health-interval 10s
          --health-timeout 5s
          --health-retries 5
        ports:
          - 5432/tcp

    env:
      DB_HOST: localhost
      DB_USER: postgres
      DB_PASSWORD: postgres
      DB_NAME: postgres
      SERVER_HOSTNAME: localhost

    steps:
      - uses: actions/checkout@v3
        with:
          fetch-depth: 1

      - name: Install Poetry
        uses: snok/install-poetry@v1
        with:
          version: '1.2.2'

      - name: Set up Python ${{ matrix.python-version }}
        uses: actions/setup-python@v4
        with:
          python-version: ${{ matrix.python-version }}
          cache: 'poetry'

      - name: Upgrade pip version
        run: |
          python -m pip install -U pip

      - name: Install Dependencies
        run: |
          poetry env use ${{ matrix.python-version }}
          poetry install
          poetry add django@~${{ matrix.django-version }}

      - name: Lint
        run: |
          poetry run isort -c .
          poetry run flake8 django_tree

      - name: Run Tests
        env:
          DB_PORT: ${{ job.services.postgres.ports[5432] }} # get randomly assigned published port
        run: |
          poetry run python -m pytest tests --cov . --cov-report xml

      - name: Coverage
        uses: paambaati/codeclimate-action@v2.6.0
        env:
          CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
        with:
          coverageCommand: poetry run python -m coverage xml
          debug: false
          coverageLocations: |
            ${{github.workspace}}/coverage.xml:coverage.py