Utility CLI for DLite Entities Service #126
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: CI - Tests | |
on: | |
pull_request: | |
push: | |
branches: | |
- 'main' | |
- 'push-action/**' # Allow pushing to protected branches (using CasperWA/push-protected) | |
jobs: | |
basic-tests: | |
name: External | |
uses: SINTEF/ci-cd/.github/workflows/[email protected] | |
with: | |
# General setup | |
install_extras: "[dev]" | |
# pre-commit | |
python_version_pre-commit: "3.10" | |
skip_pre-commit_hooks: pylint,pylint-tests | |
# pylint & safety | |
python_version_pylint_safety: "3.10" | |
pylint_runs: | | |
--rcfile=pyproject.toml --extension-pkg-whitelist='pydantic' dlite_entities_service | |
--rcfile=pyproject.toml --disable=import-outside-toplevel,redefined-outer-name --recursive=yes tests | |
# Build dist | |
python_version_package: "3.10" | |
build_libs: flit | |
build_cmd: flit build | |
# Build documentation | |
run_build_docs: false | |
docker: | |
name: Docker | |
runs-on: ubuntu-latest | |
strategy: | |
fail-fast: false | |
matrix: | |
docker_target: ["development", "production"] | |
services: | |
mongo: | |
image: mongo:6 | |
ports: | |
- "27017:27017" | |
env: | |
MONGO_INITDB_ROOT_USERNAME: root | |
MONGO_INITDB_ROOT_PASSWORD: root | |
env: | |
entity_service_mongo_uri: mongodb://localhost:27017 | |
entity_service_mongo_user: root | |
entity_service_mongo_password: root | |
DOCKER_TEST_PORT: 8000 | |
steps: | |
- name: Checkout ${{ github.repository }} | |
uses: actions/checkout@v4 | |
- name: Setup Python 3.10 | |
uses: actions/setup-python@v4 | |
with: | |
python-version: "3.10" | |
- name: Build Docker image | |
run: docker build --pull -t entity-service --target ${{ matrix.docker_target }} . | |
- name: Run Docker container | |
run: | | |
docker run --rm -d \ | |
--env entity_service_mongo_uri \ | |
--env entity_service_mongo_user \ | |
--env entity_service_mongo_password \ | |
--env PORT=${DOCKER_TEST_PORT} \ | |
--name "entity-service" \ | |
--network "host" \ | |
--volume "${PWD}:/app" \ | |
entity-service | |
sleep 5 | |
- name: Install test dependencies | |
run: | | |
python -m pip install -U pip | |
pip install -U setuptools wheel flit | |
pip install -U -r .github/utils/requirements_docker_test.txt | |
pip install -U -e . | |
- name: Fill MongoDB with test data | |
run: ./.github/utils/docker_test.py add-testdata | |
- name: Run tests | |
env: | |
DOCKER_TEST_HOST: localhost | |
run: | | |
{ | |
./.github/utils/docker_test.py run-tests && | |
cat logs/dlite_entities_service.log | |
} || { | |
echo "Failed! Here's the Docker logs for the service:" && | |
docker logs entity-service && | |
echo -e "\nAnd the service log:" && | |
cat logs/dlite_entities_service.log && | |
exit 1 | |
} | |
pytest: | |
name: pytest | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout ${{ github.repository }} | |
uses: actions/checkout@v3 | |
- name: Setup Python 3.10 | |
uses: actions/setup-python@v4 | |
with: | |
python-version: "3.10" | |
- name: Install test dependencies | |
run: | | |
python -m pip install -U pip | |
pip install -U setuptools wheel flit | |
pip install -U -e .[testing,cli] | |
- name: Run tests | |
run: pytest -vvv --cov-report=xml | |
- name: Upload coverage to Codecov | |
uses: codecov/codecov-action@v3 | |
with: | |
files: coverage.xml |