Skip to content

Commit e9298df

Browse files
iscai-msftCopilot
andcommitted
ci: add Python-specific integration workflow for branded emitter testing
Create python-integration.yml that triggers on http-client-python changes and runs the full typespec-azure branded Python e2e test suite: - Build & Regenerate - Mock API Tests - Type Checking (mypy, pyright) - Lint & Format (pylint, lint:extra, format:extra:check) - Docs Validation (apiview, sphinx) The workflow checks out Azure/typespec-azure, patches the core submodule to the PR commit, builds and packs http-client-python locally, then overrides typespec-python's dependency to use the PR version instead of the published npm version. This ensures tests validate the actual PR changes, not the last release. Reuses typespec-azure's composite actions for environment consistency. external-integration.yml is unchanged — http-client-python stays in paths-ignore since this dedicated workflow provides full Python coverage. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent d05ce00 commit e9298df

3 files changed

Lines changed: 397 additions & 0 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
changeKind: internal
3+
packages:
4+
- "@typespec/http-client-python"
5+
---
6+
7+
Add Python-specific integration workflow to test branded emitter (typespec-python) when unbranded emitter changes are made
Lines changed: 267 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,267 @@
1+
name: Python Integration
2+
3+
on:
4+
pull_request:
5+
branches: ["main"]
6+
paths:
7+
- "packages/http-client-python/**"
8+
- ".github/workflows/python-integration.yml"
9+
# Allow manual triggering
10+
workflow_dispatch:
11+
12+
permissions:
13+
contents: read
14+
15+
concurrency:
16+
group: ${{ github.workflow }}-${{ github.ref }}
17+
cancel-in-progress: true
18+
19+
jobs:
20+
build:
21+
name: "Build & Regenerate"
22+
runs-on: ubuntu-latest
23+
if: |
24+
!startsWith(github.head_ref, 'dependabot/') &&
25+
!startsWith(github.head_ref, 'publish/') &&
26+
!startsWith(github.head_ref, 'backmerge/') &&
27+
!startsWith(github.head_ref, 'revert-')
28+
steps:
29+
- name: Checkout Azure/typespec-azure repo
30+
uses: actions/checkout@v6
31+
with:
32+
repository: Azure/typespec-azure
33+
submodules: recursive
34+
35+
- name: Update core submodule to PR commit
36+
if: github.event_name == 'pull_request'
37+
run: |
38+
cd core
39+
git remote add pr https://github.com/${{ github.event.pull_request.head.repo.full_name }}.git
40+
git fetch pr ${{ github.event.pull_request.head.sha }}
41+
git checkout ${{ github.event.pull_request.head.sha }}
42+
43+
- uses: ./.github/actions/setup
44+
45+
- uses: ./.github/actions/setup-python
46+
47+
- name: Build and pack http-client-python from PR
48+
run: |
49+
cd core/packages/http-client-python
50+
npm install --ignore-scripts
51+
npm run build
52+
npm pack
53+
54+
- name: Override http-client-python with PR version
55+
run: |
56+
HCP_TGZ=$(ls core/packages/http-client-python/typespec-http-client-python-*.tgz)
57+
node -e '
58+
const pkg = require("./packages/typespec-python/package.json");
59+
const fs = require("fs");
60+
pkg.dependencies["@typespec/http-client-python"] = "file:../../" + process.argv[1];
61+
fs.writeFileSync("./packages/typespec-python/package.json", JSON.stringify(pkg, null, 2) + "\n");
62+
' "$HCP_TGZ"
63+
64+
- name: Install dependencies
65+
run: pnpm install --no-frozen-lockfile
66+
67+
- name: Build
68+
run: pnpm turbo run --filter "@azure-tools/typespec-python..." build
69+
70+
- name: Prepare Python environment
71+
run: pnpm run prepare
72+
working-directory: packages/typespec-python
73+
74+
- name: Regenerate
75+
run: pnpm run regenerate
76+
working-directory: packages/typespec-python
77+
78+
- name: Pre-build wheels
79+
working-directory: packages/typespec-python
80+
run: |
81+
venv/bin/python tests/install_packages.py build azure tests
82+
venv/bin/python tests/install_packages.py build unbranded tests
83+
84+
- name: Upload generated artifacts
85+
uses: actions/upload-artifact@v4
86+
with:
87+
name: python-generated
88+
path: |
89+
packages/typespec-python/tests/generated
90+
packages/typespec-python/tests/.wheels
91+
packages/typespec-python/dist
92+
packages/typespec-python/package.json
93+
core/packages/http-client-python/typespec-http-client-python-*.tgz
94+
core/packages/spector/dist
95+
core/packages/http-specs/dist
96+
packages/azure-http-specs/dist
97+
retention-days: 1
98+
99+
test:
100+
name: "Mock API Tests"
101+
needs: build
102+
runs-on: ubuntu-latest
103+
steps:
104+
- uses: actions/checkout@v6
105+
with:
106+
repository: Azure/typespec-azure
107+
submodules: recursive
108+
109+
- name: Update core submodule to PR commit
110+
if: github.event_name == 'pull_request'
111+
run: |
112+
cd core
113+
git remote add pr https://github.com/${{ github.event.pull_request.head.repo.full_name }}.git
114+
git fetch pr ${{ github.event.pull_request.head.sha }}
115+
git checkout ${{ github.event.pull_request.head.sha }}
116+
117+
- uses: ./.github/actions/setup
118+
119+
- uses: ./.github/actions/setup-python
120+
121+
- name: Download generated artifacts
122+
uses: actions/download-artifact@v4
123+
with:
124+
name: python-generated
125+
path: .
126+
127+
- name: Install dependencies
128+
run: pnpm install --no-frozen-lockfile
129+
130+
- name: Build spector and specs
131+
run: |
132+
pnpm turbo run --filter "@typespec/spector..." build
133+
pnpm --filter "@typespec/http-specs" exec tsc -p ./tsconfig.build.json
134+
pnpm --filter "@azure-tools/azure-http-specs" exec tsc -p ./tsconfig.build.json
135+
136+
- name: Prepare Python environment
137+
run: pnpm run prepare
138+
working-directory: packages/typespec-python
139+
140+
- name: Test
141+
run: pnpm run test:python:e2e
142+
working-directory: packages/typespec-python
143+
144+
typecheck:
145+
name: "Type Checking"
146+
needs: build
147+
runs-on: ubuntu-latest
148+
steps:
149+
- uses: actions/checkout@v6
150+
with:
151+
repository: Azure/typespec-azure
152+
submodules: recursive
153+
154+
- name: Update core submodule to PR commit
155+
if: github.event_name == 'pull_request'
156+
run: |
157+
cd core
158+
git remote add pr https://github.com/${{ github.event.pull_request.head.repo.full_name }}.git
159+
git fetch pr ${{ github.event.pull_request.head.sha }}
160+
git checkout ${{ github.event.pull_request.head.sha }}
161+
162+
- uses: ./.github/actions/setup
163+
164+
- uses: ./.github/actions/setup-python
165+
166+
- name: Download generated artifacts
167+
uses: actions/download-artifact@v4
168+
with:
169+
name: python-generated
170+
path: .
171+
172+
- name: Install dependencies
173+
run: pnpm install --filter "@azure-tools/typespec-python..."
174+
175+
- name: Prepare Python environment
176+
run: pnpm run prepare
177+
working-directory: packages/typespec-python
178+
179+
- name: Mypy & Pyright
180+
run: pnpm run test:python:e2e --env mypy,pyright
181+
working-directory: packages/typespec-python
182+
183+
lint:
184+
name: "Lint & Format"
185+
needs: build
186+
runs-on: ubuntu-latest
187+
steps:
188+
- uses: actions/checkout@v6
189+
with:
190+
repository: Azure/typespec-azure
191+
submodules: recursive
192+
193+
- name: Update core submodule to PR commit
194+
if: github.event_name == 'pull_request'
195+
run: |
196+
cd core
197+
git remote add pr https://github.com/${{ github.event.pull_request.head.repo.full_name }}.git
198+
git fetch pr ${{ github.event.pull_request.head.sha }}
199+
git checkout ${{ github.event.pull_request.head.sha }}
200+
201+
- uses: ./.github/actions/setup
202+
203+
- uses: ./.github/actions/setup-python
204+
205+
- name: Download generated artifacts
206+
uses: actions/download-artifact@v4
207+
with:
208+
name: python-generated
209+
path: .
210+
211+
- name: Install dependencies
212+
run: pnpm install --filter "@azure-tools/typespec-python..."
213+
214+
- name: Prepare Python environment
215+
run: pnpm run prepare
216+
working-directory: packages/typespec-python
217+
218+
- name: Pylint
219+
run: pnpm run test:python:e2e --env lint
220+
working-directory: packages/typespec-python
221+
222+
- name: Lint (extra)
223+
run: pnpm run lint:extra
224+
working-directory: packages/typespec-python
225+
226+
- name: Format check (extra)
227+
run: pnpm run format:extra:check
228+
working-directory: packages/typespec-python
229+
230+
docs:
231+
name: "Docs Validation"
232+
needs: build
233+
runs-on: ubuntu-latest
234+
steps:
235+
- uses: actions/checkout@v6
236+
with:
237+
repository: Azure/typespec-azure
238+
submodules: recursive
239+
240+
- name: Update core submodule to PR commit
241+
if: github.event_name == 'pull_request'
242+
run: |
243+
cd core
244+
git remote add pr https://github.com/${{ github.event.pull_request.head.repo.full_name }}.git
245+
git fetch pr ${{ github.event.pull_request.head.sha }}
246+
git checkout ${{ github.event.pull_request.head.sha }}
247+
248+
- uses: ./.github/actions/setup
249+
250+
- uses: ./.github/actions/setup-python
251+
252+
- name: Download generated artifacts
253+
uses: actions/download-artifact@v4
254+
with:
255+
name: python-generated
256+
path: .
257+
258+
- name: Install dependencies
259+
run: pnpm install --filter "@azure-tools/typespec-python..."
260+
261+
- name: Prepare Python environment
262+
run: pnpm run prepare
263+
working-directory: packages/typespec-python
264+
265+
- name: API View & Sphinx
266+
run: pnpm run test:python:e2e --env apiview,sphinx
267+
working-directory: packages/typespec-python
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
name: Python Regen Tests
2+
3+
on:
4+
push:
5+
branches: ["main"]
6+
paths:
7+
- "packages/http-client-python/**"
8+
# Allow manual triggering
9+
workflow_dispatch:
10+
11+
permissions:
12+
contents: read
13+
14+
concurrency:
15+
group: ${{ github.workflow }}-${{ github.ref }}
16+
cancel-in-progress: true
17+
18+
jobs:
19+
regenerate-and-pr:
20+
name: "Regenerate & PR to azure-sdk-for-python"
21+
runs-on: ubuntu-latest
22+
steps:
23+
- name: Checkout Azure/typespec-azure repo
24+
uses: actions/checkout@v6
25+
with:
26+
repository: Azure/typespec-azure
27+
submodules: recursive
28+
29+
- name: Update core submodule to merged commit
30+
run: |
31+
cd core
32+
git remote add merged https://github.com/microsoft/typespec.git
33+
git fetch merged ${{ github.sha }}
34+
git checkout ${{ github.sha }}
35+
36+
- uses: ./.github/actions/setup
37+
38+
- uses: ./.github/actions/setup-python
39+
40+
- name: Build and pack http-client-python from merged commit
41+
run: |
42+
cd core/packages/http-client-python
43+
npm install --ignore-scripts
44+
npm run build
45+
npm pack
46+
47+
- name: Override http-client-python with merged version
48+
run: |
49+
set -euo pipefail
50+
HCP_TGZ=$(ls core/packages/http-client-python/typespec-http-client-python-*.tgz)
51+
if [ "$(echo "$HCP_TGZ" | wc -l)" -ne 1 ]; then
52+
echo "ERROR: Expected exactly one tgz file, found: $HCP_TGZ"
53+
exit 1
54+
fi
55+
node -e '
56+
const pkg = require("./packages/typespec-python/package.json");
57+
const fs = require("fs");
58+
pkg.dependencies["@typespec/http-client-python"] = "file:../../" + process.argv[1];
59+
fs.writeFileSync("./packages/typespec-python/package.json", JSON.stringify(pkg, null, 2) + "\n");
60+
' "$HCP_TGZ"
61+
62+
- name: Install dependencies
63+
run: pnpm install --no-frozen-lockfile
64+
65+
- name: Build
66+
run: pnpm turbo run --filter "@azure-tools/typespec-python..." build
67+
68+
- name: Prepare Python environment
69+
run: pnpm run prepare
70+
working-directory: packages/typespec-python
71+
72+
- name: Regenerate tests
73+
run: pnpm run regenerate
74+
working-directory: packages/typespec-python
75+
76+
- name: Checkout azure-sdk-for-python
77+
uses: actions/checkout@v6
78+
with:
79+
repository: Azure/azure-sdk-for-python
80+
path: azure-sdk-for-python
81+
token: ${{ secrets.AZURE_SDK_PYTHON_PAT }}
82+
83+
- name: Copy regenerated tests
84+
run: |
85+
TARGET="azure-sdk-for-python/tools/typespec-python-generated-tests"
86+
rm -rf "$TARGET/azure" "$TARGET/unbranded"
87+
mkdir -p "$TARGET"
88+
cp -r packages/typespec-python/tests/generated/azure "$TARGET/azure"
89+
cp -r packages/typespec-python/tests/generated/unbranded "$TARGET/unbranded"
90+
91+
- name: Create Pull Request
92+
id: create-pr
93+
uses: peter-evans/create-pull-request@v7
94+
with:
95+
token: ${{ secrets.AZURE_SDK_PYTHON_PAT }}
96+
path: azure-sdk-for-python
97+
branch: auto/typespec-python-regen
98+
base: main
99+
delete-branch: true
100+
add-paths: tools/typespec-python-generated-tests/**
101+
title: "[typespec-python] Regenerate tests from http-client-python ${{ github.sha }}"
102+
body: |
103+
Automated regeneration of typespec-python generated tests.
104+
105+
Triggered by merge to `microsoft/typespec` main:
106+
- Commit: ${{ github.sha }}
107+
- Run: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
108+
109+
This PR was auto-generated. If CI passes, it will be auto-merged.
110+
commit-message: |
111+
[typespec-python] Regenerate tests from http-client-python
112+
113+
Source commit: microsoft/typespec@${{ github.sha }}
114+
labels: auto-merge
115+
116+
- name: Enable auto-merge
117+
if: steps.create-pr.outputs.pull-request-number
118+
env:
119+
GH_TOKEN: ${{ secrets.AZURE_SDK_PYTHON_PAT }}
120+
run: |
121+
gh pr merge ${{ steps.create-pr.outputs.pull-request-number }} \
122+
--repo Azure/azure-sdk-for-python \
123+
--auto --squash

0 commit comments

Comments
 (0)