Skip to content

Instantly share code, notes, and snippets.

@Bearbobs
Created August 22, 2020 05:57
Show Gist options
  • Save Bearbobs/3116d04cb91ebfe4023996a81fb89620 to your computer and use it in GitHub Desktop.
Save Bearbobs/3116d04cb91ebfe4023996a81fb89620 to your computer and use it in GitHub Desktop.
name: pr-coverage
on: pull_request
jobs:
build:
runs-on: ubuntu-latest
strategy:
max-parallel: 4
matrix:
python-version: [3.6]
services:
# setup local postgresql
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@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install System Dependencies
run: |
sudo apt install libpq-dev python3-dev python-psycopg2 curl
- name: Cache pip
uses: actions/cache@v2
with:
# This path is specific to Ubuntu
path: ~/.cache/pip
# Look to see if there is a cache hit for the corresponding requirements file
key: ${{ runner.os }}-pip-${{ hashFiles('requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
${{ runner.os }}-
- name: Install Dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Run Tests and Modifying and uploading coverage report
run: |
touch local.env
echo DEBUG_VALUE=1 > local.env
cd data_api/
python manage.py makemigrations
python manage.py migrate
coverage run manage.py test --noinput --parallel 16
coverage report > results.txt
# Modifying coverage report
echo "Coverage Report: " > report.txt
echo " Statements | Miss | Cover " >> report.txt
tail -4 results.txt >> report.txt
echo " " >> report.txt
echo "Link to full report :" >> report.txt
# uploading report to file.io any other services can be used
curl -F "[email protected]" https://file.io | python3 -c "import sys, json; print(json.load(sys.stdin)['link'])" >> report.txt
env:
SECRET_KEY: ${{ secrets.SECRET_KEY }}
ADMIN_URL_KEY: ${{ secrets.ADMIN_URL_KEY }}
DATABASE_NAME: github_actions
DATABASE_USER: postgres
DATABASE_PASSWORD: postgres
DATABASE_HOST: 127.0.0.1
DATABASE_PORT: 5432
- uses: actions/upload-artifact@v2
with:
name: report
path: data_api/report.txt
- uses: actions/download-artifact@v2
with:
name: report
- name: Open Coverage Notifier Action
uses: Bearbobs/open-coverage-action@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
path: data_api/report.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment