New POST
create entity endpoint - also authentication
#231
Workflow file for this run
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" | |
# pylint & safety | |
python_version_pylint_safety: "3.10" | |
run_pylint: false | |
# 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:7 | |
ports: | |
- "27017:27017" | |
env: | |
MONGO_INITDB_ROOT_USERNAME: root | |
MONGO_INITDB_ROOT_PASSWORD: root | |
env: | |
# "Regular" entities service configuration values | |
ENTITY_SERVICE_MONGO_URI: mongodb://localhost:27017 | |
ENTITY_SERVICE_ADMIN_USER: "root" # should be the same as MONGO_INITDB_ROOT_USERNAME above | |
ENTITY_SERVICE_ADMIN_PASSWORD: "root" # should be the same as MONGO_INITDB_ROOT_PASSWORD above | |
ENTITY_SERVICE_ADMIN_DB: admin | |
# These are used in the Dockerfile as well as in pytest | |
ENTITY_SERVICE_HOST: localhost | |
ENTITY_SERVICE_PORT: 8000 | |
steps: | |
- name: Checkout ${{ github.repository }} | |
uses: actions/checkout@v4 | |
- name: Setup Python 3.10 | |
uses: actions/setup-python@v5 | |
with: | |
python-version: "3.10" | |
- name: Create test SSL key | |
run: echo "ENTITY_SERVICE_PRIVATE_SSL_KEY=$(openssl rand -hex 32)" >> $GITHUB_ENV | |
- name: Build Docker image | |
run: | | |
docker build \ | |
--pull \ | |
--tag entity-service \ | |
--target ${{ matrix.docker_target }} \ | |
. | |
- name: Install test dependencies | |
run: | | |
python -m pip install -U pip | |
pip install -U setuptools wheel flit | |
pip install -U -e .[testing] | |
- name: Run Docker container | |
run: | | |
docker run --rm -d \ | |
--env ENTITY_SERVICE_MONGO_URI \ | |
--env ENTITY_SERVICE_ADMIN_USER \ | |
--env ENTITY_SERVICE_ADMIN_PASSWORD \ | |
--env ENTITY_SERVICE_ADMIN_DB \ | |
--env ENTITY_SERVICE_PRIVATE_SSL_KEY \ | |
--env PORT=${ENTITY_SERVICE_PORT} \ | |
--env RUN_TIME=40 \ | |
--env STOP_TIME=3 \ | |
--name "entity-service" \ | |
--network "host" \ | |
--volume "${PWD}:/app" \ | |
--user "$(id -u):$(id -g)" \ | |
--entrypoint "./.github/utils/coverage_entrypoint.sh" \ | |
entity-service | |
sleep 5 # Wait for the service to start | |
- name: Run tests | |
run: | | |
{ | |
pytest -vv --live-backend --cov-report= | |
} || { | |
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 | |
} | |
- name: Collect coverage | |
run: | | |
# We have mapped the current working directory with the service's working | |
# directory in Docker. This means that we can, first of all, stop the service | |
# via a file touch, and then collect the coverage data from the service. | |
# | |
# See the .github/utils/coverage_entrypoint.sh file for more details on the | |
# stopping mechanism. | |
touch stop_gunicorn | |
sleep 3 # Wait for the service to stop | |
mv .coverage .coverage.pytest | |
coverage combine --data-file=.coverage.final --rcfile=pyproject.toml .coverage.pytest .coverage.docker | |
coverage xml --data-file=.coverage.final --rcfile=pyproject.toml -o coverage.xml | |
coverage report --data-file=.coverage.final --rcfile=pyproject.toml --show-missing --skip-covered --skip-empty | |
- name: Upload coverage | |
if: github.repository_owner == 'SINTEF' | |
uses: codecov/codecov-action@v3 | |
with: | |
files: coverage.xml | |
fail_ci_if_error: true | |
env_vars: OS,PYTHON | |
flags: docker | |
env: | |
OS: ubuntu-latest | |
PYTHON: '3.10' | |
pytest: | |
runs-on: ubuntu-latest | |
strategy: | |
fail-fast: false | |
matrix: | |
python_version: ["3.10", "3.11", "3.12"] | |
steps: | |
- name: Checkout ${{ github.repository }} | |
uses: actions/checkout@v4 | |
- name: Setup Python ${{ matrix.python_version }} | |
uses: actions/setup-python@v5 | |
with: | |
python-version: ${{ matrix.python_version }} | |
- name: Install test dependencies | |
run: | | |
python -m pip install -U pip | |
pip install -U setuptools wheel flit | |
pip install -U -e .[testing] | |
- name: Run pytest | |
run: pytest -vv --cov-report=xml | |
- name: Upload coverage | |
if: github.repository_owner == 'SINTEF' | |
uses: codecov/codecov-action@v3 | |
with: | |
fail_ci_if_error: true | |
env_vars: OS,PYTHON | |
flags: local | |
env: | |
OS: ubuntu-latest | |
PYTHON: ${{ matrix.python_version }} |