forked from pypatterns/python-cqrs
-
Notifications
You must be signed in to change notification settings - Fork 0
151 lines (130 loc) · 4.71 KB
/
tests.yml
File metadata and controls
151 lines (130 loc) · 4.71 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
name: Tests
on:
push:
branches: [ main, master ]
pull_request:
branches: [ main, master ]
jobs:
lint:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.10", "3.11", "3.12"]
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- 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
pip install -e ".[dev,examples]"
- name: Get changed Python files
id: changed
run: |
git fetch origin main master 2>/dev/null || true
BASE="origin/main"
if ! git rev-parse --verify origin/main >/dev/null 2>&1; then BASE="origin/master"; fi
git diff --name-only $BASE...HEAD -- src/ tests/ examples/ | grep -E '\.py$' > changed.txt || true
if [ -s changed.txt ]; then
echo "has_changes=true" >> $GITHUB_OUTPUT
else
echo "has_changes=false" >> $GITHUB_OUTPUT
fi
echo "Changed files:"
cat changed.txt || true
- name: Run ruff check
run: |
if [ "${{ steps.changed.outputs.has_changes }}" != "true" ]; then
echo "No Python files changed, skipping ruff check"
exit 0
fi
while IFS= read -r f; do [ -f "$f" ] && echo "$f"; done < changed.txt | xargs -r ruff check --config ruff.toml
- name: Run ruff format check
run: |
if [ "${{ steps.changed.outputs.has_changes }}" != "true" ]; then
echo "No Python files changed, skipping ruff format"
exit 0
fi
while IFS= read -r f; do [ -f "$f" ] && echo "$f"; done < changed.txt | xargs -r ruff format --check --config ruff.toml
- name: Run pyright
run: |
pyright --pythonversion ${{ matrix.python-version }} src tests examples
- name: Check minimum Python version (vermin)
run: |
vermin --target=3.10- --violations --eval-annotations --backport typing_extensions --exclude=venv --exclude=build --exclude=.git --exclude=.venv src examples tests
test:
name: test (py ${{ matrix.python-version }})
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.10", "3.11", "3.12"]
steps:
- uses: actions/checkout@v4
- 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
pip install -e ".[dev]"
- name: Start infrastructure
run: |
docker compose -f docker-compose-test.yml up -d
- name: Wait for MySQL
run: |
for i in $(seq 1 30); do
if docker compose -f docker-compose-test.yml exec -T mysql_tests mysqladmin ping -h localhost -ucqrs -pcqrs --silent 2>/dev/null; then
echo "MySQL is ready"
exit 0
fi
echo "Waiting for MySQL... ($i/30)"
sleep 2
done
echo "MySQL did not become ready in time"
exit 1
- name: Wait for PostgreSQL
run: |
for i in $(seq 1 30); do
if docker compose -f docker-compose-test.yml exec -T postgres_tests pg_isready -h localhost -U cqrs -q 2>/dev/null; then
echo "PostgreSQL is ready"
exit 0
fi
echo "Waiting for PostgreSQL... ($i/30)"
sleep 2
done
echo "PostgreSQL did not become ready in time"
exit 1
- name: Wait for Redis
run: |
for i in $(seq 1 15); do
if docker compose -f docker-compose-test.yml exec -T redis_tests redis-cli ping 2>/dev/null | grep -q PONG; then
echo "Redis is ready"
exit 0
fi
echo "Waiting for Redis... ($i/15)"
sleep 1
done
echo "Redis did not become ready in time"
exit 1
- name: Run all tests with coverage
env:
DATABASE_DSN: mysql+asyncmy://cqrs:cqrs@localhost:3307/test_cqrs
DATABASE_DSN_MYSQL: mysql+asyncmy://cqrs:cqrs@localhost:3307/test_cqrs
DATABASE_DSN_POSTGRESQL: postgresql+asyncpg://cqrs:cqrs@localhost:5433/cqrs
run: |
pytest -c ./tests/pytest-config.ini --cov=src --cov-report=xml --cov-report=term -o cache_dir=/tmp/pytest_cache ./tests/unit ./tests/integration
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: false
- name: Stop infrastructure
if: always()
run: docker compose -f docker-compose-test.yml down -v