-
Notifications
You must be signed in to change notification settings - Fork 0
89 lines (86 loc) · 3.65 KB
/
django-test.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
name: CI Django + Postgres Tests
on:
# opening a pull request to master and develop branch will be a trigger
pull_request:
branches:
- develop
- master
# any code pushed to master and develop branch will also be a trigger
push:
branches:
- master
- develop
# three job definition
jobs:
health-check-job: # health check job for testing and code formatting check
runs-on: ubuntu-latest # os for running the job
services:
postgres: # we need a postgres docker image to be booted a side car service to run the tests that needs a db
image: postgres
env: # the environment variable must match with app/settings.py if block of DATBASES variable otherwise test will fail due to connectivity issue.
POSTGRES_USER: boardadmin
POSTGRES_PASSWORD: password
POSTGRES_DB: boardproject
ports:
- 5432:5432 # exposing 5432 port for application to use
# 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:
- name: Checkout code # checking our the code at current commit that triggers the workflow
uses: actions/checkout@v2
- name: Cache dependency # caching dependency will make our build faster.
uses: actions/cache@v2 # for more info checkout pip section documentation at https://github.com/actions/cache
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Setup python environment # setting python environment to 3.x
uses: actions/setup-python@v2
with:
python-version: '3.x' # if you want multiple python version run just use matrix strategy in job config. See the documentation of GitHub Actions
- name: Check Python version # checking the python version to see if 3.x is installed.
run: python --version
- name: Install requirements # install application requirements
run: pip install -r requirements.txt
# - name: Check Syntax # check code formatting
# run: pycodestyle --statistics .
- name: Run Migrations # run migrations to create table in side car db container
run: python manage.py migrate
- name: Run Test # running tests
run: python manage.py test
- name: publish
uses: pennsignals/[email protected]
with:
version: 'latest' # optional
docker_compose: 'docker-compose.yml' # required
repo_token: "${{ secrets.GITHUB_TOKEN }}"
# create-envfile:
# runs-on: ubuntu-latest
# steps:
# - name: Make envfile
# uses: SpicyPizza/[email protected]
# with:
# envkey_SECRET_KEY: ${{ secrets.SECRET_KEY }}
# envkey_DATABASE_NAME: boardproject
# envkey_DATABASE_USER: boardadmin
# envkey_DATABASE_PASSWORD: password
# envkey_DATABASE_HOST: db
# envkey_DATABASE_PORT: 5432
# envkey_ALLOWED_HOSTS: 127.0.0.1
# envkey_DATABASE: postgres
# envkey_DJANGO_SUPERUSER_PASSWORD: admin
# envkey_DJANGO_SUPERUSER_EMAIL: [email protected]
# envkey_DJANGO_SUPERUSER_USERNAME: admin
# directory: ./
# create-envfile-postgres:
# runs-on: ubuntu-latest
# steps:
# - name: Make envfile for postgres
# uses: SpicyPizza/[email protected]
# with:
# envkey_POSTGRES_USER: boardadmin
# envkey_POSTGRES_PASSWORD: password
# envkey_POSTGRES_DB: boardproject
# directory: ./
# file_name: .env.db