forked from ogx-ai/ogx
-
Notifications
You must be signed in to change notification settings - Fork 0
211 lines (183 loc) · 6.55 KB
/
Copy pathpublish-openapi-sdk.yml
File metadata and controls
211 lines (183 loc) · 6.55 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
name: Publish OpenAPI SDK to PyPI
run-name: Publish ogx-client to PyPI
on:
workflow_dispatch:
inputs:
publish_to:
description: 'Publish to PyPI or TestPyPI'
required: true
default: 'testpypi'
type: choice
options:
- testpypi
- pypi
version:
description: 'Version override (e.g., "1.2.0"). Leave empty to auto-detect from tag or fallback_version.'
required: false
type: string
dry_run:
description: 'Dry run (build only, no publish)'
type: boolean
default: false
push:
tags:
- 'openapi-sdk-v*' # Tags like openapi-sdk-v0.5.0
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: false
permissions:
contents: read
jobs:
compute-version:
name: Compute version
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version.outputs.version }}
steps:
- name: Checkout repository
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Compute SDK version
id: version
run: |
if [ -n "${{ inputs.version }}" ]; then
# Explicit override from workflow_dispatch
VERSION="${{ inputs.version }}"
elif [[ "$GITHUB_REF" == refs/tags/openapi-sdk-v* ]]; then
# Extract version from tag: openapi-sdk-v1.2.0 -> 1.2.0
VERSION="${GITHUB_REF#refs/tags/openapi-sdk-v}"
else
# Fall back to fallback_version from pyproject.toml
VERSION=$(python3 -c "
import tomllib, pathlib
p = tomllib.loads(pathlib.Path('pyproject.toml').read_text())
print(p.get('tool', {}).get('setuptools_scm', {}).get('fallback_version', '0.0.0.dev0'))
")
fi
echo "version=${VERSION}" >> "$GITHUB_OUTPUT"
echo "Computed version: ${VERSION}"
build-sdk:
needs: compute-version
runs-on: ubuntu-latest
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@be666c2fcd27ec809703dec50e508c2fdc7f6654 # v5.2.0
with:
distribution: 'temurin'
java-version: '11'
- name: Install openapi-generator-cli
run: npm install -g @openapitools/openapi-generator-cli
- name: Verify installations
working-directory: client-sdks/openapi
run: |
set -e
echo "=== Java version ==="
java -version
echo "=== OpenAPI Generator version ==="
openapi-generator-cli version
echo "=== SDK version ==="
echo "${{ needs.compute-version.outputs.version }}"
- name: Generate OpenAPI SDK
working-directory: client-sdks/openapi
run: |
VERSION="${{ needs.compute-version.outputs.version }}"
echo "Generating SDK with OPEN=0 (ogx_client) at version ${VERSION}..."
make sdk OPEN=0 VERSION="${VERSION}"
- name: Verify SDK generation
working-directory: client-sdks/openapi
run: |
if [ ! -d sdks/python ]; then
echo "Error: SDK directory was not generated"
exit 1
fi
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"
exit 1
fi
echo "SDK generated successfully"
ls -lh sdks/python/
- name: Build package
working-directory: client-sdks/openapi/sdks/python
run: |
echo "Building Python package..."
uv build
echo "Built distribution files:"
ls -lh dist/
- name: Upload build artifacts
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: python-sdk-dist
path: client-sdks/openapi/sdks/python/dist/
retention-days: 30
publish-testpypi:
if: |
(github.event_name == 'workflow_dispatch' && inputs.publish_to == 'testpypi' && inputs.dry_run == false) ||
(github.event_name == 'push' && startsWith(github.ref, 'refs/tags/openapi-sdk-v') && !contains(github.ref, '-rc') && !contains(github.ref, '-alpha') && !contains(github.ref, '-beta'))
needs: build-sdk
runs-on: ubuntu-latest
environment: testpypi
permissions:
id-token: write
steps:
- name: Download build artifacts
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
name: python-sdk-dist
path: dist
- name: Publish to TestPyPI
uses: pypa/gh-action-pypi-publish@cef221092ed1bacb1cc03d23a2d87d1d172e277b # v1.14.0
with:
repository-url: https://test.pypi.org/legacy/
packages-dir: dist/
verbose: true
- name: Summary
run: |
{
echo "## SDK Publishing Summary"
echo ""
echo "- **Event**: ${{ github.event_name }}"
echo "- **Target**: TestPyPI"
echo "- **Package**: ogx-client"
echo ""
echo "✅ Package published to TestPyPI"
echo "Install with: \`pip install --index-url https://test.pypi.org/simple/ ogx-client\`"
} >> "$GITHUB_STEP_SUMMARY"
publish-pypi:
if: |
github.event_name == 'workflow_dispatch' &&
inputs.publish_to == 'pypi' &&
inputs.dry_run == false
needs: build-sdk
runs-on: ubuntu-latest
permissions:
id-token: write
steps:
- name: Download build artifacts
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
name: python-sdk-dist
path: dist
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@cef221092ed1bacb1cc03d23a2d87d1d172e277b # v1.14.0
with:
packages-dir: dist/
verbose: true
- name: Summary
run: |
{
echo "## SDK Publishing Summary"
echo ""
echo "- **Event**: ${{ github.event_name }}"
echo "- **Target**: PyPI (production)"
echo "- **Package**: ogx-client"
echo ""
echo "✅ Package published to PyPI"
echo "Install with: \`pip install ogx-client\`"
} >> "$GITHUB_STEP_SUMMARY"