Skip to content

Prefer mongo_database value from mongo_uri if set in config #2898

Prefer mongo_database value from mongo_uri if set in config

Prefer mongo_database value from mongo_uri if set in config #2898

Workflow file for this run

name: CI tests
on:
pull_request:
push:
branches:
- main
- 'push-action/**'
env:
PYTEST_ADDOPTS: "--color=yes"
LINTING_PY_VERSION: "3.10" # The version of Python to use for linting (typically the minimum supported)
# Cancel running workflows when additional changes are pushed
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#example-using-a-fallback-value
concurrency:
group: ${{ github.head_ref || github.run_id }}
cancel-in-progress: true
jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: true
- name: Set up Python ${{ env.LINTING_PY_VERSION }}
uses: actions/setup-python@v5
with:
python-version: ${{ env.LINTING_PY_VERSION }}
cache: 'pip'
cache-dependency-path: |
requirements*.txt
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -U setuptools wheel
pip install -r requirements.txt -r requirements-server.txt -r requirements-dev.txt
pip install -e .
- name: Run pre-commit
run: pre-commit run --all-files || ( git status --short ; git diff ; exit 1 )
openapi:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: true
- name: Set up Python ${{ env.LINTING_PY_VERSION }}
uses: actions/setup-python@v5
with:
python-version: ${{ env.LINTING_PY_VERSION }}
cache: 'pip'
cache-dependency-path: |
requirements*.txt
- name: Install tools
run: |
python -m pip install --upgrade pip
pip install -U setuptools wheel
pip install -r requirements.txt -r requirements-server.txt -r requirements-dev.txt
pip install -e .
- name: Pass generated OpenAPI schemas through validator.swagger.io
run: |
invoke swagger-validator openapi/openapi.json
invoke swagger-validator openapi/index_openapi.json
- name: Check OpenAPI Schemas have not changed
run: invoke check-openapi-diff
docker-image:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: true
- name: Build the container image
run: docker build -f Dockerfile --build-arg CONFIG_FILE=.docker/docker_config.json --tag optimade .
- name: Start Docker image - server
run: |
docker run --rm -d -p 3213:5000 --name optimade optimade
.github/utils/wait_for_it.sh localhost:3213 -t 120
sleep 15
- name: Test server, including OPTIONAL base URLs
uses: Materials-Consortia/optimade-validator-action@v2
with:
port: 3213
path: /
all versioned paths: yes
validator version: ${{ github.sha }} # This ensures the head of a PR or latest push commit is tested
- name: Start Docker image - index server
run: |
docker run --rm -d -p 3214:5000 --name optimade-index -e MAIN=main_index optimade
.github/utils/wait_for_it.sh localhost:3214 -t 120
sleep 15
- name: Test index server, including OPTIONAL base URLs
uses: Materials-Consortia/optimade-validator-action@v2
with:
port: 3214
path: /
all versioned paths: yes
index: yes
validator version: ${{ github.sha }} # This ensures the head of a PR or latest push commit is tested
pytest:
runs-on: ubuntu-latest
env:
OPTIMADE_CONFIG_FILE: ${{ github.workspace }}/optimade_config.json
strategy:
fail-fast: false
max-parallel: 4
matrix:
python-version: ['3.10', '3.11', '3.12', '3.13']
services:
mongo:
image: mongo:7
ports:
- 27017:27017
postgres:
image: postgres:10
env:
POSTGRES_DB: test_aiida
POSTGRES_PASSWORD: test
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
elasticsearch:
image: elasticsearch:7.17.7
ports:
- 9200:9200
- 9300:9300
env:
discovery.type: single-node
xpack.security.enabled: 'false'
steps:
- uses: actions/checkout@v4
with:
submodules: true
fetch-depth: 2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'
cache-dependency-path: |
requirements*.txt
- name: Install latest compatible versions of immediate dependencies
run: |
python -m pip install --upgrade pip
pip install -U setuptools wheel
pip install -r requirements.txt -r requirements-dev.txt -r requirements-http-client.txt
pip install -e .
- name: Run non-server tests
run: pytest -rs -vvv --durations=10 --cov=./optimade/ --cov-report=xml tests/ --ignore tests/server
- name: Install latest server dependencies
run: pip install -r requirements-server.txt
- name: Run server tests (using `mongomock`)
run: pytest -rs -vvv --durations=10 --cov=./optimade/ --cov-report=xml --cov-append tests/server tests/filtertransformers
env:
OPTIMADE_DATABASE_BACKEND: 'mongomock'
- name: Run server tests with no API validation (using `mongomock`)
run:
pytest -rs -vvv --durations=10 --cov=./optimade/ --cov-report=xml --cov-append tests/server tests/filtertransformers
env:
OPTIMADE_DATABASE_BACKEND: 'mongomock'
OPTIMADE_VALIDATE_API_RESPONSE: false
- name: Run server tests (using a real MongoDB)
run: pytest -rs -vvv --durations=10 --cov=./optimade/ --cov-report=xml --cov-append tests/server tests/filtertransformers
env:
OPTIMADE_DATABASE_BACKEND: 'mongodb'
- name: Run server tests (using Elasticsearch)
run: |
.github/utils/wait_for_it.sh localhost:9200 -t 120
.github/utils/wait_for_it.sh localhost:9300 -t 120
pytest -rs -vvv --cov=./optimade/ --cov-report=xml --cov-append tests/server tests/filtertransformers
env:
OPTIMADE_DATABASE_BACKEND: 'elastic'
- name: Install adapter conversion dependencies
run: pip install -r requirements-client.txt
- name: Setup environment for AiiDA
env:
AIIDA_TEST_BACKEND: core.psql_dos
run: |
.github/aiida/setup_aiida.sh
- name: Run previously skipped tests for adapter conversion
run: pytest -rs -vvv --cov=./optimade/ --cov-report=xml --cov-append tests/adapters/
- name: Run tests for validator only to assess coverage (mongomock)
if: matrix.python-version == '3.11'
run: pytest -rs --cov=./optimade/ --cov-report=xml:validator_cov.xml --cov-append tests/server/test_server_validation.py
env:
OPTIMADE_DATABASE_BACKEND: 'mongomock'
- name: Run tests for validator only to assess coverage (Elasticsearch)
if: matrix.python-version == '3.11'
run: pytest -rs --cov=./optimade/ --cov-report=xml:validator_cov.xml --cov-append tests/server/test_server_validation.py
env:
OPTIMADE_DATABASE_BACKEND: 'elastic'
OPTIMADE_INSERT_TEST_DATA: false # Must be specified as previous steps will have already inserted the test data
OPTIMADE_INSERT_FROM_JSONL: '' # Must be specified as previous steps will have already inserted the test data
- name: Run tests for validator only to assess coverage (MongoDB)
if: matrix.python-version == '3.11'
run: pytest -rs --cov=./optimade/ --cov-report=xml:validator_cov.xml --cov-append tests/server/test_server_validation.py
env:
OPTIMADE_DATABASE_BACKEND: 'mongodb'
OPTIMADE_INSERT_TEST_DATA: false # Must be specified as previous steps will have already inserted the test data
OPTIMADE_INSERT_FROM_JSONL: '' # Must be specified as previous steps will have already inserted the test data
- name: Run the OPTIMADE Client CLI
if: matrix.python-version == '3.11'
run: |
coverage run --append --source optimade optimade/client/cli.py \
--filter 'nsites = 1' \
--http-timeout 10.0 \
--output-file test_get_async.json \
https://optimade.fly.dev
test test_get_async.json
coverage run --append --source optimade optimade/client/cli.py \
--filter 'nsites = 1' \
--http-timeout 10.0 \
--count \
--output-file test_count.json \
https://optimade.fly.dev
test test_count.json
coverage run --append --source optimade optimade/client/cli.py \
--no-async \
--filter 'nsites = 1' \
--http-timeout 10.0 \
--count \
--output-file test_count_no_async.json \
https://optimade.fly.dev
test test_count_no_async.json
diff test_count_no_async.json test_count.json
coverage xml
- name: Upload coverage to Codecov
if: matrix.python-version == '3.11' && github.repository == 'Materials-Consortia/optimade-python-tools'
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
name: project
file: ./coverage.xml
flags: project
- name: Upload validator coverage to Codecov
if: matrix.python-version == '3.11' && github.repository == 'Materials-Consortia/optimade-python-tools'
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
name: validator
file: ./validator_cov.xml
flags: validator
docs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: true
- uses: actions/setup-python@v5
with:
python-version: ${{ env.LINTING_PY_VERSION }}
cache: 'pip'
cache-dependency-path: |
requirements*.txt
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -U setuptools wheel
pip install -r requirements.txt -r requirements-server.txt -r requirements-dev.txt -r requirements-http-client.txt -r requirements-docs.txt
pip install -e .
# NOTE: While we're now using `mike`, this is still useful
# to test the integrity of the documentation build.
- name: Build
run: |
invoke create-api-reference-docs --pre-clean
mkdocs build --strict
test_build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Python ${{ env.LINTING_PY_VERSION }}
uses: actions/setup-python@v5
with:
python-version: ${{ env.LINTING_PY_VERSION }}
cache: 'pip'
cache-dependency-path: |
requirements*.txt
- name: Install Python dependencies
run: |
python -m pip install --upgrade pip
pip install --upgrade setuptools requests
- name: Install package
run: |
pip install -r requirements.txt -r requirements-dev.txt -r requirements-client.txt -r requirements-http-client.txt -r requirements-docs.txt
pip install -e .[all]
- name: Build source distribution
run: python -m build