|
| 1 | +name: MSSQL - Automated CI testing |
| 2 | +# This workflow run automatically for every commit on github it checks the syntax and launch the tests. |
| 3 | +# | grep . | uniq -c filters out empty lines and then groups consecutive lines together with the number of occurrences |
| 4 | +on: |
| 5 | + pull_request: |
| 6 | + workflow_dispatch: |
| 7 | + inputs: |
| 8 | + comment: |
| 9 | + description: Just a simple comment to know the purpose of the manual build |
| 10 | + required: false |
| 11 | + |
| 12 | +jobs: |
| 13 | + run_test: |
| 14 | + runs-on: ubuntu-20.04 |
| 15 | + services: |
| 16 | + mssql: |
| 17 | + image: mcr.microsoft.com/mssql/server:2017-latest |
| 18 | + env: |
| 19 | + ACCEPT_EULA: Y |
| 20 | + SA_PASSWORD: GitHub999 |
| 21 | + ports: |
| 22 | + - 1433:1433 |
| 23 | + # needed because the mssql container does not provide a health check |
| 24 | + options: --health-interval=10s --health-timeout=3s --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" |
| 25 | + |
| 26 | + steps: |
| 27 | + - name: Set up Python 3.8 |
| 28 | + uses: actions/setup-python@v2 |
| 29 | + with: |
| 30 | + python-version: 3.8 |
| 31 | + - name: install linux packages |
| 32 | + run: | |
| 33 | + wget https://raw.githubusercontent.com/openimis/database_ms_sqlserver/main/Empty%20databases/openIMIS_ONLINE.sql -O openIMIS_ONLINE.sql |
| 34 | + wget https://raw.githubusercontent.com/openimis/database_ms_sqlserver/main/Demo%20database/openIMIS_demo_ONLINE.sql -O openIMIS_demo_ONLINE.sql |
| 35 | + curl https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add - |
| 36 | + curl https://packages.microsoft.com/config/ubuntu/20.04/prod.list | sudo tee /etc/apt/sources.list.d/msprod.list |
| 37 | + sudo apt-get update |
| 38 | + sudo ACCEPT_EULA=Y apt-get install -y mssql-tools build-essential dialog apt-utils unixodbc-dev -y |
| 39 | + python -m pip install --upgrade pip |
| 40 | + - name: pull openimis backend |
| 41 | + run: | |
| 42 | + rm ./openimis -rf |
| 43 | + git clone --depth 1 --branch develop https://github.com/openimis/openimis-be_py.git ./openimis |
| 44 | + - name: copy current branch |
| 45 | + uses: actions/checkout@v2 |
| 46 | + with: |
| 47 | + path: './current-module' |
| 48 | + - name: Update the configuration |
| 49 | + working-directory: ./openimis |
| 50 | + run: | |
| 51 | + export MODULE_NAME="$(echo $GITHUB_REPOSITORY | sed 's#^openimis/openimis-be-\(.*\)_py$#\1#')" |
| 52 | + echo "the local module called $MODULE_NAME will be injected in openIMIS .json" |
| 53 | + jq --arg name "$MODULE_NAME" 'if [.modules[].name == ($name)]| max then (.modules[] | select(.name == ($name)) | .pip)|="../current-module" else .modules |= .+ [{name:($name), pip:"../current-module"}] end' openimis.json |
| 54 | + echo $(jq --arg name "$MODULE_NAME" 'if [.modules[].name == ($name)]| max then (.modules[] | select(.name == ($name)) | .pip)|="../current-module" else .modules |= .+ [{name:($name), pip:"../current-module"}] end' openimis.json) > openimis.json |
| 55 | + - name: Install openIMIS Python dependencies |
| 56 | + working-directory: ./openimis |
| 57 | + run: | |
| 58 | + pip install -r requirements.txt |
| 59 | + python modules-requirements.py openimis.json > modules-requirements.txt |
| 60 | + cat modules-requirements.txt |
| 61 | + pip install -r modules-requirements.txt |
| 62 | + - name: Environment info |
| 63 | + working-directory: ./openimis |
| 64 | + run: | |
| 65 | + pip list |
| 66 | + - name: Initialize DB |
| 67 | + run: | |
| 68 | + /opt/mssql-tools/bin/sqlcmd -S localhost,1433 -U SA -P $SA_PASSWORD -Q 'DROP DATABASE IF EXISTS imis' |
| 69 | + /opt/mssql-tools/bin/sqlcmd -S localhost,1433 -U SA -P $SA_PASSWORD -Q 'CREATE DATABASE imis' |
| 70 | + /opt/mssql-tools/bin/sqlcmd -S localhost,1433 -U SA -P $SA_PASSWORD -d imis -i openIMIS_ONLINE.sql | grep . | uniq -c |
| 71 | + /opt/mssql-tools/bin/sqlcmd -S localhost,1433 -U SA -P $SA_PASSWORD -d imis -i openIMIS_demo_ONLINE.sql | grep . | uniq -c |
| 72 | + env: |
| 73 | + SA_PASSWORD: GitHub999 |
| 74 | + ACCEPT_EULA: Y |
| 75 | + |
| 76 | +# - name: Check formatting with black |
| 77 | +# run: | |
| 78 | +# black --check . |
| 79 | + |
| 80 | + - name: Django tests |
| 81 | + working-directory: ./openimis/openIMIS |
| 82 | + run: | |
| 83 | + export MODULE_NAME="$(echo $GITHUB_REPOSITORY | sed 's#^openimis/openimis-be-\(.*\)_py$#\1#')" |
| 84 | + python -V |
| 85 | + ls -l |
| 86 | + python manage.py migrate |
| 87 | + python init_test_db.py | grep . | uniq -c |
| 88 | + python manage.py test --keepdb $MODULE_NAME |
| 89 | + env: |
| 90 | + SECRET_KEY: secret |
| 91 | + DEBUG: true |
| 92 | + #DJANGO_SETTINGS_MODULE: hat.settings |
| 93 | + DB_HOST: localhost |
| 94 | + DB_PORT: 1433 |
| 95 | + DB_NAME: imis |
| 96 | + DB_USER: sa |
| 97 | + DB_PASSWORD: GitHub999 |
| 98 | + #DEV_SERVER: true |
| 99 | + SITE_ROOT: api |
| 100 | + REMOTE_USER_AUTHENTICATION: True |
0 commit comments