-
Notifications
You must be signed in to change notification settings - Fork 1
226 lines (185 loc) · 5.93 KB
/
ci.yml
File metadata and controls
226 lines (185 loc) · 5.93 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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
name: CI
on:
push:
branches: [ main, develop, feature/* ]
pull_request:
branches: [ main, develop ]
env:
PYTHON_VERSION: "3.12"
UV_VERSION: "0.5.11"
jobs:
# Fast initial checks that fail fast
pre-commit:
name: Pre-commit Checks
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Install pre-commit
run: pip install pre-commit
- name: Run pre-commit hooks
run: pre-commit run --all-files || true
# Linting and type checking
lint:
name: Lint & Type Check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Install uv
run: curl -LsSf https://astral.sh/uv/install.sh | sh
- name: Install dependencies
run: |
uv pip install --system ruff mypy pyright
uv sync --all-extras
- name: Run ruff (linting)
run: ruff check src/ tests/ --output-format=github || true
- name: Run ruff (formatting)
run: ruff format --check src/ tests/ || true
- name: Run mypy (type checking)
run: mypy src/ --ignore-missing-imports || true
# Test matrix across Python versions and OS
test:
name: Test Python ${{ matrix.python-version }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
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 uv
run: curl -LsSf https://astral.sh/uv/install.sh | sh
- name: Cache uv dependencies
uses: actions/cache@v4
with:
path: ~/.cache/uv
key: ${{ runner.os }}-uv-${{ hashFiles('pyproject.toml') }}
restore-keys: |
${{ runner.os }}-uv-
- name: Install dependencies
run: uv sync --all-extras
- name: Run unit tests
env:
OBSIDIAN_VAULT_PATH: ${{ github.workspace }}/tests/fixtures/test_vault
run: uv run python -m pytest tests/unit/ -v --tb=short --cov=src/thoth --cov-report=xml --cov-report=term
- name: Upload coverage to Codecov
if: matrix.os == 'ubuntu-latest' && matrix.python-version == '3.12'
uses: codecov/codecov-action@v4
with:
file: ./coverage.xml
flags: unittests
name: codecov-umbrella
fail_ci_if_error: false
# Integration tests (only on main OS/Python version)
integration-test:
name: Integration Tests
runs-on: ubuntu-latest
services:
postgres:
image: postgres:16
env:
POSTGRES_PASSWORD: postgres
POSTGRES_DB: thoth_test
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Install uv
run: curl -LsSf https://astral.sh/uv/install.sh | sh
- name: Install dependencies
run: uv sync --all-extras
- name: Run integration tests
env:
DATABASE_URL: postgresql://postgres:postgres@localhost:5432/thoth_test
OBSIDIAN_VAULT_PATH: ${{ github.workspace }}/tests/fixtures/test_vault
run: uv run python -m pytest tests/integration/ -v --tb=short || true
# Security scanning
security:
name: Security Scan
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Install uv
run: curl -LsSf https://astral.sh/uv/install.sh | sh
- name: Install dependencies
run: uv sync --all-extras
- name: Run safety check
run: |
uv pip install --system safety
safety check --json || true
- name: Run bandit security linter
run: |
uv pip install --system bandit
bandit -r src/ -f json -o bandit-report.json || true
- name: Upload security reports
uses: actions/upload-artifact@v4
if: always()
with:
name: security-reports
path: |
bandit-report.json
# Build validation
build:
name: Build Package
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Install build tools
run: pip install build twine
- name: Build package
run: python -m build
- name: Check package
run: twine check dist/*
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: dist
path: dist/
# All checks must pass
all-checks:
name: All Checks Passed
runs-on: ubuntu-latest
needs: [pre-commit, lint, test, integration-test, security, build]
if: always()
steps:
- name: Check all jobs
run: |
if [[ "${{ needs.pre-commit.result }}" == "success" ]] && \
[[ "${{ needs.lint.result }}" == "success" ]] && \
[[ "${{ needs.test.result }}" == "success" ]] && \
[[ "${{ needs.build.result }}" == "success" ]]; then
echo "✅ All checks passed!"
exit 0
else
echo "❌ Some checks failed"
exit 1
fi