Skip to content

Commit

Permalink
OP-1524 Merged CI scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
malinowskikam committed Aug 24, 2023
1 parent 6407fd4 commit e0b9741
Show file tree
Hide file tree
Showing 4 changed files with 155 additions and 197 deletions.
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Database engine, should be changed for mssql
DB_ENGINE=django.db.backends.postgresql
# Database host
DB_HOST=<host>
# Database port
Expand Down
153 changes: 153 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
name: Automated CI testing
# This workflow run automatically for every commit on github it checks the syntax and launch the tests.
# | grep . | uniq -c filters out empty lines and then groups consecutive lines together with the number of occurrences
on:
push:
workflow_dispatch:
inputs:
comment:
description: Just a simple comment to know the purpose of the manual build
required: false

jobs:
ci:
runs-on: ubuntu-20.04

services:
mssql:
image: mcr.microsoft.com/mssql/server:2017-latest
env:
ACCEPT_EULA: Y
SA_PASSWORD: GitHub999
ports:
- 1433:1433
# this health-cmd needed because the mssql container does not provide a health check
options: >-
--health-interval=10s
--health-timeout=5s
--health-start-period=10s
--health-retries=10
--health-cmd="/opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P ${SA_PASSWORD} -Q 'SELECT 1' || exit 1"
pgsql:
image: postgres
env:
DB_HOST: localhost
DB_PORT: 5432
POSTGRES_DB: imis
POSTGRES_USER: postgres
POSTGRES_PASSWORD: GitHub999
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 10
steps:
- uses: actions/checkout@v2

- name: Set up Python 3.8
uses: actions/setup-python@v1
with:
python-version: 3.8

- name: Install Python dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
python modules-requirements.py openimis.json > modules-requirements.txt
pip install -r modules-requirements.txt
export MODULES=$(jq -r '(.modules[].name)' ../openimis.json | xargs)
echo $modules
- name: Environment info
run: |
pip list
export DBBRANCH="$([ $GITHUB_REF == 'main' ] && echo "main" || echo "develop")"
if [ ${GITHUB_REF##*/} = "develop" ]; then export DBBRANCH="main"; else export DBBRANCH="develop"; fi
echo "Branch ${GITHUB_REF##*/}, usign ${DBBRANCH} branch for database"
sudo apt-get update
sudo apt-get install jq
- name: Init PSQL
run: |
git clone --depth 1 --branch $DBBRANCH https://github.com/openimis/database_postgresql.git ./sql_psql
echo 'set search_path to public' >> ~/.psqlrc
PGPASSWORD=GitHub999 psql -U postgres -h localhost -d imis -U postgres -f ./sql_psql/database\ scripts/00_dump.sql | grep . | uniq -c
PGPASSWORD=GitHub999 psql -U postgres -h localhost -d imis -U postgres -f ./sql_psql/database\ scripts/02_aux_functions.sql | grep . | uniq -c
PGPASSWORD=GitHub999 psql -U postgres -h localhost -d imis -U postgres -f ./sql_psql/database\ scripts/03_views.sql | grep . | uniq -c
PGPASSWORD=GitHub999 psql -U postgres -h localhost -d imis -U postgres -f ./sql_psql/database\ scripts/04_functions.sql | grep . | uniq -c
PGPASSWORD=GitHub999 psql -U postgres -h localhost -d imis -U postgres -f ./sql_psql/database\ scripts/05_stored_procs.sql | grep . | uniq -c
PGPASSWORD=GitHub999 psql -U postgres -h localhost -d imis -U postgres -f ./sql_psql/database\ scripts/demo_db.sql | grep . | uniq -c
- name: Initialize MSSQL
run: |
git clone --depth 1 --branch $DBBRANCH https://github.com/openimis/database_ms_sqlserver.git ./sql_mssql
cd sql/ && bash concatenate_files.sh && cd ..
curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -
curl https://packages.microsoft.com/config/ubuntu/20.04/prod.list | sudo tee /etc/apt/sources.list.d/msprod.list
sudo apt-get update
sudo apt-get install mssql-tools unixodbc-dev
/opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P $SA_PASSWORD -Q 'DROP DATABASE IF EXISTS imis'
/opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P $SA_PASSWORD -Q 'CREATE DATABASE imis'
/opt/mssql-tools/bin/sqlcmd -S localhost,1433 -U SA -P $SA_PASSWORD -d imis -i ./sql_mssql/output/fullDemoDatabase.sql | grep . | uniq -c
python init_test_db.py | grep . | uniq -c
#We don't need to migrate the main database, `python manage.py test` migrates the test database
env:
SECRET_KEY: secret
DEBUG: true
#DJANGO_SETTINGS_MODULE: hat.settings
DB_HOST: localhost
DB_PORT: 1433
DB_NAME: imis
DB_USER: sa
DB_PASSWORD: GitHub999
#DEV_SERVER: true
SITE_ROOT: api
#REMOTE_USER_AUTHENTICATION: True

- name: Django tests PSQL
run: |
python -V
cd openIMIS
coverage run python manage.py test --keepdb $MODULES
coverage report
env:
SECRET_KEY: secret
DEBUG: true
DB_ENGINE: django.db.backends.postgresql
#DJANGO_SETTINGS_MODULE: hat.settings
DB_HOST: localhost
DB_PORT: 5432
DB_NAME: imis
DB_USER: postgres
DB_PASSWORD: GitHub999
#DEV_SERVER: true
SITE_ROOT: api

- name: Django tests MSSQL
run: |
python -V
cd openIMIS
coverage run manage.py test --keepdb $MODULES
coverage report
env:
SECRET_KEY: secret
DEBUG: true
#DJANGO_SETTINGS_MODULE: hat.settings
DB_HOST: localhost
DB_PORT: 1433
DB_NAME: imis
DB_USER: sa
DB_PASSWORD: GitHub999
#DEV_SERVER: true
SITE_ROOT: api
#REMOTE_USER_AUTHENTICATION: False
105 changes: 0 additions & 105 deletions .github/workflows/main.yml

This file was deleted.

92 changes: 0 additions & 92 deletions .github/workflows/pgsql.yml

This file was deleted.

0 comments on commit e0b9741

Please sign in to comment.