Test #488
This file contains hidden or 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: Test | |
on: | |
pull_request: | |
branches: [master] | |
push: | |
branches: [master] | |
schedule: | |
# * is a special character in YAML so you have to quote this string | |
# min hours day(month) month day(week) | |
- cron: "0 0 * * 0" | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.ref }}-${{ github.head_ref }} | |
cancel-in-progress: ${{ github.ref != 'refs/heads/master' }} | |
jobs: | |
pytester: | |
# run on both push & normal PR | |
if: github.event_name == 'push' || github.event_name == 'pull_request' | |
runs-on: ${{ matrix.os }} | |
environment: test | |
strategy: | |
fail-fast: false | |
matrix: | |
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"] | |
os: ["ubuntu-latest", "macOS-latest", "windows-latest"] | |
backend: ["local", "mongodb", "postgres", "redis"] | |
exclude: | |
# ToDo: take if back when the connection become stable | |
# or resolve using `InMemoryMongoClient` | |
- { os: "macOS-latest", backend: "mongodb" } | |
- { os: "macOS-latest", backend: "postgres" } | |
- { os: "macOS-latest", backend: "redis" } | |
- { os: "windows-latest", backend: "postgres" } | |
- { os: "windows-latest", backend: "redis" } | |
env: | |
CACHIER_TEST_HOST: "localhost" | |
CACHIER_TEST_PORT: "27017" | |
#CACHIER_TEST_DB: "dummy_db" | |
#CACHIER_TEST_USERNAME: "myuser" | |
#CACHIER_TEST_PASSWORD: "yourpassword" | |
CACHIER_TEST_VS_DOCKERIZED_MONGO: "true" | |
CACHIER_TEST_REDIS_HOST: "localhost" | |
CACHIER_TEST_REDIS_PORT: "6379" | |
CACHIER_TEST_REDIS_DB: "0" | |
CACHIER_TEST_VS_DOCKERIZED_REDIS: "true" | |
steps: | |
- uses: actions/checkout@v5 | |
- name: Set up Python ${{ matrix.python-version }} | |
uses: actions/setup-python@v5 | |
with: | |
python-version: ${{ matrix.python-version }} | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
python -m pip install -e . -r tests/requirements.txt | |
- name: Lower inotify instance limit (Linux only, for Issue #24 test) | |
if: runner.os == 'Linux' && matrix.backend == 'local' | |
run: sudo sysctl -w fs.inotify.max_user_instances=128 | |
# This helps the test_inotify_instance_limit_reached hit the limit in CI | |
- name: Unit tests (local) | |
if: matrix.backend == 'local' | |
run: pytest -m "not mongo and not sql and not redis" --cov=cachier --cov-report=term --cov-report=xml:cov.xml | |
- name: Setup docker (missing on MacOS) | |
if: runner.os == 'macOS' && matrix.backend == 'mongodb' | |
run: | | |
brew install docker | |
colima start | |
# For testcontainers to find the Colima socket | |
sudo ln -sf $HOME/.colima/default/docker.sock /var/run/docker.sock | |
# ToDo: find a way to cache docker images | |
#- name: Cache Container Images | |
# if: matrix.backend == 'mongodb' | |
# uses: borda/cache-container-images-action@b32a5e804cb39af3c3d134fc03ab76eac0bfcfa9 | |
# with: | |
# prefix-key: "mongo-db" | |
# images: mongo:latest | |
- name: Start MongoDB in docker | |
if: matrix.backend == 'mongodb' | |
run: | | |
# start MongoDB in a container | |
docker run -d -p ${{ env.CACHIER_TEST_PORT }}:27017 --name mongodb mongo:latest | |
# wait for MongoDB to start, which is in average 5 seconds | |
sleep 5 | |
# show running containers | |
docker ps -a | |
- name: Install MongoDB core test dependencies | |
if: matrix.backend == 'mongodb' | |
run: | | |
python -m pip install -e . -r tests/mongodb_requirements.txt | |
- name: Unit tests (DB) | |
if: matrix.backend == 'mongodb' | |
run: pytest -m "mongo" --cov=cachier --cov-report=term --cov-report=xml:cov.xml | |
- name: Speed eval | |
run: python tests/speed_eval.py | |
- name: Start PostgreSQL in docker | |
if: matrix.backend == 'postgres' | |
run: | | |
docker run -d \ | |
-e POSTGRES_USER=testuser \ | |
-e POSTGRES_PASSWORD=testpass \ | |
-e POSTGRES_DB=testdb \ | |
-p 5432:5432 \ | |
--name postgres postgres:15 | |
# wait for PostgreSQL to start | |
sleep 10 | |
docker ps -a | |
- name: Install SQL core test dependencies (SQL/Postgres) | |
if: matrix.backend == 'postgres' | |
run: | | |
python -m pip install -e . -r tests/sql_requirements.txt | |
- name: Unit tests (SQL/Postgres) | |
if: matrix.backend == 'postgres' | |
env: | |
SQLALCHEMY_DATABASE_URL: postgresql://testuser:testpass@localhost:5432/testdb | |
run: pytest -m sql --cov=cachier --cov-report=term --cov-report=xml:cov.xml | |
- name: Start Redis in docker | |
if: matrix.backend == 'redis' | |
run: | | |
docker run -d \ | |
-p ${{ env.CACHIER_TEST_REDIS_PORT }}:6379 \ | |
--name redis redis:7-alpine | |
# wait for Redis to start | |
sleep 5 | |
docker ps -a | |
- name: Install Redis core test dependencies | |
if: matrix.backend == 'redis' | |
run: | | |
python -m pip install -e . -r tests/redis_requirements.txt | |
- name: Unit tests (Redis) | |
if: matrix.backend == 'redis' | |
run: pytest -m redis --cov=cachier --cov-report=term --cov-report=xml:cov.xml | |
- name: Upload coverage to Codecov (non PRs) | |
continue-on-error: true | |
uses: codecov/codecov-action@v5 | |
with: | |
fail_ci_if_error: true | |
token: ${{ secrets.CODECOV_TOKEN }} # required | |
flags: ${{ matrix.backend }} | |
override_pr: ${{ github.event.pull_request.number }} | |
testing-guardian: | |
runs-on: ubuntu-latest | |
needs: pytester | |
if: always() | |
steps: | |
- run: echo "${{ needs.pytester.result }}" | |
- name: failing... | |
if: needs.pytester.result == 'failure' | |
run: exit 1 | |
- name: cancelled or skipped... | |
if: contains(fromJSON('["cancelled", "skipped"]'), needs.pytester.result) | |
timeout-minutes: 1 | |
run: sleep 90 |