forked from ogx-ai/ogx
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathopenapi-generator-validation.yml
More file actions
259 lines (213 loc) · 8.42 KB
/
Copy pathopenapi-generator-validation.yml
File metadata and controls
259 lines (213 loc) · 8.42 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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
name: OpenAPI Generator SDK Validation
run-name: Validate OpenAPI Generator SDK generation
on:
pull_request:
paths:
# OpenAPI Generator files
- 'client-sdks/openapi/Makefile'
- 'client-sdks/openapi/merge_stainless_config.py'
- 'client-sdks/openapi/build_hierarchy.py'
- 'client-sdks/openapi/patch_hierarchy.py'
- 'client-sdks/openapi/patches.yml'
- 'client-sdks/openapi/openapi-config.json'
- 'client-sdks/openapi/openapitools.json'
- 'client-sdks/openapi/README.md'
# Stainless source files (our inputs)
- 'client-sdks/stainless/openapi.yml'
- 'client-sdks/stainless/config.yml'
# This workflow itself
- '.github/workflows/openapi-generator-validation.yml'
merge_group:
branches:
- main
- 'release-[0-9]+.[0-9]+.x'
push:
branches:
- main
- 'release-[0-9]+.[0-9]+.x'
paths:
- 'client-sdks/openapi/**'
- 'client-sdks/stainless/openapi.yml'
- 'client-sdks/stainless/config.yml'
- '.github/workflows/openapi-generator-validation.yml'
workflow_dispatch:
inputs:
test_macos:
description: 'Force macOS testing (expensive)'
type: boolean
default: true
concurrency:
group: ${{ github.workflow }}-${{ github.ref == 'refs/heads/main' && github.run_id || github.ref }}
cancel-in-progress: true
permissions:
contents: read
jobs:
determine-matrix:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- name: Checkout repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Check which files changed
uses: dorny/paths-filter@fbd0ab8f3e69293af611ebaee6363fc25e6d187d # v4.0.1
id: filter
with:
filters: |
critical:
- 'client-sdks/openapi/Makefile'
- 'client-sdks/openapi/merge_stainless_config.py'
- 'client-sdks/openapi/build_hierarchy.py'
- 'client-sdks/openapi/patch_hierarchy.py'
- 'client-sdks/openapi/patches.yml'
- 'client-sdks/openapi/openapitools.json'
- 'client-sdks/stainless/openapi.yml'
- 'client-sdks/stainless/config.yml'
- name: Determine test matrix
id: set-matrix
run: |
# Always test on Linux
MATRIX='{"os":["ubuntu-latest"]}'
# Include macOS if:
# 1. Manual workflow_dispatch with test_macos=true
# 2. Push to main/release branches
# 3. Critical files changed in PR
INCLUDE_MACOS="false"
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
INCLUDE_MACOS="${{ inputs.test_macos }}"
elif [ "${{ github.event_name }}" = "push" ]; then
# Always test macOS on main/release branches
INCLUDE_MACOS="true"
elif [ "${{ steps.filter.outputs.critical }}" = "true" ]; then
# Critical files changed in PR
INCLUDE_MACOS="true"
fi
if [ "$INCLUDE_MACOS" = "true" ]; then
MATRIX='{"os":["ubuntu-latest","macos-latest"]}'
fi
echo "matrix=$MATRIX" >> "$GITHUB_OUTPUT"
echo "Testing on platforms: $MATRIX"
validate-sdk-generation:
needs: determine-matrix
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix: ${{ fromJSON(needs.determine-matrix.outputs.matrix) }}
steps:
- name: Checkout repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Setup Python environment
uses: ./.github/actions/setup-runner
with:
python-version: '3.12'
- name: Set up Java
uses: actions/setup-java@1bcf9fb12cf4aa7d266a90ae39939e61372fe520 # v5.4.0
with:
distribution: 'temurin'
java-version: '11'
- name: Set up Node.js (Linux only)
if: runner.os == 'Linux'
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
with:
node-version: '22'
- name: Install openapi-generator-cli (Linux)
if: runner.os == 'Linux'
run: npm install -g @openapitools/openapi-generator-cli
- name: Install openapi-generator-cli (macOS)
if: runner.os == 'macOS'
run: brew install openapi-generator
- name: Verify installations
working-directory: client-sdks/openapi
run: |
set -e
GENERATOR_CMD=$([ "${{ runner.os }}" = "macOS" ] && echo "openapi-generator" || echo "openapi-generator-cli")
echo "=== Java version ==="
java -version
echo "=== OpenAPI Generator version ==="
$GENERATOR_CMD version
echo "=== SDK version from pyproject.toml ==="
VERSION_OUTPUT=$(make version)
echo "$VERSION_OUTPUT"
# Extract version string
VERSION="${VERSION_OUTPUT#SDK version: }"
# Check version is at least 5 characters (e.g., "0.5.0")
if [ ${#VERSION} -lt 5 ]; then
echo "Error: Version string too short: '$VERSION'"
exit 1
fi
echo "Version validation passed: $VERSION"
- name: Run dependency check
working-directory: client-sdks/openapi
run: make check-generator
- name: Generate OpenAPI spec
working-directory: client-sdks/openapi
run: make openapi
- name: Validate generated OpenAPI spec
working-directory: client-sdks/openapi
run: |
set -e
# Check that openapi.yml was generated
if [ ! -f openapi.yml ]; then
echo "Error: openapi.yml was not generated"
exit 1
fi
echo "OpenAPI spec generated successfully"
ls -lh openapi.yml
- name: Generate Python SDK
working-directory: client-sdks/openapi
run: make sdk OPEN=0
- name: Validate generated SDK
working-directory: client-sdks/openapi
run: |
set -e
# Check SDK directory was generated
if [ ! -d sdks/python ]; then
echo "Error: SDK directory was not generated"
exit 1
fi
# Check we generated a substantial number of Python files (> 10)
PY_FILE_COUNT=$(find sdks/python -name "*.py" | wc -l)
echo "Generated Python files: $PY_FILE_COUNT"
if [ "$PY_FILE_COUNT" -le 10 ]; then
echo "Error: Too few Python files generated (expected > 10, got $PY_FILE_COUNT)"
exit 1
fi
echo "SDK validation passed: $PY_FILE_COUNT Python files generated"
# Show directory structure for debugging
echo "=== Generated SDK structure ==="
find sdks/python -type f -name "*.py" | head -20
- name: Install generated SDK
run: |
echo "Reinstalling OpenAPI-generated SDK (ogx_client)..."
uv pip uninstall ogx-client || true
# Install SDK using uv pip
uv pip install -e client-sdks/openapi/sdks/python
echo "Verifying installation..."
uv run python -c "import ogx_client; print(f'Installed: {ogx_client.__name__}')"
- name: Setup Ollama (for integration tests)
if: runner.os == 'Linux'
uses: ./.github/actions/setup-ollama
- name: Run integration tests with OpenAPI SDK
if: runner.os == 'Linux'
run: |
echo "Running integration tests with OpenAPI-generated SDK..."
# Run a smoke test suite - basic functionality tests
uv run pytest tests/integration/inspect/test_inspect.py \
--stack-config="inference=ollama" \
-v \
|| echo "::warning::Some integration tests failed - this may indicate SDK compatibility issues"
# Show which SDK is actually being used
uv run python -c "import ogx_client; import inspect; print(f'SDK location: {inspect.getfile(ogx_client)}')"
- name: Summary
if: runner.os == 'Linux'
run: |
{
echo "## OpenAPI SDK Validation Summary"
echo ""
echo "✅ SDK generation completed successfully"
echo "✅ SDK installed and importable"
echo "✅ Integration tests executed (check logs for results)"
echo ""
echo "**Platform**: ${{ matrix.os }}"
echo "**Package**: ogx_client (OpenAPI-generated)"
} >> "$GITHUB_STEP_SUMMARY"