-
Notifications
You must be signed in to change notification settings - Fork 0
202 lines (174 loc) · 6.79 KB
/
ci.yml
File metadata and controls
202 lines (174 loc) · 6.79 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
name: CI
on:
push:
branches: [main]
pull_request:
branches: [main]
permissions:
contents: read
env:
DO_NOT_TRACK: '1'
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
cache: 'pip'
cache-dependency-path: 'pyproject.toml'
- name: Install dependencies
run: pip install -e ".[dev]"
- name: Run Ruff linter
run: ruff check .
- name: Run Ruff formatter check
run: ruff format --check .
- name: Run MyPy
run: mypy axonflow
- name: Run falsey-clobber check (no `data.get(...) or X` against pre-existing baseline)
run: python3 scripts/lint_no_falsey_clobber.py axonflow/ --baseline .lint_baselines/falsey_clobber.json
test:
runs-on: ubuntu-latest
strategy:
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 }}
cache: 'pip'
cache-dependency-path: 'pyproject.toml'
- name: Install dependencies
run: pip install -e ".[dev,all]"
- name: Run tests
run: pytest --cov-report=xml
- name: Upload coverage
if: matrix.python-version == '3.11'
uses: codecov/codecov-action@v4
with:
files: ./coverage.xml
flags: python-sdk
fail_ci_if_error: false
# QF-15: wire-shape contract CI. Blocks drift between Python SDK pydantic
# models and the OpenAPI specs that are the authoritative wire contract.
# Runs on every PR. Drift the baseline does not cover fails the check.
#
# The specs are fetched from the getaxonflow/axonflow community mirror
# pinned to the SHA recorded in tests/fixtures/wire_shape_baseline.json
# so the gate is deterministic — a given SDK commit always diffs against
# the same spec revision, independent of upstream activity. Changing the
# pinned SHA from the same PR that changes SDK models would bypass the
# gate, so the workflow also runs a SHA-bump guard that requires a
# 'spec-pin-bump' label on PRs that move the SHA.
#
# To pick up new spec changes, regenerate the baseline via
# scripts/refresh_wire_shape_baseline.py (ideally in a dedicated PR).
wire-shape-contract:
runs-on: ubuntu-latest
steps:
- name: Checkout SDK (full history for SHA-bump guard)
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Read pinned OpenAPI specs SHA from baseline
id: specs_sha
run: |
python3 - <<'PY' >> "$GITHUB_OUTPUT"
import json
import sys
path = "tests/fixtures/wire_shape_baseline.json"
data = json.load(open(path))
sha = data.get("openapi_specs_sha", "").strip()
if not sha:
print(
f"::error::{path} is missing openapi_specs_sha. "
"Regenerate via scripts/refresh_wire_shape_baseline.py.",
file=sys.stderr,
)
sys.exit(1)
print(f"sha={sha}")
PY
# SHA-bump guard: the pinned SHA is the contract's source of truth.
# A PR that both changes the SHA and the SDK models can silently
# retarget the gate away from the drift it should have caught. Require
# explicit 'spec-pin-bump' label to acknowledge the bump. First-time
# introductions (base branch has no pin yet) bypass the guard.
- name: Guard against unauthorized OpenAPI specs SHA bump
if: github.event_name == 'pull_request'
env:
PR_LABELS: ${{ toJSON(github.event.pull_request.labels.*.name) }}
BASE_REF: ${{ github.base_ref }}
PR_SHA: ${{ steps.specs_sha.outputs.sha }}
run: |
set -e
BASE_SHA=$(
git show "origin/${BASE_REF}:tests/fixtures/wire_shape_baseline.json" 2>/dev/null \
| python3 -c "import json, sys; print(json.load(sys.stdin).get('openapi_specs_sha','') or '')" \
|| true
)
if [ -z "$BASE_SHA" ]; then
echo "::notice::Base branch has no openapi_specs_sha yet; treating this PR as the first pin introduction."
exit 0
fi
if [ "$BASE_SHA" = "$PR_SHA" ]; then
echo "openapi_specs_sha unchanged (${PR_SHA})."
exit 0
fi
echo "SHA change detected: ${BASE_SHA} -> ${PR_SHA}"
HAS_LABEL=$(printf '%s' "$PR_LABELS" | python3 -c "import json, sys; print('spec-pin-bump' in json.load(sys.stdin))")
if [ "$HAS_LABEL" = "True" ]; then
echo "::notice::'spec-pin-bump' label present — SHA bump authorized."
exit 0
fi
echo "::error::openapi_specs_sha changed from ${BASE_SHA} to ${PR_SHA}."
echo "::error::The wire-shape contract's spec revision is pinned to preserve"
echo "::error::review integrity: a SHA change in the same PR as SDK changes"
echo "::error::can silence drift by retargeting the contract to a friendlier"
echo "::error::revision. Either split this into a dedicated SHA-bump PR, or"
echo "::error::apply the 'spec-pin-bump' label to this PR to acknowledge that"
echo "::error::the bump is intentional and has been reviewed independently."
exit 1
- name: Checkout OpenAPI specs (pinned to baseline SHA)
uses: actions/checkout@v4
with:
repository: getaxonflow/axonflow
ref: ${{ steps.specs_sha.outputs.sha }}
path: axonflow-community
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
cache: 'pip'
cache-dependency-path: 'pyproject.toml'
- name: Install dependencies
run: pip install -e ".[dev]"
- name: Run wire-shape contract tests
env:
AXONFLOW_OPENAPI_SPECS_DIR: ${{ github.workspace }}/axonflow-community/docs/api
run: pytest tests/test_wire_shape.py -m wire_shape -v --no-cov
build:
runs-on: ubuntu-latest
needs: [lint, test, wire-shape-contract]
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
cache: 'pip'
cache-dependency-path: 'pyproject.toml'
- 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/