Skip to content

tests

tests #229

Workflow file for this run

name: tests
on:
# Run this workflow every time a new commit is pushed to repo
push:
# Also run it once weekly to check for impact due to changes in the OS,
# python, postgres, or any external packages/dependencies
schedule:
- cron: '7 14 * * fri'
jobs:
run-tests:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
# Test with specific supported versions
- name: supported
os: ubuntu-20.04
python: 3.7
postgres: 10
# Test everything with latest versions
- name: latest
os: ubuntu-22.04
python: 3.x
postgres: latest
services:
postgres:
image: postgres:${{ matrix.postgres }}
env:
POSTGRES_PASSWORD: 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:
# Maps tcp port 5432 on service container to the host
- 5432:5432
steps:
- name: Check out repository code
uses: actions/checkout@v3
- name: Install Python ${{ matrix.python }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python }}
# Cache entire Python environment
# - uses: actions/cache@v3
# with:
# path: ${{ env.pythonLocation }}
# # pythonLocation includes exact Python version
# key: build-${{ env.pythonLocation }}-${{ hashFiles('requirements.txt') }}
- name: Install poetry
shell: bash
run: |
curl -sSL https://install.python-poetry.org | POETRY_VERSION=1.4.0 python -
- name: Install dependencies
run: poetry install
- name: Check for flake8 issues
run: poetry run flake8 --exclude "tests" pgmerge/
# We do a separate pass with less stringent documentation requirements
- name: Check for flake8 issues in tests
run: poetry run flake8 --extend-ignore=D pgmerge/
- name: Check for mypy typing issues
run: poetry run mypy --install-types --non-interactive --ignore-missing-imports --strict pgmerge/*.py
# No strict type requirements for tests
- name: Check for mypy typing issues in tests
run: poetry run mypy --ignore-missing-imports pgmerge/tests
- name: Test with pytest
run: |
DB_TEST_URL=postgresql://postgres:postgres@localhost:5432/ SQLALCHEMY_WARN_20=1 poetry run pytest \
--cov-report html --cov-report xml --cov pgmerge --verbose
- name: Get final code coverage percentage & color
run: |
COV_TOTAL=$(poetry run coverage report | grep 'TOTAL' | tr -s ' ' | cut -d ' ' -f 4 | tr -d '%')
if ((COV_TOTAL<=60)); then
COV_COLOR="red"
elif ((COV_TOTAL<=70)); then
COV_COLOR="orange"
elif ((COV_TOTAL<=80)); then
COV_COLOR="yellow"
elif ((COV_TOTAL<=90)); then
COV_COLOR="green"
elif ((COV_TOTAL<=100)); then
COV_COLOR="brightgreen"
else
COV_COLOR="lightgrey"
fi
echo "COV_TOTAL=$COV_TOTAL" >> $GITHUB_ENV
echo "COV_COLOR=$COV_COLOR" >> $GITHUB_ENV
- name: Create code coverage badge
# Ensure we only update once per build
if: matrix.name == 'supported'
uses: schneegans/[email protected]
with:
auth: ${{ secrets.GIST_TOKEN }}
gistID: 3c84321138784d39b31a02d7fe93b31d
filename: badge-coverage.json
label: coverage
message: "${{ env.COV_TOTAL }}%"
color: ${{ env.COV_COLOR }}
- name: Archive code coverage results
# Ensure we only upload once per build
if: matrix.name == 'supported'
uses: actions/upload-artifact@v3
with:
name: code-coverage-report
path: htmlcov/