Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
| 1 | #!/usr/bin/env node |
| 2 | |
| 3 | import { readFileSync } from 'node:fs'; |
| 4 | import { execFileSync } from 'node:child_process'; |
| 5 | import { getPackages } from '@manypkg/get-packages'; |
| 6 | import { dirname, resolve } from 'node:path'; |
| 7 | import { fileURLToPath } from 'node:url'; |
| 8 | import readChangesets from '@changesets/read'; |
| 9 | |
| 10 | const scriptPath = fileURLToPath(import.meta.url); |
| 11 | const repositoryRoot = resolve(dirname(scriptPath), '../..'); |
| 12 | |
| 13 | export function findIgnoredChangesetReleases(changesetStatus, ignoredPackages) { |
| 14 | const ignored = new Set(ignoredPackages); |
| 15 | |
| 16 | return (changesetStatus.changesets ?? []).flatMap(changeset => |
| 17 | (changeset.releases ?? []) |
| 18 | .filter(release => ignored.has(release.name)) |
| 19 | .map(release => ({ changeset: changeset.id, package: release.name })) |
| 20 | ); |
| 21 | } |
| 22 | |
| 23 | export function missingReleaseNotes(changedPaths, changesets, packages, exemption = '') { |
| 24 | if (/<!--\s*sdk-release-note-exempt:\s*(.{20,}?)\s*-->/s.test(exemption)) return []; |
| 25 | const required = new Set(); |
| 26 | for (const path of changedPaths) { |
| 27 | if ( |
| 28 | /(?:^|\/)(?:tests?|integration_tests?|__tests__|fixtures?|__fixtures__|examples|scripts)(?:\/|$)|(?:\.test|\.spec)\.|(?:^|\/)test_[^/]*\.py$|_test\.py$|(?:^|\/)(?:AGENTS\.md|CHANGELOG\.md|README\.md)$/.test( |
| 29 | path |
| 30 | ) |
| 31 | ) |
| 32 | continue; |
| 33 | if ( |
| 34 | /^python\/(?:composio\/.*\.pyi?|providers\/[^/]+\/(?:composio_[^/]+\/.*\.pyi?|pyproject\.toml|setup\.py)|pyproject\.toml|setup\.py)$/.test( |
| 35 | path |
| 36 | ) |
| 37 | ) |
| 38 | required.add('@composio/python-sdk'); |
| 39 | for (const pkg of packages) { |
| 40 | if ( |
| 41 | !pkg.private && |
| 42 | pkg.name !== '@composio/cli' && |
| 43 | path.startsWith(`${pkg.directory}/`) && |
| 44 | /\.(?:ts|tsx|js|mjs|json)$/.test(path) |
| 45 | ) |
| 46 | required.add(pkg.name); |
| 47 | } |
| 48 | } |
| 49 | const covered = new Set( |
| 50 | changesets |
| 51 | .filter(note => changedPaths.includes(`.changeset/${note.id}.md`)) |
| 52 | .flatMap(note => |
| 53 | note.releases |
| 54 | .filter(entry => ['patch', 'minor', 'major'].includes(entry.type)) |
| 55 | .map(entry => entry.name) |
| 56 | ) |
| 57 | ); |
| 58 | return [...required].filter(name => !covered.has(name)).sort(); |
| 59 | } |
| 60 | |
| 61 | export async function validateChangesets( |
| 62 | cwd = repositoryRoot, |
| 63 | base = process.env.SDK_RELEASE_NOTE_BASE |
| 64 | ) { |
| 65 | const config = JSON.parse(readFileSync(resolve(cwd, '.changeset/config.json'), 'utf8')); |
| 66 | const changesets = await readChangesets(cwd); |
| 67 | if (base) { |
| 68 | if (!/^[a-zA-Z0-9_./-]+$/.test(base)) throw new Error('Invalid release-note comparison base'); |
| 69 | const paths = execFileSync('git', ['diff', '--name-only', `${base}...HEAD`], { |
| 70 | cwd, |
| 71 | encoding: 'utf8', |
| 72 | }) |
| 73 | .trim() |
| 74 | .split('\n'); |
| 75 | const { packages } = await getPackages(cwd); |
| 76 | const missing = missingReleaseNotes( |
| 77 | paths, |
| 78 | changesets, |
| 79 | packages.map(pkg => ({ |
| 80 | name: pkg.packageJson.name, |
| 81 | private: pkg.packageJson.private, |
| 82 | directory: pkg.dir.slice(cwd.length + 1), |
| 83 | })), |
| 84 | process.env.SDK_RELEASE_PR_BODY ?? '' |
| 85 | ); |
| 86 | if (missing.length) |
| 87 | throw new Error( |
| 88 | `SDK behavior changes require release notes for: ${missing.join(', ')}. Add a Changeset or explain the public-behavior exemption in the PR description.` |
| 89 | ); |
| 90 | } |
| 91 | const violations = findIgnoredChangesetReleases({ changesets }, config.ignore ?? []); |
| 92 | |
| 93 | if (violations.length > 0) { |
| 94 | const details = violations |
| 95 | .map(({ changeset, package: packageName }) => `- ${changeset}: ${packageName}`) |
| 96 | .join('\n'); |
| 97 | |
| 98 | throw new Error( |
| 99 | [ |
| 100 | 'Pending changesets must not target packages listed in .changeset/config.json#ignore.', |
| 101 | details, |
| 102 | '', |
| 103 | 'An ignored-package changeset makes changesets/action enter version-PR mode, but', |
| 104 | '`changeset version` emits no commit. The release job then fails while trying to', |
| 105 | 'open a pull request with no commits. Remove the changeset, or remove the package', |
| 106 | 'from the ignore list when intentionally restoring its Changesets release flow.', |
| 107 | ].join('\n') |
| 108 | ); |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | if (resolve(process.argv[1] ?? '') === scriptPath) { |
| 113 | try { |
| 114 | await validateChangesets(); |
| 115 | console.log('changeset validation passed'); |
| 116 | } catch (error) { |
| 117 | console.error(error instanceof Error ? error.message : error); |
| 118 | process.exitCode = 1; |
| 119 | } |
| 120 | } |