tests #329
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.5.1 python - | |
- name: Install dependencies | |
run: poetry install | |
- name: Check for linting issues | |
run: ./run.sh lint | |
- name: Test with pytest | |
run: ./run.sh test | |
- name: Check consistent versions | |
run: ./run.sh check-version | |
- name: Get final code coverage percentage & color | |
run: | | |
COV_TOTAL=$(poetry run coverage report | grep 'TOTAL' | tr -s ' ' | rev | cut -d ' ' -f 1 | rev | 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@v4 | |
with: | |
name: code-coverage-report | |
path: htmlcov/ | |
# Ignore errors where parallel execution causes conflicting uploads | |
# See: https://github.com/actions/upload-artifact/issues/506 | |
continue-on-error: true |