.github/workflows/backend-ci.yml
name: Back-end CI
on: push
jobs:
backend-ci:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./api
services:
db:
image: postgres:12
env:
POSTGRES_USER: myuser
POSTGRES_PASSWORD: password
POSTGRES_DB: myproject
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- uses: actions/checkout@v2
- name: Build backend image
run: docker build -t backend .
- name: Check code stylesheet based on setup.cfg with flake8
run: docker run backend flake8 .
- name: Run back-end tests
run: |
docker run\
--network="host"\
--env POSTGRES_HOST="localhost"\
--env POSTGRES_PORT="5432"\
--env POSTGRES_DB="myproject"\
--env POSTGRES_USER="myuser"\
--env POSTGRES_PASSWORD="password"\
--env DJANGO_KEY="django-insecure-sca_4i79@8^p7b4i3ggm!vz_&t7!+-omwh&8_q=lxbu%elp-o#"\
--env PORT="8000"\
--env DEBUG="1"\
--env ENVIRONMENT="development"\
--volume ${PWD}:/api\
backend sh -c\
"python3 manage.py makemigrations\
&& python3 manage.py migrate\
&& coverage run manage.py test\
&& coverage report\
&& coverage xml"
- name: Publish tests to Code Climate
run: |
curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
chmod +x cc-test-reporter
./cc-test-reporter format-coverage -t coverage.py coverage.xml
./cc-test-reporter upload-coverage
env:
CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}