Skip to content

Commit

Permalink
add tests in GitHub actions
Browse files Browse the repository at this point in the history
  • Loading branch information
PetrDlouhy committed Nov 20, 2021
1 parent 6677d43 commit e7cf8ae
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 19 deletions.
89 changes: 89 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# This is a basic workflow to help you get started with Actions

name: CI

# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the master branch
push:
branches: [ master ]
pull_request:
branches: [ master ]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
tests:
# The type of runner that the job will run on
runs-on: ubuntu-latest

strategy:
matrix:
DJANGO_VERSION: [ '2.2.*', '3.0.*', '2.1.*', '3.2.*' ]
DB_ENGINE: [ 'postgres', 'mysql' ]

services:
postgres:
image: postgres
env:
POSTGRES_PASSWORD: postgres
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
mysql:
image: mysql:5.7
env:
MYSQL_DATABASE: test_db
MYSQL_USER: db_user
MYSQL_PASSWORD: mysql
MYSQL_ROOT_PASSWORD: rootpassword
options: >-
--health-cmd "mysqladmin ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 3306:3306

steps:
- uses: actions/checkout@v2

- uses: actions/cache@v2
with:
path: ~/.cache/pip
key: ${{ hashFiles('setup.py') }}-${{ hashFiles('demoproject/requirements.txt') }}-${{ hashFiles('requirements.txt') }}-${{ matrix.DJANGO_VERSION }}

- name: Install
run: |
pip install -q -e .
pip install -q --upgrade --upgrade-strategy eager -r demoproject/requirements.txt
pip install -q --upgrade --upgrade-strategy eager -r requirements.txt
pip install -q Django==${{ matrix.DJANGO_VERSION }}
pip install codecov
- name: Testing
run: |
if [ "$matrix.DB_ENGINE" = 'mysql' ]; then
mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u db_user -p mysql mysql
fi
export DB_ENGINE=${{ matrix.DB_ENGINE }}
coverage run setup.py test
coverage xml && codecov
env:
POSTGRES_HOST: localhost
POSTGRES_PORT: 5432
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install
run: pip install flake8
- name: Running Flake8
run: flake8
38 changes: 20 additions & 18 deletions demoproject/demoproject/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,20 @@
MANAGERS = ADMINS

if os.environ.get('DB_ENGINE') == 'mysql':
print("------------MySQL----------")
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'travis_ci',
'NAME': 'test_db',
'USER': os.environ.get('MYSQL_USER', 'root'),
'PASSWORD': os.environ.get('MYSQL_PASSWORD', 'password'),
'HOST': '127.0.0.1',
'HOST': 'localhost',
'PORT': 3306,
'TEST': {
'CHARSET': 'utf8',
'COLLATION': 'utf8_general_ci',
}
}
},
},
}
elif os.environ.get('DB_ENGINE') == 'sqlite':
if 'test' in sys.argv:
Expand All @@ -41,18 +42,19 @@
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': database_name,
}
},
}
else:
elif os.environ.get('DB_ENGINE') == 'postgres':
print("------------PostgreSQL----------")
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'travis_ci',
'NAME': os.environ.get('POSTGRES_NAME', 'postgres'),
'USER': os.environ.get('POSTGRES_USER', 'postgres'),
'PASSWORD': os.environ.get('POSTGRES_PASSWORD', ''),
'HOST': '',
'PORT': '',
}
'PASSWORD': os.environ.get('POSTGRES_PASSWORD', 'postgres'),
'HOST': os.environ.get('POSTGRES_HOST', ''),
'PORT': os.environ.get('POSTGRES_PORT', ''),
},
}


Expand Down Expand Up @@ -144,7 +146,7 @@
"django.template.context_processors.csrf",
"django.template.context_processors.tz",
"django.template.context_processors.request",
]
],
},
}]

Expand Down Expand Up @@ -209,7 +211,7 @@
except ImportError:
pass
else:
INSTALLED_APPS = INSTALLED_APPS + ['django_extensions', ]
INSTALLED_APPS = INSTALLED_APPS + ['django_extensions']

# A sample logging configuration. The only tangible logging
# performed by this configuration is to send an email to
Expand All @@ -221,23 +223,23 @@
'disable_existing_loggers': False,
'filters': {
'require_debug_false': {
'()': 'django.utils.log.RequireDebugFalse'
}
'()': 'django.utils.log.RequireDebugFalse',
},
},
'handlers': {
'mail_admins': {
'level': 'ERROR',
'filters': ['require_debug_false'],
'class': 'django.utils.log.AdminEmailHandler'
}
'class': 'django.utils.log.AdminEmailHandler',
},
},
'loggers': {
'django.request': {
'handlers': ['mail_admins'],
'level': 'ERROR',
'propagate': True,
},
}
},
}


Expand Down
3 changes: 2 additions & 1 deletion demoproject/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ django-nvd3
django-bower
django-admin-tools
model-mommy
psycopg2
psycopg2==2.8.6
mysqlclient
django-coverage-plugin

0 comments on commit e7cf8ae

Please sign in to comment.