Skip to content

Commit

Permalink
Adding github actions (#154)
Browse files Browse the repository at this point in the history
  • Loading branch information
shosca committed Nov 20, 2020
1 parent a10ce28 commit ae85764
Show file tree
Hide file tree
Showing 13 changed files with 166 additions and 78 deletions.
68 changes: 68 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: Build

on:
push:
branches:
- master

pull_request:

jobs:
build:

runs-on: ubuntu-latest
services:
postgres:
image: postgres
ports:
- "5432:5432"
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: test

strategy:
matrix:
container:
- image: python:3.6
toxenv: py36
- image: python:3.7
toxenv: py37
- image: python:3.8
toxenv: py38
- image: python:3.9
toxenv: py39

container:
image: ${{ matrix.container.image }}

steps:
- uses: actions/checkout@v1
- name: Install dependencies
run: |
apt-get update
apt-get install -y postgresql-client
pip install -r requirements.txt
- name: Tox
run: |
tox -f ${{ matrix.container.toxenv }}
env:
DATABASE_URL: postgresql://postgres:postgres@postgres
- name: Upload Coverage
run: coveralls
env:
GITHUB_TOKEN: ${{ secrets.github_token }}
COVERALLS_FLAG_NAME: ${{ matrix.container.image }}
COVERALLS_PARALLEL: true

finish:
needs: build
runs-on: ubuntu-latest
container: python:3-slim
steps:
- name: Coveralls Finished
run: |
pip3 install -U coveralls
coveralls --finish
env:
GITHUB_TOKEN: ${{ secrets.github_token }}
10 changes: 5 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ repos:
language_version: python3

- repo: https://github.com/psf/black
rev: 19.10b0
rev: 20.8b1
hooks:
- id: black
language_version: python3

- repo: https://github.com/asottile/pyupgrade
rev: v2.7.2
rev: v2.7.3
hooks:
- id: pyupgrade
args: [--py3-plus]
Expand All @@ -25,7 +25,7 @@ repos:
- id: docformatter

- repo: https://gitlab.com/pycqa/flake8
rev: 3.8.3
rev: 3.8.4
hooks:
- id: flake8
exclude: deployment/roles
Expand All @@ -36,12 +36,12 @@ repos:
- flake8-debugger

- repo: https://github.com/mgedmin/check-manifest
rev: '0.42'
rev: '0.45'
hooks:
- id: check-manifest

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.2.0
rev: v3.3.0
hooks:
- id: check-added-large-files
- id: check-builtin-literals
Expand Down
26 changes: 0 additions & 26 deletions .travis.yml

This file was deleted.

1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
include *.rc
include *.editorconfig
include *.rst
include *.sh
include *.toml
include *.txt
include *.yaml *.yml
Expand Down
9 changes: 4 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ DBS=\
minimal_backpop
RESETDBS=$(addsuffix -resetdb,$(DBS))
COVERAGE_FLAGS?=--cov-report term-missing --cov-fail-under=100
DATBASE_URL?=postgresql://postgres:postgres@localhost

.PHONY: help list docs $(FILES)

Expand Down Expand Up @@ -39,15 +40,13 @@ clean-test: ## remove test and coverage artifacts
rm -rf .tox .coverage htmlcov

%-resetdb:
-psql postgresql://postgres:postgres@localhost -c "drop database $*;"
-psql postgresql://postgres:postgres@localhost -c "create database $*;"
-psql $(DATABASE_URL) -c "drop database $*;"
-psql $(DATABASE_URL) -c "create database $*;"

resetdb: $(RESETDBS)

lint: ## run pre-commit hooks on all files
if python -c "import sys; exit(1) if sys.version_info.major < 3 else exit(0)"; then \
pre-commit run --all-files ; \
fi
pre-commit run --all-files

coverage: ## check code coverage quickly with the default Python
py.test $(PYTEST_OPTS) \
Expand Down
30 changes: 29 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: '2.1'
version: '3.7'

services:
pg:
Expand All @@ -9,3 +9,31 @@ services:
- "5432:5432"
environment:
- POSTGRES_PASSWORD=postgres

py36: &base
image: python:3.6
depends_on:
- pg
environment:
- DATABASE_URL=postgresql://postgres:postgres@pg
working_dir: /code
entrypoint: /code/entrypoint.sh
volumes:
- .:/code
- /tmp:/root/.cache

py37:
image: python:3.7
<<: *base

py38:
image: python:3.8
<<: *base

py39:
image: python:3.9
<<: *base

pypy36:
image: pypy:3.6
<<: *base
6 changes: 6 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

apt update && apt install -y postgresql-client
pip install -r requirements.txt

exec "$@"
10 changes: 6 additions & 4 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
-e .
Sphinx
attrs
beautifulsoup4
coveralls
coverage
coveralls
django-extensions
flake8
flake8-bugbear
flake8-comprehensions
flake8-django
gitchangelog
mock; python_version <= '2.7'
ipython
pdbpp
pre_commit
psycopg2cffi
Expand All @@ -18,5 +20,5 @@ sphinx-autobuild
sphinx_rtd_theme
sqlalchemy_utils
tox
tox-factor
tox-pyenv
yapf
4 changes: 3 additions & 1 deletion tests/db/test_query.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from django.conf import settings
from django_sorcery.db.query import QueryProperty

from ..base import TestCase
Expand Down Expand Up @@ -121,7 +122,8 @@ def test_bad_attr(self):
self.assertEqual(
ctx.exception.args,
(
"<QueryProperty db=<SQLAlchemy engine=postgresql://postgres:***@localhost/test>, model='Vehicle'> "
f"<QueryProperty db=<SQLAlchemy engine=postgresql://postgres:***@{settings.DB_URL.host}/test>, "
"model='Vehicle'> "
"object has no attribute 'dummy'",
),
)
Expand Down
3 changes: 2 additions & 1 deletion tests/db/test_sqlalchemy.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import sqlalchemy as sa
from django.conf import settings
from django_sorcery.db.query import Operation
from django_sorcery.utils import suppress

Expand Down Expand Up @@ -37,7 +38,7 @@ def test_url(self):
self.assertEqual(db.bind.url, db.url)

def test_repr(self):
self.assertEqual(repr(db), "<SQLAlchemy engine=postgresql://postgres:***@localhost/test>")
self.assertEqual(repr(db), f"<SQLAlchemy engine=postgresql://postgres:***@{settings.DB_URL.host}/test>")

def test_queryproperty(self):
qp = db.queryproperty(ModelOne)
Expand Down
5 changes: 3 additions & 2 deletions tests/management/commands/test_sorcery_current.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import six

from django.conf import settings
from django.test import TestCase
from django_sorcery.db import databases
from django_sorcery.management.commands.sorcery_current import Command
Expand Down Expand Up @@ -109,7 +110,7 @@ def test_verbose(self):
out.readlines(),
[
"Revision for tests.testapp on database test\n",
"Current revision(s) for postgresql://postgres:***@localhost/test\n",
f"Current revision(s) for postgresql://postgres:***@{settings.DB_URL.host}/test\n",
"Rev: 000000000001 (head)\n",
"Parent: 000000000000\n",
"Path: {}/000000000001_.py\n".format(MIGRATION_DIR),
Expand All @@ -120,6 +121,6 @@ def test_verbose(self):
" Revises: 000000000000\n",
" Create Date: 2018-07-24 02:02:55.504526\n",
"Revision for tests.otherapp on database test\n",
"Current revision(s) for postgresql://postgres:***@localhost/test\n",
f"Current revision(s) for postgresql://postgres:***@{settings.DB_URL.host}/test\n",
],
)
46 changes: 25 additions & 21 deletions tests/settings.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import os

from sqlalchemy.engine.url import make_url


def absjoin(*args):
return os.path.normpath(os.path.abspath(os.path.join(*args)))
Expand All @@ -11,21 +13,23 @@ def absjoin(*args):
PROJECT_ROOT = os.path.dirname(absjoin(__file__))
STATIC_ROOT = absjoin(PROJECT_ROOT, "..", "static")

DB_URL = make_url(os.environ.get("DATABASE_URL", "postgresql://postgres:postgres@localhost"))

DATABASES = {
"default": {
"ENGINE": "django.db.backends.postgresql",
"NAME": "default_db",
"USER": "postgres",
"PASSWORD": "postgres",
"HOST": "localhost",
"USER": DB_URL.username,
"PASSWORD": DB_URL.password,
"HOST": DB_URL.host,
"PORT": "",
},
"fromdbs": {
"ENGINE": "django.db.backends.postgresql",
"NAME": "fromdbs",
"USER": "postgres",
"PASSWORD": "postgres",
"HOST": "localhost",
"USER": DB_URL.username,
"PASSWORD": DB_URL.password,
"HOST": DB_URL.host,
"PORT": "",
},
}
Expand All @@ -34,41 +38,41 @@ def absjoin(*args):
"default": {
"DIALECT": "postgresql",
"NAME": "default_db",
"USER": "postgres",
"PASSWORD": "postgres",
"HOST": "localhost",
"USER": DB_URL.username,
"PASSWORD": DB_URL.password,
"HOST": DB_URL.host,
"PORT": "",
},
"test": {
"DIALECT": "postgresql",
"NAME": "test",
"USER": "postgres",
"PASSWORD": "postgres",
"HOST": "localhost",
"USER": DB_URL.username,
"PASSWORD": DB_URL.password,
"HOST": DB_URL.host,
"PORT": "",
},
"minimal": {
"DIALECT": "postgresql",
"NAME": "minimal",
"USER": "postgres",
"PASSWORD": "postgres",
"HOST": "localhost",
"USER": DB_URL.username,
"PASSWORD": DB_URL.password,
"HOST": DB_URL.host,
"PORT": "",
},
"minimal_backpop": {
"DIALECT": "postgresql",
"NAME": "minimal_backpop",
"USER": "postgres",
"PASSWORD": "postgres",
"HOST": "localhost",
"USER": DB_URL.username,
"PASSWORD": DB_URL.password,
"HOST": DB_URL.host,
"PORT": "",
},
"terrible": {
"DIALECT": "postgresql",
"NAME": "minimal_backpop",
"USER": "postgres",
"PASSWORD": "postgres",
"HOST": "localhost",
"USER": DB_URL.username,
"PASSWORD": DB_URL.password,
"HOST": DB_URL.host,
"PORT": "",
},
}
Expand Down

0 comments on commit ae85764

Please sign in to comment.