-
Notifications
You must be signed in to change notification settings - Fork 0
196 lines (170 loc) · 6.83 KB
/
Copy pathci.yml
File metadata and controls
196 lines (170 loc) · 6.83 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
name: CI
permissions:
contents: read
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
test-fast:
# Fast feedback: unit tests and light orchestration tests only (`slow`
# deselected). Runs in parallel with `test` below rather than blocking
# on it, so a regression in the common-case code paths surfaces well
# before the slow, walk-forward-heavy suite finishes. No coverage gate
# here -- `test` already enforces it over the full suite; gating on
# this narrower subset alone would risk a spurious failure merely
# because the slow tests are the ones that exercise most of
# `quantlab.validation`.
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest]
python-version: ["3.12", "3.13"]
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
- name: Install uv
uses: astral-sh/setup-uv@20cfd1bf945f4377ade1205e4dbc17946fc9a30d # v10.0.1
with:
version: "0.12.3"
- name: Set up Python ${{ matrix.python-version }}
run: uv python install ${{ matrix.python-version }}
- name: Install dependencies (locked)
run: >-
uv sync --locked --python ${{ matrix.python-version }}
--extra dev --extra dashboard --extra yahoo --extra docs
--extra notebooks
- name: Lint (ruff)
run: |
uv run ruff check src tests scripts
uv run ruff format --check src tests scripts
- name: Type-check (mypy)
run: uv run mypy src tests scripts
- name: Test (fast offline suite)
run: uv run pytest -m "not network and not slow"
test:
# The authoritative, coverage-gated run: the full offline suite,
# `slow` included (real multi-fold walk-forward selection,
# multi-invocation CLI scenarios, ...). Exercise both supported Python
# versions on Linux and Windows.
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest]
python-version: ["3.12", "3.13"]
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
- name: Install uv
uses: astral-sh/setup-uv@20cfd1bf945f4377ade1205e4dbc17946fc9a30d # v10.0.1
with:
version: "0.12.3"
- name: Set up Python ${{ matrix.python-version }}
run: uv python install ${{ matrix.python-version }}
- name: Install dependencies (locked)
run: >-
uv sync --locked --python ${{ matrix.python-version }}
--extra dev --extra dashboard --extra yahoo --extra docs
--extra notebooks
- name: Lint (ruff)
run: |
uv run ruff check src tests scripts
uv run ruff format --check src tests scripts
- name: Type-check (mypy)
run: uv run mypy src tests scripts
- name: Test (full offline suite, with coverage)
run: >-
uv run pytest -m "not network" --cov=quantlab
--cov-report=term-missing --cov-report=xml --cov-fail-under=82
- name: Build documentation (strict)
run: uv run mkdocs build --strict
packaging:
# Verify distributions and bundled resources independently of the checkout.
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
- name: Install uv
uses: astral-sh/setup-uv@20cfd1bf945f4377ade1205e4dbc17946fc9a30d # v10.0.1
with:
version: "0.12.3"
- name: Set up Python
run: uv python install "3.12"
- name: Build sdist, then build the wheel *from that sdist*
# Building from the extracted sdist verifies both distribution manifests.
shell: bash
run: |
uv build --sdist --out-dir dist
mkdir sdist_extracted
tar -xzf dist/*.tar.gz -C sdist_extracted --strip-components=1
uv build --wheel --out-dir dist sdist_extracted
- name: Install the wheel and smoke-test the CLI from *outside* the checkout
# Running outside the checkout proves that bundled resources are installed.
shell: bash
working-directory: ${{ runner.temp }}
run: |
uv venv wheel_venv --python 3.12
if [ "$RUNNER_OS" = "Windows" ]; then
PY="wheel_venv/Scripts/python.exe"
QUANTLAB="wheel_venv/Scripts/quantlab.exe"
else
PY="wheel_venv/bin/python"
QUANTLAB="wheel_venv/bin/quantlab"
fi
uv pip install --python "$PY" "$GITHUB_WORKSPACE"/dist/*.whl
"$QUANTLAB" --help
"$QUANTLAB" backtest --shipped-config demo_offline
- name: Verify py.typed ships with the installed (non-editable) wheel
# Verify the marker in the installed package, not the source tree.
shell: bash
working-directory: ${{ runner.temp }}
run: |
if [ "$RUNNER_OS" = "Windows" ]; then
PY="wheel_venv/Scripts/python.exe"
else
PY="wheel_venv/bin/python"
fi
"$PY" -c "
import pathlib
import quantlab
marker = pathlib.Path(quantlab.__file__).parent / 'py.typed'
assert marker.is_file(), f'py.typed missing from installed package: {marker}'
print(f'py.typed present: {marker}')
"
- name: Build Docker image
if: matrix.os == 'ubuntu-latest'
run: docker build -t quantlab-ci-smoke-test .
- name: Smoke-test the Docker image with a real backtest
# Exercise the locked non-editable install and bundled offline data.
if: matrix.os == 'ubuntu-latest'
shell: bash
run: |
docker run --rm --entrypoint python quantlab-ci-smoke-test -c "
import os, pathlib, shutil
import quantlab
package = pathlib.Path(quantlab.__file__).resolve()
assert os.geteuid() != 0, 'runtime must not run as root'
assert shutil.which('gcc') is None, 'compiler leaked into runtime image'
assert 'site-packages' in package.parts, package
print(f'non-root wheel install: {package}')
"
docker run --rm quantlab-ci-smoke-test \
backtest --shipped-config demo_offline
- name: Smoke-test the Docker dashboard
if: matrix.os == 'ubuntu-latest'
shell: bash
run: |
container_id=$(docker run -d -p 8501:8501 quantlab-ci-smoke-test dashboard)
trap 'docker rm -f "$container_id" >/dev/null 2>&1 || true' EXIT
for attempt in {1..30}; do
if curl --fail --silent http://127.0.0.1:8501/_stcore/health; then
exit 0
fi
sleep 1
done
docker logs "$container_id"
exit 1