-
Notifications
You must be signed in to change notification settings - Fork 72
159 lines (141 loc) · 5.54 KB
/
ci-test.yml
File metadata and controls
159 lines (141 loc) · 5.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
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.10", "3.11", "3.12", "3.13", "3.14"]
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@v6
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v6
with:
python-version: ${{ matrix.python-version }}
cache: "pip"
- name: Install package & dependencies
run: 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
- name: Install other test dependencies
if: matrix.backend != 'local'
run: python -m pip install -e . -r tests/requirements_${{ matrix.backend }}.txt
# 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: 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: Unit tests (SQL/Postgres)
if: matrix.backend == 'postgres'
env:
SQLALCHEMY_DATABASE_URL: postgresql+psycopg://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: 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