Skip to content

Commit 415f365

Browse files
committed
update ci module to split module and full test
1 parent 5f22342 commit 415f365

File tree

1 file changed

+42
-13
lines changed

1 file changed

+42
-13
lines changed

.github/workflows/ci_module.yml

+42-13
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,11 @@ jobs:
7272
sudo apt-get install jq
7373
7474
export MODULE_NAME="$(echo $GITHUB_REPOSITORY | sed 's#^openimis/openimis-be-\(.*\)_py$#\1#')"
75-
7675
echo "MODULE_NAME=$MODULE_NAME" >> $GITHUB_ENV
76+
export MODULES=$(jq -r '(.modules[].name)' ./openimis.json | xargs)
77+
# Remove some module from MODULES
78+
MODULES=$(echo "$MODULES" | sed -E "s/\b$(echo "${CI_EXCLUDED_MODULE// /\\b|\\b}")\b/ /g" | xargs)
79+
echo "MODULES=$MODULES" >> $GITHUB_ENV
7780
7881
# Add or replace MODULE_NAME module in openimis.json (local version)
7982
echo $(jq --arg name "$MODULE_NAME" 'if [.modules[].name == ($name)]| max then (.modules[] | select(.name == ($name)) | .pip)|="-e ../current-module" else .modules |= .+ [{name:($name), pip:"../current-module"}] end' openimis.json) > openimis.json
@@ -145,10 +148,13 @@ jobs:
145148
name: site-packages
146149
path: /tmp/
147150

151+
148152
- name: Locate site-packages
149153
run: |
150154
SITE_PACKAGES=$(python -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())")
151155
echo "SITE_PACKAGES=$SITE_PACKAGES" >> $GITHUB_ENV
156+
export MODULE_NAME="$(echo $GITHUB_REPOSITORY | sed 's#^openimis/openimis-be-\(.*\)_py$#\1#')"
157+
echo "MODULE_NAME=$MODULE_NAME" >> $GITHUB_ENV
152158
153159
- name: Download site-packages artifact
154160
uses: actions/download-artifact@v2
@@ -202,10 +208,7 @@ jobs:
202208
if: success() || failure()
203209
run: |
204210
python -V
205-
export MODULES=$(jq -r '(.modules[].name)' ../openimis.json | xargs)
206-
MODULES=$(echo "$MODULES" | sed -E "s/\b$(echo "${CI_EXCLUDED_MODULE// /\\b|\\b}")\b/ /g" | xargs)
207-
echo $MODULES
208-
python manage.py test --debug-mode --timing --keepdb $MODULES
211+
python manage.py test --debug-mode --timing --keepdb $MODULE_NAME
209212
env:
210213
SECRET_KEY: secret
211214
MODE: DEV
@@ -256,6 +259,8 @@ jobs:
256259
run: |
257260
SITE_PACKAGES=$(python -c "from distutils.sysconfig import get_python_lib; print(get_python_lib())")
258261
echo "SITE_PACKAGES=$SITE_PACKAGES" >> $GITHUB_ENV
262+
export MODULE_NAME="$(echo $GITHUB_REPOSITORY | sed 's#^openimis/openimis-be-\(.*\)_py$#\1#')"
263+
echo "MODULE_NAME=$MODULE_NAME" >> $GITHUB_ENV
259264
260265
- name: Download site-packages artifact
261266
uses: actions/download-artifact@v2
@@ -294,20 +299,37 @@ jobs:
294299
DB_PASSWORD: GitHub999
295300
- name: Django tests PSQL
296301
working-directory: ./openimis/openIMIS
302+
id: django-test-psql
297303
# Run the tests regardless if previous steps failed (if setup fails the tests should crash instantly)
298304
if: success() || failure()
299305
run: |
300306
python -V
307+
# This has to exit 0, or report is not generated
308+
python -m coverage run --source=$MODULE_NAME --omit=*/migrations/* ./manage.py test --keepdb $MODULE_NAME
309+
env:
310+
SECRET_KEY: secret
311+
MODE: DEV
312+
DB_ENGINE: django.db.backends.postgresql
313+
#DJANGO_SETTINGS_MODULE: hat.settings
314+
DB_HOST: localhost
315+
DB_PORT: 5432
316+
DB_NAME: imis
317+
DB_USER: postgres
318+
DB_PASSWORD: GitHub999
319+
#DEV_SERVER: true
320+
SITE_ROOT: api
321+
CI_EXCLUDED_MODULE: ${{ vars.CI_EXCLUDED_MODULE }}
322+
- name: Django full PSQL
323+
working-directory: ./openimis/openIMIS
324+
id: django-full-psql
325+
# Run the tests regardless if previous steps failed (if setup fails the tests should crash instantly)
326+
run: |
301327
export MODULES=$(jq -r '(.modules[].name)' ../openimis.json | xargs)
302-
303328
# Remove some module from MODULES
304329
MODULES=$(echo "$MODULES" | sed -E "s/\b$(echo "${CI_EXCLUDED_MODULE// /\\b|\\b}")\b/ /g" | xargs)
305-
echo $MODULES
306-
# Generate sonar report
307-
export MODULE_NAME="$(echo $GITHUB_REPOSITORY | sed 's#^openimis/openimis-be-\(.*\)_py$#\1#')"
308-
309-
# This has to exit 0, or report is not generated
310-
python -m coverage run --source=$MODULE_NAME --omit=*/migrations/* ./manage.py test --keepdb $MODULES
330+
echo "MODULES=$MODULES" >> $GITHUB_ENV
331+
python manage.py test --debug-mode --timing --keepdb $MODULES
332+
continue-on-error: true
311333
env:
312334
SECRET_KEY: secret
313335
MODE: DEV
@@ -321,6 +343,14 @@ jobs:
321343
#DEV_SERVER: true
322344
SITE_ROOT: api
323345
CI_EXCLUDED_MODULE: ${{ vars.CI_EXCLUDED_MODULE }}
346+
# Check if the full test failed but not the PSQL
347+
- name: Set warning status if full test step failed
348+
id: check-status
349+
run: echo "status=${{ steps.django-full-psql.outcome == 'failure' && steps.django-test-psql.outcome == 'success' }}" >> $GITHUB_OUTPUT
350+
# Print a warning message if the previous step failed
351+
- name: Print warning
352+
if: steps.check-status.outputs.status == 'true'
353+
run: echo "::warning::Global test failed, check if it is not because of your changes"
324354
- name: Generate Coverage Report
325355
if: always()
326356
working-directory: ./openimis/openIMIS
@@ -376,7 +406,6 @@ jobs:
376406
if: success() || failure()
377407
run: |
378408
# Flake8 Report
379-
export MODULE_NAME="$(echo $GITHUB_REPOSITORY | sed 's#^openimis/openimis-be-\(.*\)_py$#\1#')"
380409
MOD_DIR="../current-module/$MODULE_NAME"
381410
python -m flake8 --output-file=flake8-report.txt $MOD_DIR --exit-zero
382411
sed -i 's|\.\./current-module/||g' flake8-report.txt

0 commit comments

Comments
 (0)