Andrey-Volkovitskiy/python-project-83

View on GitHub
.github/workflows/pytest_with_postgres.yml

Summary

Maintainability
Test Coverage
name: Pytest (with postgres)
on: push

jobs:
  runner-job:
    runs-on: ubuntu-latest

    # Service containers to run with `runner-job`
    services:
      # Label used to access the service container
      postgres:
        # Docker Hub image
        image: postgres:latest
        # Provide the password for postgres
        env:
          POSTGRES_PASSWORD: ${{ secrets.SECRET_KEY }}
        # Set health checks to wait until postgres has started
        options: >-
          --health-cmd pg_isready
          --health-interval 10s
          --health-timeout 5s
          --health-retries 5
        ports:
          # Maps tcp port 5432 on service container to the host
          - 5432:5432

    steps:
      - name: Check out repository code
        uses: actions/checkout@v3

      - name: Set up Python
        uses: actions/setup-python@v4
        with:
          python-version: "3.11.1"

      - name: Install dependencies
        run: |
          pip install poetry
          make install

      - name: Test with pytest
        run: |
          make test
        env:
          SECRET_KEY: ${{ secrets.SECRET_KEY }}
          DATABASE_URL: postgresql://postgres:${{ secrets.SECRET_KEY }}@localhost:5432/postgres
          PROJECT_ENV: GitHub_Workflow_Tests

      - name: Test coverage
        run: |
          poetry run python3 -m pytest --cov=page_analyzer/ tests/ --cov-report xml
        env:
          SECRET_KEY: ${{ secrets.SECRET_KEY }}
          DATABASE_URL: postgresql://postgres:${{ secrets.SECRET_KEY }}@localhost:5432/postgres
          PROJECT_ENV: GitHub_Workflow_Tests

      - name: Publish code coverage
        uses: paambaati/codeclimate-action@v3.2.0
        env:
          CC_TEST_REPORTER_ID: f4cb57cb20d261af4d7d9b684a131c1f49e336373d2928adea34c94185212d0e