From 9670050ed11faf6831b957b38b12f842a2cdc26a Mon Sep 17 00:00:00 2001 From: Samweli Mwakisambwe Date: Sat, 5 Nov 2022 01:56:27 +0300 Subject: [PATCH] CI workflow for tests (#704) * added admin operations script and test workflow * decreased number of QGIS images to test against decreased number of QGIS images to test against * full confs for running tests in ci * added test suite added test suite added test suite added test suite added test suite * expand QGIS test images matrix added test suite added test suite added test suite * update info about the test action workflow * reformatted using black * use correct link when installing plugin into the test QGIS image * change docker compose version * include test_ci for checking tests runs before making a PR * update test image before running the tests update test image before running the tests update test image before running the tests update test image before running the tests update test image before running the tests update test image before running the tests update test image before running the tests update test image before running the tests * added comment about display issue workaround * removed admin.py its changes will be implemented in another PR --- .github/workflows/test.yaml | 66 +++++++++++++++++++++++++ docker-compose.yml | 29 +++++++---- docker/qgis-testing-entrypoint.sh | 16 ++++++ docker/trends-earth-test-pre-scripts.sh | 11 +++++ 4 files changed, 112 insertions(+), 10 deletions(-) create mode 100644 .github/workflows/test.yaml create mode 100755 docker/qgis-testing-entrypoint.sh create mode 100755 docker/trends-earth-test-pre-scripts.sh diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml new file mode 100644 index 000000000..15db9e48e --- /dev/null +++ b/.github/workflows/test.yaml @@ -0,0 +1,66 @@ +# Runs tests on QGIS 3.16, 3.22 LTR, 3.26 and master branch +name: Continous Integration + +on: + workflow_dispatch: + push: + branches: + - main + - test_ci + pull_request: + types: + - opened + - reopened + - synchronize + branches: + - main + +env: + # Global environment variable + IMAGE: qgis/qgis + WITH_PYTHON_PEP: "true" + MUTE_LOGS: "true" + +jobs: + test: + runs-on: ubuntu-latest + name: Running tests on QGIS ${{ matrix.qgis_version_tag }} + + strategy: + fail-fast: false + matrix: + qgis_version_tag: + - release-3_22 + - release-3_26 + - latest + + steps: + + - name: Checkout + uses: actions/checkout@v2 + with: + submodules: recursive + + - name: Preparing docker-compose environment + env: + QGIS_VERSION_TAG: ${{ matrix.qgis_version_tag }} + run: | + cat << EOF > .env + QGIS_VERSION_TAG=${QGIS_VERSION_TAG} + IMAGE=${IMAGE} + ON_TRAVIS=true + MUTE_LOGS=${MUTE_LOGS} + WITH_PYTHON_PEP=${WITH_PYTHON_PEP} + EOF + - name: Preparing test environment + run: | + cat .env + docker pull "${IMAGE}":${{ matrix.qgis_version_tag }} + docker-compose up -d + sleep 10 + + - name: Run test suite + run: | + docker-compose exec -T qgis-testing-environment sh -c "apt-get update" + docker-compose exec -T qgis-testing-environment sh -c "apt-get install -y python3-opencv" + docker-compose exec -T qgis-testing-environment qgis_testrunner.sh LDMP.test.testplugin diff --git a/docker-compose.yml b/docker-compose.yml index ae78f8153..df28f0bba 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,11 +1,20 @@ -version: '3' - +version: '2.1' services: - qgis: - volumes: - - ./:/tests_directory - environment: - DISPLAY: ':99' - build: - context: . - container_name: trendsearth_qgis_1 + qgis-testing-environment: + image: ${IMAGE}:${QGIS_VERSION_TAG} + volumes: + - ./:/tests_directory + environment: + QGIS_VERSION_TAG: "${QGIS_VERSION_TAG}" + WITH_PYTHON_PEP: "${WITH_PYTHON_PEP}" + ON_TRAVIS: "${ON_TRAVIS}" + MUTE_LOGS: "${MUTE_LOGS}" + DISPLAY: ":99" + working_dir: /tests_directory + entrypoint: /tests_directory/docker/qgis-testing-entrypoint.sh + # Enable "command:" line below to immediately run unittests upon docker-compose up + # command: qgis_testrunner.sh test_suite.test_package + # Default behaviour of the container is to standby + command: tail -f /dev/null + # qgis_testrunner.sh needs tty for tee + tty: true diff --git a/docker/qgis-testing-entrypoint.sh b/docker/qgis-testing-entrypoint.sh new file mode 100755 index 000000000..7a7987ae3 --- /dev/null +++ b/docker/qgis-testing-entrypoint.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env bash + +# Docker entrypoint file intended for docker-compose recipe for running unittests + +set -e + +source /tests_directory/docker/trends-earth-test-pre-scripts.sh + +# Run supervisor +# This is the default command of qgis/qgis but we will run it in background +supervisord -c /etc/supervisor/supervisord.conf & + +# Wait for XVFB +sleep 10 + +exec "$@" diff --git a/docker/trends-earth-test-pre-scripts.sh b/docker/trends-earth-test-pre-scripts.sh new file mode 100755 index 000000000..edf83e5f9 --- /dev/null +++ b/docker/trends-earth-test-pre-scripts.sh @@ -0,0 +1,11 @@ +#!/usr/bin/env bash + +qgis_setup.sh + +# FIX default installation because the sources must be in "trends.earth parent folder +rm -rf /root/.local/share/QGIS/QGIS3/profiles/default/python/plugins/trends.earth +ln -sf /tests_directory/LDMP /root/.local/share/QGIS/QGIS3/profiles/default/python/plugins/trends.earth +ln -sf /tests_directory/LDMP /usr/share/qgis/python/plugins/trends.earth + +pip3 install -r /tests_directory/requirements.txt +pip3 install -r /tests_directory/requirements-dev.txt