wangonya/auto-repair-saas

View on GitHub
.github/workflows/django.yml

Summary

Maintainability
Test Coverage
name: Django CI

on:
  push:
    branches: [main]
  pull_request:
    branches: [main]

jobs:
  create-virtualenv:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v1
      - uses: actions/setup-python@v2
      - uses: syphar/restore-virtualenv@v1
        id: cache-virtualenv

      - uses: syphar/restore-pip-download-cache@v1
        if: steps.cache-virtualenv.outputs.cache-hit != 'true'

      - run: pip install -r requirements.txt
        if: steps.cache-virtualenv.outputs.cache-hit != 'true'

  build-docs:
    needs: create-virtualenv
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v1
      - uses: actions/setup-python@v2
      - uses: syphar/restore-virtualenv@v1
        id: cache-virtualenv

      - name: Build docs
        env:
          INPUT_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        run: |
          chmod +x ./publish_docs.sh
          ./publish_docs.sh

  tests:
    needs: create-virtualenv
    runs-on: ubuntu-latest
    services:
      postgres:
        image: postgres:10.8
        env:
          POSTGRES_USER: postgres
          POSTGRES_PASSWORD: postgres
          POSTGRES_DB: github_actions
        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@v1
      - uses: actions/setup-python@v2
      - uses: syphar/restore-virtualenv@v1
        id: cache-virtualenv

      - name: psycopg2 prerequisites
        run: sudo apt-get install python-dev libpq-dev
      - name: Setup CC Test Reporter
        run: |
          curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
          chmod +x ./cc-test-reporter
          ./cc-test-reporter before-build
      - name: Run Tests
        env:
          SECRET_KEY: ${{ secrets.SECRET_KEY }}
        run: |
          coverage run --source='auto_repair_saas.apps' manage.py test
          coverage xml
      - name: Upload Test Results
        env:
          CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
        run: |
          ./cc-test-reporter format-coverage -t coverage.py
          ./cc-test-reporter upload-coverage