Skip to content

Commit

Permalink
ci: Use github actions for CI
Browse files Browse the repository at this point in the history
  • Loading branch information
last-partizan authored Sep 18, 2021
1 parent 67f99f7 commit e3c5213
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 55 deletions.
83 changes: 83 additions & 0 deletions .github/workflows/github-actions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# Docs:
# - https://docs.github.com/en/actions/guides/about-service-containers
# Example
# - https://github.com/actions/example-services/blob/main/.github/workflows/postgres-service.yml
name: CI
on: [push]
jobs:
Lint:
runs-on: ubuntu-latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
strategy:
matrix:
python: [3.9]
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python }}
- name: Install flake8
run: |
python -m pip install --upgrade pip
pip install flake8
- name: Lint with flake8
run: |
flake8 modeltranslation
Test:
runs-on: ubuntu-latest
strategy:
matrix:
python: [3.6, 3.7, 3.8, 3.9]
django: [2.2, 3.0, 3.2]
database: ["sqlite", "postgres", "mysql"]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
DJANGO: ${{ matrix.django }}
DB: ${{ matrix.database }}
DB_HOST: 127.0.0.1
MYSQL_DATABASE: "modeltranslation"
MYSQL_USER: "root"
MYSQL_PASSWORD: "password"
POSTGRES_DB: "modeltranslation"
POSTGRES_USER: "modeltranslation"
POSTGRES_PASSWORD: "modeltranslation"
services:
mariadb:
image: mariadb
ports:
- 3306:3306
env:
MYSQL_DATABASE: "modeltranslation"
MYSQL_USER: "modeltranslation"
MYSQL_PASSWORD: "password"
MYSQL_ROOT_PASSWORD: "password"
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
postgres:
image: postgres
ports:
- 5432:5432
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
env:
POSTGRES_DB: "modeltranslation"
POSTGRES_USER: "modeltranslation"
POSTGRES_PASSWORD: "modeltranslation"
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python }}
- name: Set up env
run: |
if [[ $DB == mysql ]]; then
pip install -q mysqlclient
fi
if [[ $DB == postgres ]]; then
pip install -q psycopg2-binary
fi
pip install Pillow coverage six $(./get-django-version.py ${{ matrix.django }})
- name: Run tests
run: |
coverage run --source=modeltranslation ./runtests.py
40 changes: 0 additions & 40 deletions .travis.yml

This file was deleted.

3 changes: 0 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ may they use translations or not, and you never have to touch the original
model class.


.. image:: http://img.shields.io/travis/deschler/django-modeltranslation/master.svg?style=flat-square
:target: https://travis-ci.org/deschler/django-modeltranslation

.. image:: http://img.shields.io/coveralls/deschler/django-modeltranslation.svg?style=flat-square
:target: https://coveralls.io/r/deschler/django-modeltranslation

Expand Down
3 changes: 0 additions & 3 deletions docs/modeltranslation/contribute.rst
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,6 @@ against our `Travis CI config`_, checking code against different databases,
Python and Django versions. This includes automatic tracking of test coverage
through `Coveralls`_.

.. image:: http://img.shields.io/travis/deschler/django-modeltranslation/master.png?style=flat
:target: https://travis-ci.org/deschler/django-modeltranslation

.. image:: http://img.shields.io/coveralls/deschler/django-modeltranslation.png?style=flat
:target: https://coveralls.io/r/deschler/django-modeltranslation

Expand Down
File renamed without changes.
5 changes: 1 addition & 4 deletions modeltranslation/decorators.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# -*- coding: utf-8 -*-


def register(model_or_iterable, **options):
"""
Registers the given model(s) with the given translation options.
Expand All @@ -19,7 +16,7 @@ class AuthorTranslation(TranslationOptions):

def wrapper(opts_class):
if not issubclass(opts_class, TranslationOptions):
raise ValueError('Wrapped class must subclass TranslationOptions.')
raise ValueError("Wrapped class must subclass TranslationOptions.")
translator.register(model_or_iterable, opts_class, **options)
return opts_class

Expand Down
15 changes: 10 additions & 5 deletions runtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,29 @@
def runtests(test_path='modeltranslation'):
if not settings.configured:
# Choose database for settings
test_db = os.getenv('DB', 'sqlite')
test_db_host = os.getenv('DB_HOST', 'localhost')
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': ':memory:'
}
}
test_db = os.environ.get('DB', 'sqlite')
if test_db == 'mysql':
DATABASES['default'].update({
'ENGINE': 'django.db.backends.mysql',
'NAME': 'modeltranslation',
'USER': 'root',
'NAME': os.getenv('MYSQL_DATABASE', 'modeltranslation'),
'USER': os.getenv('MYSQL_USER', 'root'),
'PASSWORD': os.getenv('MYSQL_PASSWORD', 'password'),
'HOST': test_db_host,
})
elif test_db == 'postgres':
DATABASES['default'].update({
'ENGINE': 'django.db.backends.postgresql',
'USER': 'postgres',
'NAME': 'modeltranslation',
'USER': os.getenv('POSTGRES_USER', 'postgres'),
'PASSWORD': os.getenv('POSTGRES_DB', 'postgres'),
'NAME': os.getenv('POSTGRES_DB', 'modeltranslation'),
'HOST': test_db_host,
})

# Configure test environment
Expand Down

0 comments on commit e3c5213

Please sign in to comment.