14
import { spawnSync } from 'node:child_process';
15
16
const packageJson = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8'));
17
+const tsCorePackageJson = JSON.parse(
18
+ readFileSync(new URL('../ts/packages/core/package.json', import.meta.url), 'utf8')
19
+);
20
const changesetConfig = JSON.parse(
21
readFileSync(new URL('../.changeset/config.json', import.meta.url), 'utf8')
22
);
29
new URL('../python/composio/__version__.py', import.meta.url),
30
'utf8'
31
);
32
+const pythonReleaseWorkflow = readFileSync(
33
+ new URL('../.github/workflows/py.release.yml', import.meta.url),
34
+ 'utf8'
35
+);
36
+const pythonMakefilePath = new URL('../python/Makefile', import.meta.url).pathname;
37
const changesetBinPath = new URL('../node_modules/.bin/changeset', import.meta.url).pathname;
38
const releaseScriptUrl = new URL('../ts/scripts/changeset-release.sh', import.meta.url);
39
const releaseScriptPath = releaseScriptUrl.pathname;
73
return requireMatch(text, /^\s*version\s*=\s*"([^"]+)"\s*$/m, label);
74
}
75
68
-function readPythonSdkVersions(rows) {
76
+function readSdkVersions(rows) {
77
const versions = new Set();
78
const pythonVersionPattern =
79
/\bv?(\d+(?:\.\d+)+(?:[._-]?(?:a|b|c|rc|alpha|beta|pre|preview)\d*)?(?:[._-]?(?:post|rev|r)\d*)?(?:[._-]?dev\d*)?(?:\+[a-z0-9]+(?:[._-][a-z0-9]+)*)?)\b/gi;
91
return versions;
92
}
93
86
-function readDocumentedPythonSdkVersions() {
94
+function escapeRegExp(value) {
95
+ return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
96
+}
97
+
98
+function readDocumentedSdkVersions(sdkLabel) {
99
const changelogDir = new URL('../docs/content/changelog/', import.meta.url);
100
+ const rowPattern = new RegExp(`^\\|\\s*${escapeRegExp(sdkLabel)}\\s*\\|.*$`, 'gm');
101
const rows = [];
102
103
for (const entry of readdirSync(changelogDir, { withFileTypes: true })) {
104
if (!entry.isFile() || !entry.name.endsWith('.mdx')) continue;
105
93
- const source = readFileSync(new URL(`../docs/content/changelog/${entry.name}`, import.meta.url), 'utf8');
94
- rows.push(...(source.match(/^\|\s*Python `composio`\s*\|.*$/gm) ?? []));
106
+ const source = readFileSync(
107
+ new URL(`../docs/content/changelog/${entry.name}`, import.meta.url),
108
+ 'utf8'
109
+ );
110
+ rows.push(...(source.match(rowPattern) ?? []));
111
}
112
97
- return readPythonSdkVersions(rows);
113
+ return readSdkVersions(rows);
114
+}
115
+
116
+function runPythonBuildFixture({ providers, providerFiles = [], failingProvider = '' }) {
117
+ const fixtureDir = mkdtempSync(join(tmpdir(), 'composio-python-build-'));
118
+ const buildLogPath = join(fixtureDir, 'build.log');
119
+
120
+ try {
121
+ mkdirSync(join(fixtureDir, '.venv/bin'), { recursive: true });
122
+ mkdirSync(join(fixtureDir, 'providers'), { recursive: true });
123
+ writeFileSync(buildLogPath, '');
124
+
125
+ const fakePythonPath = join(fixtureDir, '.venv/bin/python');
126
+ writeFileSync(
127
+ fakePythonPath,
128
+ `#!/usr/bin/env bash
129
+set -euo pipefail
130
+target="\${3:-}"
131
+printf '%s\n' "\${target:-<root>}" >> "$BUILD_LOG"
132
+
133
+if [[ -z "$target" ]]; then
134
+ mkdir -p dist
135
+ touch dist/root.whl
136
+ exit 0
137
+fi
138
+
139
+target="\${target%/}"
140
+if [[ "$target" == "$FAILING_PROVIDER" ]]; then
141
+ exit 23
142
+fi
143
+
144
+mkdir -p "$target/dist"
145
+touch "$target/dist/provider.whl"
146
+`
147
+ );
148
+ chmodSync(fakePythonPath, 0o755);
149
+
150
+ for (const provider of providers) {
151
+ const providerDir = join(fixtureDir, 'providers', provider);
152
+ mkdirSync(providerDir, { recursive: true });
153
+ writeFileSync(join(providerDir, 'pyproject.toml'), '[build-system]\n');
154
+ }
155
+ for (const providerFile of providerFiles) {
156
+ writeFileSync(join(fixtureDir, 'providers', providerFile), 'not a provider package\n');
157
+ }
158
+
159
+ const result = spawnSync('make', ['-f', pythonMakefilePath, 'build'], {
160
+ cwd: fixtureDir,
161
+ encoding: 'utf8',
162
+ env: {
163
+ ...process.env,
164
+ BUILD_LOG: buildLogPath,
165
+ FAILING_PROVIDER: failingProvider ? `providers/${failingProvider}` : '',
166
+ },
167
+ });
168
+
169
+ return {
170
+ ...result,
171
+ invocations: readFileSync(buildLogPath, 'utf8').trim().split('\n'),
172
+ };
173
+ } finally {
174
+ rmSync(fixtureDir, { recursive: true, force: true });
175
+ }
176
}
177
178
{
101
- const directVersion = readPythonSdkVersions(['| Python `composio` | `9.9.9` |']);
102
- const versionWithPrevious = readPythonSdkVersions([
179
+ const result = runPythonBuildFixture({
180
+ providers: ['valid'],
181
+ providerFiles: ['AGENTS.md'],
182
+ });
183
+
184
+ if (result.status !== 0) {
185
+ throw new Error(
186
+ `Python package build fixture failed unexpectedly\nstdout:\n${result.stdout}\nstderr:\n${result.stderr}`
187
+ );
188
+ }
189
+ if (result.invocations.includes('providers/AGENTS.md')) {
190
+ throw new Error('Python package build must skip non-provider files under python/providers');
191
+ }
192
+ if (!result.invocations.includes('providers/valid')) {
193
+ throw new Error('Python package build must include provider directories with pyproject.toml');
194
+ }
195
+}
196
+
197
+{
198
+ const result = runPythonBuildFixture({
199
+ providers: ['a-failing', 'z-valid'],
200
+ failingProvider: 'a-failing',
201
+ });
202
+
203
+ if (result.status === 0) {
204
+ throw new Error('Python package build must fail when a provider build fails');
205
+ }
206
+ if (!result.invocations.includes('providers/a-failing')) {
207
+ throw new Error('Python package build fixture did not exercise the failing provider');
208
+ }
209
+ if (result.invocations.includes('providers/z-valid')) {
210
+ throw new Error('Python package build must stop after the first provider failure');
211
+ }
212
+}
213
+
214
+{
215
+ const directVersion = readSdkVersions(['| Python `composio` | `9.9.9` |']);
216
+ const versionWithPrevious = readSdkVersions([
217
'| Python `composio` | v9.9.8 | **v9.9.9** |',
218
]);
105
- const previousVersionOnly = readPythonSdkVersions([
219
+ const previousVersionOnly = readSdkVersions([
220
'| Python `composio` | v9.9.9 | **v9.9.10** |',
221
]);
108
- const pep440Versions = readPythonSdkVersions([
222
+ const pep440Versions = readSdkVersions([
223
'| Python `composio` | `9.9.9rc1` |',
224
'| Python `composio` | `9.9.9.post1` |',
225
'| Python `composio` | `9.9.9.dev1` |',
261
262
// --- Python release metadata: package version, runtime version, and docs changelog must agree ---
263
264
+if (!pythonReleaseWorkflow.includes('run: pnpm test:release-workflow')) {
265
+ throw new Error('py.release.yml must validate release metadata before publishing');
266
+}
267
+
268
{
269
const pythonVersion = readPyprojectVersion(pythonPyproject, 'python/pyproject.toml version');
270
const runtimeVersion = requireMatch(
279
);
280
}
281
164
- const documentedPythonVersions = readDocumentedPythonSdkVersions();
282
+ const documentedPythonVersions = readDocumentedSdkVersions('Python `composio`');
283
if (!documentedPythonVersions.has(pythonVersion)) {
284
throw new Error(
285
`docs/content/changelog must document the current Python package version (${pythonVersion})`
295
import.meta.url
296
);
297
const setupPath = new URL(`../python/providers/${entry.name}/setup.py`, import.meta.url);
180
- if (!existsSync(pyprojectPath) || !existsSync(setupPath)) continue;
298
+ if (!existsSync(pyprojectPath)) continue;
299
300
const providerPyprojectVersion = readPyprojectVersion(
301
readFileSync(pyprojectPath, 'utf8'),
302
`python/providers/${entry.name}/pyproject.toml version`
303
);
186
- const providerSetupVersion = requireMatch(
187
- readFileSync(setupPath, 'utf8'),
188
- /version\s*=\s*"([^"]+)"/,
189
- `python/providers/${entry.name}/setup.py version`
190
- );
191
-
304
if (providerPyprojectVersion !== pythonVersion) {
305
throw new Error(
306
`python/providers/${entry.name}/pyproject.toml must match python/pyproject.toml (${providerPyprojectVersion} !== ${pythonVersion})`
307
);
308
}
309
+
310
+ if (!existsSync(setupPath)) continue;
311
+
312
+ const providerSetupVersion = requireMatch(
313
+ readFileSync(setupPath, 'utf8'),
314
+ /version\s*=\s*"([^"]+)"/,
315
+ `python/providers/${entry.name}/setup.py version`
316
+ );
317
if (providerSetupVersion !== pythonVersion) {
318
throw new Error(
319
`python/providers/${entry.name}/setup.py must match python/pyproject.toml (${providerSetupVersion} !== ${pythonVersion})`
322
}
323
}
324
325
+{
326
+ const documentedTsCoreVersions = readDocumentedSdkVersions('TypeScript `@composio/core`');
327
+ if (!documentedTsCoreVersions.has(tsCorePackageJson.version)) {
328
+ throw new Error(
329
+ `docs/content/changelog must document the current TypeScript core package version (${tsCorePackageJson.version})`
330
+ );
331
+ }
332
+}
333
+
334
if (!releaseScript.includes('pnpm changeset publish')) {
335
throw new Error('release script must still publish non-CLI changeset packages');
336
}