diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS deleted file mode 100644 index 3812494d18..0000000000 --- a/.github/CODEOWNERS +++ /dev/null @@ -1,3 +0,0 @@ -/.github/ @ccurme @eyurtsev @mdrxy -/libs/core/ @eyurtsev -/libs/partners/ @ccurme @mdrxy diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index a1f0f2b61d..bf8618b1b6 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -1,48 +1,3 @@ -Fixes # + ---- - - - -Read the full contributing guidelines: https://docs.langchain.com/oss/python/contributing/overview - -> **All contributions must be in English.** See the [language policy](https://docs.langchain.com/oss/python/contributing/overview#language-policy). - -If you paste a large clearly AI generated description here your PR may be IGNORED or CLOSED! - -Thank you for contributing to LangChain! Follow these steps to have your pull request considered as ready for review. - -1. PR title: Should follow the format: TYPE(SCOPE): DESCRIPTION - - - Examples: - - fix(anthropic): resolve flag parsing error - - feat(core): add multi-tenant support - - test(openai): update API usage tests - - Allowed TYPE and SCOPE values: https://github.com/langchain-ai/langchain/blob/master/.github/workflows/pr_lint.yml#L15-L33 - -2. PR description: - - - Write 1-2 sentences that make the change easy to understand: who benefits, what problem they had, and how this solves it. Prefer a simple user story over a long summary. - - The `Fixes #xx` line at the top is **required** for external contributions — update the issue number and keep the keyword. This links your PR to the approved issue and auto-closes it on merge. - - If there are any breaking changes, please clearly describe them. - - If this PR depends on another PR being merged first, please include "Depends on #PR_NUMBER" in the description. - -## Release note - - -3. Run `make format`, `make lint` and `make test` from the root of the package(s) you've modified. - - - We will not consider a PR unless these three are passing in CI. - -4. How did you verify your code works? - -Additional guidelines: - - - All external PRs must link to an issue or discussion where a solution has been approved by a maintainer, and you must be assigned to that issue. PRs without prior approval will be closed. - - PRs should not touch more than one package unless absolutely necessary. - - Do not update the `uv.lock` files or add dependencies to `pyproject.toml` files (even optional ones) unless you have explicit permission to do so by a maintainer. - -## Social handles (optional) - -Twitter: @ -LinkedIn: https://linkedin.com/in/ +What changed and why. diff --git a/.github/dependabot.yml b/.github/dependabot.yml index fdafc60d01..c89c3a992c 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -24,50 +24,7 @@ updates: - package-ecosystem: "uv" directories: - - "/libs/core/" - - "/libs/langchain/" - - "/libs/langchain_v1/" - schedule: - interval: "monthly" - versioning-strategy: increase - ignore: - - dependency-name: "langchain-core" - - dependency-name: "langchain" - - dependency-name: "langchain-classic" - - dependency-name: "langchain-text-splitters" - - dependency-name: "langchain-tests" - - dependency-name: "langchain-model-profiles" - groups: - minor-and-patch: - patterns: - - "*" - update-types: - - "minor" - - "patch" - major: - patterns: - - "*" - update-types: - - "major" - - - package-ecosystem: "uv" - directories: - - "/libs/partners/anthropic/" - - "/libs/partners/chroma/" - - "/libs/partners/deepseek/" - - "/libs/partners/exa/" - - "/libs/partners/fireworks/" - - "/libs/partners/groq/" - - "/libs/partners/huggingface/" - - "/libs/partners/mistralai/" - - "/libs/partners/nomic/" - - "/libs/partners/ollama/" - - "/libs/partners/openai/" - - "/libs/partners/openrouter/" - "/libs/partners/decodo/" - - "/libs/partners/perplexity/" - - "/libs/partners/qdrant/" - - "/libs/partners/xai/" schedule: interval: "monthly" versioning-strategy: increase @@ -90,51 +47,3 @@ updates: - "*" update-types: - "major" - - - package-ecosystem: "uv" - directories: - - "/libs/text-splitters/" - - "/libs/standard-tests/" - - "/libs/model-profiles/" - schedule: - interval: "monthly" - versioning-strategy: increase - ignore: - - dependency-name: "langchain-core" - - dependency-name: "langchain" - - dependency-name: "langchain-classic" - - dependency-name: "langchain-text-splitters" - - dependency-name: "langchain-tests" - - dependency-name: "langchain-model-profiles" - groups: - minor-and-patch: - patterns: - - "*" - update-types: - - "minor" - - "patch" - major: - patterns: - - "*" - update-types: - - "major" - - - - package-ecosystem: "docker" - directories: - - "/.devcontainer/" - - "/libs/langchain/" - schedule: - interval: "monthly" - groups: - minor-and-patch: - patterns: - - "*" - update-types: - - "minor" - - "patch" - major: - patterns: - - "*" - update-types: - - "major" diff --git a/.github/scripts/check_extras_sync.py b/.github/scripts/check_extras_sync.py deleted file mode 100644 index 8d2c4bd50a..0000000000 --- a/.github/scripts/check_extras_sync.py +++ /dev/null @@ -1,118 +0,0 @@ -"""Check that optional extras stay in sync with required dependencies. - -When a package appears in both [project.dependencies] and -[project.optional-dependencies], we ensure their version constraints match. -This prevents silent version drift (e.g. bumping a required dep but -forgetting the corresponding extra). -""" - -import sys -import tomllib -from pathlib import Path -from re import compile as re_compile - -# Matches the package name at the start of a PEP 508 dependency string. -# Stops at the first non-name character; downstream code is responsible for -# stripping extras (`[...]`) and env markers (`; ...`) from the remainder. -_NAME_RE = re_compile(r"^([A-Za-z0-9]([A-Za-z0-9._-]*[A-Za-z0-9])?)") - - -def _normalize(name: str) -> str: - """Normalize a package name for equality comparison. - - Lowercases and maps `-` and `.` to `_`. Looser than PEP 503 - (which uses `-` and collapses runs), but sufficient for matching the - same package across two PEP 508 strings. - - Returns: - Lowercased, underscore-normalized package name. - """ - return name.lower().replace("-", "_").replace(".", "_") - - -def _parse_dep(dep: str) -> tuple[str, str]: - """Return `(normalized_name, version_spec)` from a PEP 508 string. - - Strips extras (`pkg[async]`), environment markers (`; python_version ...`), - URL specifiers (`pkg @ git+...`), and whitespace so the returned - `version_spec` is directly comparable between a required and optional dep. - - Returns: - Tuple of normalized package name and bare version specifier. - - Raises: - ValueError: If the dependency string cannot be parsed. - """ - match = _NAME_RE.match(dep) - if not match: - msg = f"Cannot parse dependency: {dep!r}" - raise ValueError(msg) - name = match.group(1) - rest = dep[match.end() :].strip() - - if rest.startswith("["): - close = rest.find("]") - if close == -1: - msg = f"Unclosed extras bracket in dependency: {dep!r}" - raise ValueError(msg) - rest = rest[close + 1 :].strip() - - if ";" in rest: - rest = rest.split(";", 1)[0].strip() - - # URL specifiers have no comparable version; treat as unconstrained. - if rest.startswith("@"): - rest = "" - - rest = " ".join(rest.split()) - return _normalize(name), rest - - -def main(pyproject_path: Path) -> int: - """Check extras sync and return `0` on pass, `1` on mismatch or parse error.""" - with pyproject_path.open("rb") as f: - data = tomllib.load(f) - - required: dict[str, str] = {} - for dep in data.get("project", {}).get("dependencies", []): - try: - name, spec = _parse_dep(dep) - except ValueError as e: - print(f"::error file={pyproject_path}::{e}") - return 1 - required[name] = spec - - optional = data.get("project", {}).get("optional-dependencies", {}) - if not optional: - return 0 - - mismatches: list[str] = [] - for group, deps in optional.items(): - for dep in deps: - try: - name, spec = _parse_dep(dep) - except ValueError as e: - print(f"::error file={pyproject_path}::{e}") - return 1 - if name in required and spec != required[name]: - mismatches.append( - f" [{group}] {name}: extra has '{spec}' " - f"but required dep has '{required[name]}'" - ) - - if mismatches: - print(f"Extra / required dependency version mismatch in {pyproject_path}:") - print("\n".join(mismatches)) - print( - "\nUpdate the optional extras in [project.optional-dependencies] " - "to match [project.dependencies]." - ) - return 1 - - print(f"All extras in {pyproject_path} are in sync with required dependencies.") - return 0 - - -if __name__ == "__main__": - path = Path(sys.argv[1]) if len(sys.argv) > 1 else Path("pyproject.toml") - raise SystemExit(main(path)) diff --git a/.github/scripts/check_prerelease_dependencies.py b/.github/scripts/check_prerelease_dependencies.py deleted file mode 100644 index f445ede08f..0000000000 --- a/.github/scripts/check_prerelease_dependencies.py +++ /dev/null @@ -1,36 +0,0 @@ -"""Check that no dependencies allow prereleases unless we're releasing a prerelease.""" - -import sys - -import tomllib - -if __name__ == "__main__": - # Get the TOML file path from the command line argument - toml_file = sys.argv[1] - - with open(toml_file, "rb") as file: - toml_data = tomllib.load(file) - - # See if we're releasing an rc or dev version - version = toml_data["project"]["version"] - releasing_rc = "rc" in version or "dev" in version - - # If not, iterate through dependencies and make sure none allow prereleases - if not releasing_rc: - dependencies = toml_data["project"]["dependencies"] - for dep_version in dependencies: - dep_version_string = ( - dep_version["version"] if isinstance(dep_version, dict) else dep_version - ) - - if "rc" in dep_version_string: - raise ValueError( - f"Dependency {dep_version} has a prerelease version. Please remove this." - ) - - if isinstance(dep_version, dict) and dep_version.get( - "allow-prereleases", False - ): - raise ValueError( - f"Dependency {dep_version} has allow-prereleases set to true. Please remove this." - ) diff --git a/.github/scripts/pr-labeler-config.json b/.github/scripts/pr-labeler-config.json deleted file mode 100644 index 507a87ff85..0000000000 --- a/.github/scripts/pr-labeler-config.json +++ /dev/null @@ -1,86 +0,0 @@ -{ - "trustedThreshold": 5, - "labelColor": "b76e79", - "sizeThresholds": [ - { "label": "size: XS", "max": 50 }, - { "label": "size: S", "max": 200 }, - { "label": "size: M", "max": 500 }, - { "label": "size: L", "max": 1000 }, - { "label": "size: XL" } - ], - "excludedFiles": ["uv.lock"], - "excludedPaths": ["docs/"], - "typeToLabel": { - "feat": "feature", - "fix": "fix", - "docs": "documentation", - "style": "linting", - "refactor": "refactor", - "perf": "performance", - "test": "tests", - "build": "infra", - "ci": "infra", - "chore": "infra", - "revert": "revert", - "release": "release", - "hotfix": "hotfix", - "breaking": "breaking" - }, - "scopeToLabel": { - "core": "core", - "langchain": "langchain", - "langchain-classic": "langchain-classic", - "model-profiles": "model-profiles", - "standard-tests": "standard-tests", - "text-splitters": "text-splitters", - "anthropic": "anthropic", - "chroma": "chroma", - "deepseek": "deepseek", - "exa": "exa", - "fireworks": "fireworks", - "groq": "groq", - "huggingface": "huggingface", - "mistralai": "mistralai", - "nomic": "nomic", - "ollama": "ollama", - "openai": "openai", - "openrouter": "openrouter", - "decodo": "decodo", - "perplexity": "perplexity", - "qdrant": "qdrant", - "xai": "xai", - "deps": "dependencies", - "docs": "documentation", - "infra": "infra" - }, - "fileRules": [ - { "label": "core", "prefix": "libs/core/", "skipExcludedFiles": true }, - { "label": "langchain-classic", "prefix": "libs/langchain/", "skipExcludedFiles": true }, - { "label": "langchain", "prefix": "libs/langchain_v1/", "skipExcludedFiles": true }, - { "label": "standard-tests", "prefix": "libs/standard-tests/", "skipExcludedFiles": true }, - { "label": "model-profiles", "prefix": "libs/model-profiles/", "skipExcludedFiles": true }, - { "label": "text-splitters", "prefix": "libs/text-splitters/", "skipExcludedFiles": true }, - { "label": "integration", "prefix": "libs/partners/", "skipExcludedFiles": true }, - { "label": "anthropic", "prefix": "libs/partners/anthropic/", "skipExcludedFiles": true }, - { "label": "chroma", "prefix": "libs/partners/chroma/", "skipExcludedFiles": true }, - { "label": "deepseek", "prefix": "libs/partners/deepseek/", "skipExcludedFiles": true }, - { "label": "exa", "prefix": "libs/partners/exa/", "skipExcludedFiles": true }, - { "label": "fireworks", "prefix": "libs/partners/fireworks/", "skipExcludedFiles": true }, - { "label": "groq", "prefix": "libs/partners/groq/", "skipExcludedFiles": true }, - { "label": "huggingface", "prefix": "libs/partners/huggingface/", "skipExcludedFiles": true }, - { "label": "mistralai", "prefix": "libs/partners/mistralai/", "skipExcludedFiles": true }, - { "label": "nomic", "prefix": "libs/partners/nomic/", "skipExcludedFiles": true }, - { "label": "ollama", "prefix": "libs/partners/ollama/", "skipExcludedFiles": true }, - { "label": "openai", "prefix": "libs/partners/openai/", "skipExcludedFiles": true }, - { "label": "openrouter", "prefix": "libs/partners/openrouter/", "skipExcludedFiles": true }, - { "label": "decodo", "prefix": "libs/partners/decodo/", "skipExcludedFiles": true }, - { "label": "perplexity", "prefix": "libs/partners/perplexity/", "skipExcludedFiles": true }, - { "label": "qdrant", "prefix": "libs/partners/qdrant/", "skipExcludedFiles": true }, - { "label": "xai", "prefix": "libs/partners/xai/", "skipExcludedFiles": true }, - { "label": "github_actions", "prefix": ".github/workflows/" }, - { "label": "github_actions", "prefix": ".github/actions/" }, - { "label": "dependencies", "suffix": "pyproject.toml" }, - { "label": "dependencies", "exact": "uv.lock" }, - { "label": "dependencies", "pattern": "(?:^|/)requirements[^/]*\\.txt$" } - ] -} diff --git a/.github/scripts/pr-labeler.js b/.github/scripts/pr-labeler.js deleted file mode 100644 index f2f252dff4..0000000000 --- a/.github/scripts/pr-labeler.js +++ /dev/null @@ -1,278 +0,0 @@ -// Shared helpers for pr_labeler.yml and tag-external-issues.yml. -// -// Usage from actions/github-script (requires actions/checkout first): -// const { h } = require('./.github/scripts/pr-labeler.js').loadAndInit(github, owner, repo, core); - -const fs = require('fs'); -const path = require('path'); - -function loadConfig() { - const configPath = path.join(__dirname, 'pr-labeler-config.json'); - let raw; - try { - raw = fs.readFileSync(configPath, 'utf8'); - } catch (e) { - throw new Error(`Failed to read ${configPath}: ${e.message}`); - } - let config; - try { - config = JSON.parse(raw); - } catch (e) { - throw new Error(`Failed to parse pr-labeler-config.json: ${e.message}`); - } - const required = [ - 'labelColor', 'sizeThresholds', 'fileRules', - 'typeToLabel', 'scopeToLabel', 'trustedThreshold', - 'excludedFiles', 'excludedPaths', - ]; - const missing = required.filter(k => !(k in config)); - if (missing.length > 0) { - throw new Error(`pr-labeler-config.json missing required keys: ${missing.join(', ')}`); - } - return config; -} - -function init(github, owner, repo, config, core) { - if (!core) { - throw new Error('init() requires a `core` parameter (e.g., from actions/github-script)'); - } - const { - trustedThreshold, - labelColor, - sizeThresholds, - scopeToLabel, - typeToLabel, - fileRules: fileRulesDef, - excludedFiles, - excludedPaths, - } = config; - - const sizeLabels = sizeThresholds.map(t => t.label); - const allTypeLabels = [...new Set(Object.values(typeToLabel))]; - const tierLabels = ['new-contributor', 'trusted-contributor']; - - // ── Label management ────────────────────────────────────────────── - - async function ensureLabel(name, color = labelColor) { - try { - await github.rest.issues.getLabel({ owner, repo, name }); - } catch (e) { - if (e.status !== 404) throw e; - try { - await github.rest.issues.createLabel({ owner, repo, name, color }); - } catch (createErr) { - // 422 = label created by a concurrent run between our get and create - if (createErr.status !== 422) throw createErr; - core.info(`Label "${name}" creation returned 422 (likely already exists)`); - } - } - } - - // ── Size calculation ────────────────────────────────────────────── - - function getSizeLabel(totalChanged) { - for (const t of sizeThresholds) { - if (t.max != null && totalChanged < t.max) return t.label; - } - // Last entry has no max — it's the catch-all - return sizeThresholds[sizeThresholds.length - 1].label; - } - - function computeSize(files) { - const excluded = new Set(excludedFiles); - const totalChanged = files.reduce((sum, f) => { - const p = f.filename ?? ''; - const base = p.split('/').pop(); - if (excluded.has(base)) return sum; - for (const prefix of excludedPaths) { - if (p.startsWith(prefix)) return sum; - } - return sum + (f.additions ?? 0) + (f.deletions ?? 0); - }, 0); - return { totalChanged, sizeLabel: getSizeLabel(totalChanged) }; - } - - // ── File-based labels ───────────────────────────────────────────── - - function buildFileRules() { - return fileRulesDef.map((rule, i) => { - let test; - if (rule.prefix) test = p => p.startsWith(rule.prefix); - else if (rule.suffix) test = p => p.endsWith(rule.suffix); - else if (rule.exact) test = p => p === rule.exact; - else if (rule.pattern) { - const re = new RegExp(rule.pattern); - test = p => re.test(p); - } else { - throw new Error( - `fileRules[${i}] (label: "${rule.label}") has no recognized matcher ` + - `(expected one of: prefix, suffix, exact, pattern)` - ); - } - return { label: rule.label, test, skipExcluded: !!rule.skipExcludedFiles }; - }); - } - - function matchFileLabels(files, fileRules) { - const rules = fileRules || buildFileRules(); - const excluded = new Set(excludedFiles); - const labels = new Set(); - for (const rule of rules) { - // skipExcluded: ignore files whose basename is in the top-level - // "excludedFiles" list (e.g. uv.lock) so lockfile-only changes - // don't trigger package labels. - const candidates = rule.skipExcluded - ? files.filter(f => !excluded.has((f.filename ?? '').split('/').pop())) - : files; - if (candidates.some(f => rule.test(f.filename ?? ''))) { - labels.add(rule.label); - } - } - return labels; - } - - // ── Title-based labels ──────────────────────────────────────────── - - function matchTitleLabels(title) { - const labels = new Set(); - const m = (title ?? '').match(/^(\w+)(?:\(([^)]+)\))?(!)?:/); - if (!m) return { labels, type: null, typeLabel: null, scopes: [], breaking: false }; - - const type = m[1].toLowerCase(); - const scopeStr = m[2] ?? ''; - const breaking = !!m[3]; - - const typeLabel = typeToLabel[type] || null; - if (typeLabel) labels.add(typeLabel); - if (breaking) labels.add('breaking'); - - const scopes = scopeStr.split(',').map(s => s.trim()).filter(Boolean); - for (const scope of scopes) { - const sl = scopeToLabel[scope]; - if (sl) labels.add(sl); - } - - return { labels, type, typeLabel, scopes, breaking }; - } - - // ── Org membership ──────────────────────────────────────────────── - - async function checkMembership(author, userType) { - if (userType === 'Bot') { - console.log(`${author} is a Bot — treating as internal`); - return { isExternal: false }; - } - - try { - const membership = await github.rest.orgs.getMembershipForUser({ - org: 'langchain-ai', - username: author, - }); - const isExternal = membership.data.state !== 'active'; - console.log( - isExternal - ? `${author} has pending membership — treating as external` - : `${author} is an active member of langchain-ai`, - ); - return { isExternal }; - } catch (e) { - if (e.status === 404) { - console.log(`${author} is not a member of langchain-ai`); - return { isExternal: true }; - } - // Non-404 errors (rate limit, auth failure, server error) must not - // silently default to external — rethrow to fail the step. - throw new Error( - `Membership check failed for ${author} (${e.status}): ${e.message}`, - ); - } - } - - // ── Contributor analysis ────────────────────────────────────────── - - async function getContributorInfo(contributorCache, author, userType) { - if (contributorCache.has(author)) return contributorCache.get(author); - - const { isExternal } = await checkMembership(author, userType); - - let mergedCount = null; - if (isExternal) { - try { - const result = await github.rest.search.issuesAndPullRequests({ - q: `repo:${owner}/${repo} is:pr is:merged author:"${author}"`, - per_page: 1, - }); - mergedCount = result?.data?.total_count ?? null; - } catch (e) { - if (e?.status !== 422) throw e; - core.warning(`Search failed for ${author}; skipping tier.`); - } - } - - const info = { isExternal, mergedCount }; - contributorCache.set(author, info); - return info; - } - - // ── Tier label resolution ─────────────────────────────────────────── - - async function applyTierLabel(issueNumber, author, { skipNewContributor = false } = {}) { - let mergedCount; - try { - const result = await github.rest.search.issuesAndPullRequests({ - q: `repo:${owner}/${repo} is:pr is:merged author:"${author}"`, - per_page: 1, - }); - mergedCount = result?.data?.total_count; - } catch (error) { - if (error?.status !== 422) throw error; - core.warning(`Search failed for ${author}; skipping tier label.`); - return; - } - - if (mergedCount == null) { - core.warning(`Search response missing total_count for ${author}; skipping tier label.`); - return; - } - - let tierLabel = null; - if (mergedCount >= trustedThreshold) tierLabel = 'trusted-contributor'; - else if (mergedCount === 0 && !skipNewContributor) tierLabel = 'new-contributor'; - - if (tierLabel) { - await ensureLabel(tierLabel); - await github.rest.issues.addLabels({ - owner, repo, issue_number: issueNumber, labels: [tierLabel], - }); - console.log(`Applied '${tierLabel}' to #${issueNumber} (${mergedCount} merged PRs)`); - } else { - console.log(`No tier label for ${author} (${mergedCount} merged PRs)`); - } - - return tierLabel; - } - - return { - ensureLabel, - getSizeLabel, - computeSize, - buildFileRules, - matchFileLabels, - matchTitleLabels, - allTypeLabels, - checkMembership, - getContributorInfo, - applyTierLabel, - sizeLabels, - tierLabels, - trustedThreshold, - labelColor, - }; -} - -function loadAndInit(github, owner, repo, core) { - const config = loadConfig(); - return { config, h: init(github, owner, repo, config, core) }; -} - -module.exports = { loadConfig, init, loadAndInit }; diff --git a/.github/scripts/test_release_options.py b/.github/scripts/test_release_options.py deleted file mode 100644 index 47cc4245f0..0000000000 --- a/.github/scripts/test_release_options.py +++ /dev/null @@ -1,66 +0,0 @@ -"""Verify _release.yml dropdown options match actual package directories. - -Dropdown options are short names (e.g. `openai`, `core`). The workflow's -`EFFECTIVE_WORKING_DIR` expression re-adds the `libs/` prefix for top-level -packages and `libs/partners/` for everything else. This test reconstructs the -full path for each short name and compares against packages on disk. -""" - -from pathlib import Path - -import yaml - -REPO_ROOT = Path(__file__).resolve().parents[2] - -# Keep in sync with the non-partner allowlist in `EFFECTIVE_WORKING_DIR` -# in `.github/workflows/_release.yml`. -TOP_LEVEL_PACKAGES = frozenset( - {"core", "langchain", "langchain_v1", "text-splitters", "standard-tests", "model-profiles"} -) - - -def _get_release_options() -> list[str]: - workflow = REPO_ROOT / ".github" / "workflows" / "_release.yml" - with open(workflow) as f: - data = yaml.safe_load(f) - try: - # PyYAML (YAML 1.1) parses the bare key `on` as boolean True - return data[True]["workflow_dispatch"]["inputs"]["working-directory"]["options"] - except (KeyError, TypeError) as e: - msg = f"Could not find workflow_dispatch options in {workflow}: {e}" - raise AssertionError(msg) from e - - -def _expand_option(option: str) -> str: - if option in TOP_LEVEL_PACKAGES: - return f"libs/{option}" - return f"libs/partners/{option}" - - -def _get_package_dirs() -> set[str]: - libs = REPO_ROOT / "libs" - dirs: set[str] = set() - # Top-level packages (libs/core, libs/langchain, etc.) - for p in libs.iterdir(): - if p.is_dir() and (p / "pyproject.toml").exists(): - dirs.add(f"libs/{p.name}") - # Partner packages (libs/partners/*) - partners = libs / "partners" - if partners.exists(): - for p in partners.iterdir(): - if p.is_dir() and (p / "pyproject.toml").exists(): - dirs.add(f"libs/partners/{p.name}") - return dirs - - -def test_release_options_match_packages() -> None: - options = {_expand_option(o) for o in _get_release_options()} - packages = _get_package_dirs() - missing_from_dropdown = packages - options - extra_in_dropdown = options - packages - assert not missing_from_dropdown, ( - f"Packages on disk missing from _release.yml dropdown: {missing_from_dropdown}" - ) - assert not extra_in_dropdown, ( - f"Dropdown options with no matching package directory: {extra_in_dropdown}" - ) diff --git a/.github/tools/git-restore-mtime b/.github/tools/git-restore-mtime deleted file mode 100755 index 05c25ed635..0000000000 --- a/.github/tools/git-restore-mtime +++ /dev/null @@ -1,756 +0,0 @@ -#!/usr/bin/env python3 -# -# git-restore-mtime - Change mtime of files based on commit date of last change -# -# Copyright (C) 2012 Rodrigo Silva (MestreLion) -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. See -# -# Source: https://github.com/MestreLion/git-tools -# Version: July 13, 2023 (commit hash 5f832e72453e035fccae9d63a5056918d64476a2) -""" -Change the modification time (mtime) of files in work tree, based on the -date of the most recent commit that modified the file, including renames. - -Ignores untracked files and uncommitted deletions, additions and renames, and -by default modifications too. ---- -Useful prior to generating release tarballs, so each file is archived with a -date that is similar to the date when the file was actually last modified, -assuming the actual modification date and its commit date are close. -""" - -# TODO: -# - Add -z on git whatchanged/ls-files, so we don't deal with filename decoding -# - When Python is bumped to 3.7, use text instead of universal_newlines on subprocess -# - Update "Statistics for some large projects" with modern hardware and repositories. -# - Create a README.md for git-restore-mtime alone. It deserves extensive documentation -# - Move Statistics there -# - See git-extras as a good example on project structure and documentation - -# FIXME: -# - When current dir is outside the worktree, e.g. using --work-tree, `git ls-files` -# assume any relative pathspecs are to worktree root, not the current dir. As such, -# relative pathspecs may not work. -# - Renames are tricky: -# - R100 should not change mtime, but original name is not on filelist. Should -# track renames until a valid (A, M) mtime found and then set on current name. -# - Should set mtime for both current and original directories. -# - Check mode changes with unchanged blobs? -# - Check file (A, D) for the directory mtime is not sufficient: -# - Renames also change dir mtime, unless rename was on a parent dir -# - If most recent change of all files in a dir was a Modification (M), -# dir might not be touched at all. -# - Dirs containing only subdirectories but no direct files will also -# not be touched. They're files' [grand]parent dir, but never their dirname(). -# - Some solutions: -# - After files done, perform some dir processing for missing dirs, finding latest -# file (A, D, R) -# - Simple approach: dir mtime is the most recent child (dir or file) mtime -# - Use a virtual concept of "created at most at" to fill missing info, bubble up -# to parents and grandparents -# - When handling [grand]parent dirs, stay inside -# - Better handling of merge commits. `-m` is plain *wrong*. `-c/--cc` is perfect, but -# painfully slow. First pass without merge commits is not accurate. Maybe add a new -# `--accurate` mode for `--cc`? - -if __name__ != "__main__": - raise ImportError("{} should not be used as a module.".format(__name__)) - -import argparse -import datetime -import logging -import os.path -import shlex -import signal -import subprocess -import sys -import time - -__version__ = "2022.12+dev" - -# Update symlinks only if the platform supports not following them -UPDATE_SYMLINKS = bool(os.utime in getattr(os, "supports_follow_symlinks", [])) - -# Call os.path.normpath() only if not in a POSIX platform (Windows) -NORMALIZE_PATHS = os.path.sep != "/" - -# How many files to process in each batch when re-trying merge commits -STEPMISSING = 100 - -# (Extra) keywords for the os.utime() call performed by touch() -UTIME_KWS = {} if not UPDATE_SYMLINKS else {"follow_symlinks": False} - - -# Command-line interface ###################################################### - - -def parse_args(): - parser = argparse.ArgumentParser(description=__doc__.split("\n---")[0]) - - group = parser.add_mutually_exclusive_group() - group.add_argument( - "--quiet", - "-q", - dest="loglevel", - action="store_const", - const=logging.WARNING, - default=logging.INFO, - help="Suppress informative messages and summary statistics.", - ) - group.add_argument( - "--verbose", - "-v", - action="count", - help=""" - Print additional information for each processed file. - Specify twice to further increase verbosity. - """, - ) - - parser.add_argument( - "--cwd", - "-C", - metavar="DIRECTORY", - help=""" - Run as if %(prog)s was started in directory %(metavar)s. - This affects how --work-tree, --git-dir and PATHSPEC arguments are handled. - See 'man 1 git' or 'git --help' for more information. - """, - ) - - parser.add_argument( - "--git-dir", - dest="gitdir", - metavar="GITDIR", - help=""" - Path to the git repository, by default auto-discovered by searching - the current directory and its parents for a .git/ subdirectory. - """, - ) - - parser.add_argument( - "--work-tree", - dest="workdir", - metavar="WORKTREE", - help=""" - Path to the work tree root, by default the parent of GITDIR if it's - automatically discovered, or the current directory if GITDIR is set. - """, - ) - - parser.add_argument( - "--force", - "-f", - default=False, - action="store_true", - help=""" - Force updating files with uncommitted modifications. - Untracked files and uncommitted deletions, renames and additions are - always ignored. - """, - ) - - parser.add_argument( - "--merge", - "-m", - default=False, - action="store_true", - help=""" - Include merge commits. - Leads to more recent times and more files per commit, thus with the same - time, which may or may not be what you want. - Including merge commits may lead to fewer commits being evaluated as files - are found sooner, which can improve performance, sometimes substantially. - But as merge commits are usually huge, processing them may also take longer. - By default, merge commits are only used for files missing from regular commits. - """, - ) - - parser.add_argument( - "--first-parent", - default=False, - action="store_true", - help=""" - Consider only the first parent, the "main branch", when evaluating merge commits. - Only effective when merge commits are processed, either when --merge is - used or when finding missing files after the first regular log search. - See --skip-missing. - """, - ) - - parser.add_argument( - "--skip-missing", - "-s", - dest="missing", - default=True, - action="store_false", - help=""" - Do not try to find missing files. - If merge commits were not evaluated with --merge and some files were - not found in regular commits, by default %(prog)s searches for these - files again in the merge commits. - This option disables this retry, so files found only in merge commits - will not have their timestamp updated. - """, - ) - - parser.add_argument( - "--no-directories", - "-D", - dest="dirs", - default=True, - action="store_false", - help=""" - Do not update directory timestamps. - By default, use the time of its most recently created, renamed or deleted file. - Note that just modifying a file will NOT update its directory time. - """, - ) - - parser.add_argument( - "--test", - "-t", - default=False, - action="store_true", - help="Test run: do not actually update any file timestamp.", - ) - - parser.add_argument( - "--commit-time", - "-c", - dest="commit_time", - default=False, - action="store_true", - help="Use commit time instead of author time.", - ) - - parser.add_argument( - "--oldest-time", - "-o", - dest="reverse_order", - default=False, - action="store_true", - help=""" - Update times based on the oldest, instead of the most recent commit of a file. - This reverses the order in which the git log is processed to emulate a - file "creation" date. Note this will be inaccurate for files deleted and - re-created at later dates. - """, - ) - - parser.add_argument( - "--skip-older-than", - metavar="SECONDS", - type=int, - help=""" - Ignore files that are currently older than %(metavar)s. - Useful in workflows that assume such files already have a correct timestamp, - as it may improve performance by processing fewer files. - """, - ) - - parser.add_argument( - "--skip-older-than-commit", - "-N", - default=False, - action="store_true", - help=""" - Ignore files older than the timestamp it would be updated to. - Such files may be considered "original", likely in the author's repository. - """, - ) - - parser.add_argument( - "--unique-times", - default=False, - action="store_true", - help=""" - Set the microseconds to a unique value per commit. - Allows telling apart changes that would otherwise have identical timestamps, - as git's time accuracy is in seconds. - """, - ) - - parser.add_argument( - "pathspec", - nargs="*", - metavar="PATHSPEC", - help=""" - Only modify paths matching %(metavar)s, relative to current directory. - By default, update all but untracked files and submodules. - """, - ) - - parser.add_argument( - "--version", - "-V", - action="version", - version="%(prog)s version {version}".format(version=get_version()), - ) - - args_ = parser.parse_args() - if args_.verbose: - args_.loglevel = max(logging.TRACE, logging.DEBUG // args_.verbose) - args_.debug = args_.loglevel <= logging.DEBUG - return args_ - - -def get_version(version=__version__): - if not version.endswith("+dev"): - return version - try: - cwd = os.path.dirname(os.path.realpath(__file__)) - return Git(cwd=cwd, errors=False).describe().lstrip("v") - except Git.Error: - return "-".join((version, "unknown")) - - -# Helper functions ############################################################ - - -def setup_logging(): - """Add TRACE logging level and corresponding method, return the root logger""" - logging.TRACE = TRACE = logging.DEBUG // 2 - logging.Logger.trace = lambda _, m, *a, **k: _.log(TRACE, m, *a, **k) - return logging.getLogger() - - -def normalize(path): - r"""Normalize paths from git, handling non-ASCII characters. - - Git stores paths as UTF-8 normalization form C. - If path contains non-ASCII or non-printable characters, git outputs the UTF-8 - in octal-escaped notation, escaping double-quotes and backslashes, and then - double-quoting the whole path. - https://git-scm.com/docs/git-config#Documentation/git-config.txt-corequotePath - - This function reverts this encoding, so: - normalize(r'"Back\\slash_double\"quote_a\303\247a\303\255"') => - r'Back\slash_double"quote_açaí') - - Paths with invalid UTF-8 encoding, such as single 0x80-0xFF bytes (e.g, from - Latin1/Windows-1251 encoding) are decoded using surrogate escape, the same - method used by Python for filesystem paths. So 0xE6 ("æ" in Latin1, r'\\346' - from Git) is decoded as "\udce6". See https://peps.python.org/pep-0383/ and - https://vstinner.github.io/painful-history-python-filesystem-encoding.html - - Also see notes on `windows/non-ascii-paths.txt` about path encodings on - non-UTF-8 platforms and filesystems. - """ - if path and path[0] == '"': - # Python 2: path = path[1:-1].decode("string-escape") - # Python 3: https://stackoverflow.com/a/46650050/624066 - path = ( - path[1:-1] # Remove enclosing double quotes - .encode("latin1") # Convert to bytes, required by 'unicode-escape' - .decode("unicode-escape") # Perform the actual octal-escaping decode - .encode("latin1") # 1:1 mapping to bytes, UTF-8 encoded - .decode("utf8", "surrogateescape") - ) # Decode from UTF-8 - if NORMALIZE_PATHS: - # Make sure the slash matches the OS; for Windows we need a backslash - path = os.path.normpath(path) - return path - - -def dummy(*_args, **_kwargs): - """No-op function used in dry-run tests""" - - -def touch(path, mtime): - """The actual mtime update""" - os.utime(path, (mtime, mtime), **UTIME_KWS) - - -def touch_ns(path, mtime_ns): - """The actual mtime update, using nanoseconds for unique timestamps""" - os.utime(path, None, ns=(mtime_ns, mtime_ns), **UTIME_KWS) - - -def isodate(secs: int): - # time.localtime() accepts floats, but discards fractional part - return time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(secs)) - - -def isodate_ns(ns: int): - # for integers fromtimestamp() is equivalent and ~16% slower than isodate() - return datetime.datetime.fromtimestamp(ns / 1000000000).isoformat(sep=" ") - - -def get_mtime_ns(secs: int, idx: int): - # Time resolution for filesystems and functions: - # ext-4 and other POSIX filesystems: 1 nanosecond - # NTFS (Windows default): 100 nanoseconds - # datetime.datetime() (due to 64-bit float epoch): 1 microsecond - us = idx % 1000000 # 10**6 - return 1000 * (1000000 * secs + us) - - -def get_mtime_path(path): - return os.path.getmtime(path) - - -# Git class and parse_log(), the heart of the script ########################## - - -class Git: - def __init__(self, workdir=None, gitdir=None, cwd=None, errors=True): - self.gitcmd = ["git"] - self.errors = errors - self._proc = None - if workdir: - self.gitcmd.extend(("--work-tree", workdir)) - if gitdir: - self.gitcmd.extend(("--git-dir", gitdir)) - if cwd: - self.gitcmd.extend(("-C", cwd)) - self.workdir, self.gitdir = self._get_repo_dirs() - - def ls_files(self, paths: list = None): - return (normalize(_) for _ in self._run("ls-files --full-name", paths)) - - def ls_dirty(self, force=False): - return ( - normalize(_[3:].split(" -> ", 1)[-1]) - for _ in self._run("status --porcelain") - if _[:2] != "??" and (not force or (_[0] in ("R", "A") or _[1] == "D")) - ) - - def log( - self, - merge=False, - first_parent=False, - commit_time=False, - reverse_order=False, - paths: list = None, - ): - cmd = "whatchanged --pretty={}".format("%ct" if commit_time else "%at") - if merge: - cmd += " -m" - if first_parent: - cmd += " --first-parent" - if reverse_order: - cmd += " --reverse" - return self._run(cmd, paths) - - def describe(self): - return self._run("describe --tags", check=True)[0] - - def terminate(self): - if self._proc is None: - return - try: - self._proc.terminate() - except OSError: - # Avoid errors on OpenBSD - pass - - def _get_repo_dirs(self): - return ( - os.path.normpath(_) - for _ in self._run( - "rev-parse --show-toplevel --absolute-git-dir", check=True - ) - ) - - def _run(self, cmdstr: str, paths: list = None, output=True, check=False): - cmdlist = self.gitcmd + shlex.split(cmdstr) - if paths: - cmdlist.append("--") - cmdlist.extend(paths) - popen_args = dict(universal_newlines=True, encoding="utf8") - if not self.errors: - popen_args["stderr"] = subprocess.DEVNULL - log.trace("Executing: %s", " ".join(cmdlist)) - if not output: - return subprocess.call(cmdlist, **popen_args) - if check: - try: - stdout: str = subprocess.check_output(cmdlist, **popen_args) - return stdout.splitlines() - except subprocess.CalledProcessError as e: - raise self.Error(e.returncode, e.cmd, e.output, e.stderr) - self._proc = subprocess.Popen(cmdlist, stdout=subprocess.PIPE, **popen_args) - return (_.rstrip() for _ in self._proc.stdout) - - def __del__(self): - self.terminate() - - class Error(subprocess.CalledProcessError): - """Error from git executable""" - - -def parse_log(filelist, dirlist, stats, git, merge=False, filterlist=None): - mtime = 0 - datestr = isodate(0) - for line in git.log( - merge, args.first_parent, args.commit_time, args.reverse_order, filterlist - ): - stats["loglines"] += 1 - - # Blank line between Date and list of files - if not line: - continue - - # Date line - if line[0] != ":": # Faster than `not line.startswith(':')` - stats["commits"] += 1 - mtime = int(line) - if args.unique_times: - mtime = get_mtime_ns(mtime, stats["commits"]) - if args.debug: - datestr = isodate(mtime) - continue - - # File line: three tokens if it describes a renaming, otherwise two - tokens = line.split("\t") - - # Possible statuses: - # M: Modified (content changed) - # A: Added (created) - # D: Deleted - # T: Type changed: to/from regular file, symlinks, submodules - # R099: Renamed (moved), with % of unchanged content. 100 = pure rename - # Not possible in log: C=Copied, U=Unmerged, X=Unknown, B=pairing Broken - status = tokens[0].split(" ")[-1] - file = tokens[-1] - - # Handles non-ASCII chars and OS path separator - file = normalize(file) - - def do_file(): - if args.skip_older_than_commit and get_mtime_path(file) <= mtime: - stats["skip"] += 1 - return - if args.debug: - log.debug( - "%d\t%d\t%d\t%s\t%s", - stats["loglines"], - stats["commits"], - stats["files"], - datestr, - file, - ) - try: - touch(os.path.join(git.workdir, file), mtime) - stats["touches"] += 1 - except Exception as e: - log.error("ERROR: %s: %s", e, file) - stats["errors"] += 1 - - def do_dir(): - if args.debug: - log.debug( - "%d\t%d\t-\t%s\t%s", - stats["loglines"], - stats["commits"], - datestr, - "{}/".format(dirname or "."), - ) - try: - touch(os.path.join(git.workdir, dirname), mtime) - stats["dirtouches"] += 1 - except Exception as e: - log.error("ERROR: %s: %s", e, dirname) - stats["direrrors"] += 1 - - if file in filelist: - stats["files"] -= 1 - filelist.remove(file) - do_file() - - if args.dirs and status in ("A", "D"): - dirname = os.path.dirname(file) - if dirname in dirlist: - dirlist.remove(dirname) - do_dir() - - # All files done? - if not stats["files"]: - git.terminate() - return - - -# Main Logic ################################################################## - - -def main(): - start = time.time() # yes, Wall time. CPU time is not realistic for users. - stats = { - _: 0 - for _ in ( - "loglines", - "commits", - "touches", - "skip", - "errors", - "dirtouches", - "direrrors", - ) - } - - logging.basicConfig(level=args.loglevel, format="%(message)s") - log.trace("Arguments: %s", args) - - # First things first: Where and Who are we? - if args.cwd: - log.debug("Changing directory: %s", args.cwd) - try: - os.chdir(args.cwd) - except OSError as e: - log.critical(e) - return e.errno - # Using both os.chdir() and `git -C` is redundant, but might prevent side effects - # `git -C` alone could be enough if we make sure that: - # - all paths, including args.pathspec, are processed by git: ls-files, rev-parse - # - touch() / os.utime() path argument is always prepended with git.workdir - try: - git = Git(workdir=args.workdir, gitdir=args.gitdir, cwd=args.cwd) - except Git.Error as e: - # Not in a git repository, and git already informed user on stderr. So we just... - return e.returncode - - # Get the files managed by git and build file list to be processed - if UPDATE_SYMLINKS and not args.skip_older_than: - filelist = set(git.ls_files(args.pathspec)) - else: - filelist = set() - for path in git.ls_files(args.pathspec): - fullpath = os.path.join(git.workdir, path) - - # Symlink (to file, to dir or broken - git handles the same way) - if not UPDATE_SYMLINKS and os.path.islink(fullpath): - log.warning( - "WARNING: Skipping symlink, no OS support for updates: %s", path - ) - continue - - # skip files which are older than given threshold - if ( - args.skip_older_than - and start - get_mtime_path(fullpath) > args.skip_older_than - ): - continue - - # Always add files relative to worktree root - filelist.add(path) - - # If --force, silently ignore uncommitted deletions (not in the filesystem) - # and renames / additions (will not be found in log anyway) - if args.force: - filelist -= set(git.ls_dirty(force=True)) - # Otherwise, ignore any dirty files - else: - dirty = set(git.ls_dirty()) - if dirty: - log.warning( - "WARNING: Modified files in the working directory were ignored." - "\nTo include such files, commit your changes or use --force." - ) - filelist -= dirty - - # Build dir list to be processed - dirlist = set(os.path.dirname(_) for _ in filelist) if args.dirs else set() - - stats["totalfiles"] = stats["files"] = len(filelist) - log.info("{0:,} files to be processed in work dir".format(stats["totalfiles"])) - - if not filelist: - # Nothing to do. Exit silently and without errors, just like git does - return - - # Process the log until all files are 'touched' - log.debug("Line #\tLog #\tF.Left\tModification Time\tFile Name") - parse_log(filelist, dirlist, stats, git, args.merge, args.pathspec) - - # Missing files - if filelist: - # Try to find them in merge logs, if not done already - # (usually HUGE, thus MUCH slower!) - if args.missing and not args.merge: - filterlist = list(filelist) - missing = len(filterlist) - log.info( - "{0:,} files not found in log, trying merge commits".format(missing) - ) - for i in range(0, missing, STEPMISSING): - parse_log( - filelist, - dirlist, - stats, - git, - merge=True, - filterlist=filterlist[i : i + STEPMISSING], - ) - - # Still missing some? - for file in filelist: - log.warning("WARNING: not found in the log: %s", file) - - # Final statistics - # Suggestion: use git-log --before=mtime to brag about skipped log entries - def log_info(msg, *a, width=13): - ifmt = "{:%d,}" % (width,) # not using 'n' for consistency with ffmt - ffmt = "{:%d,.2f}" % (width,) - # %-formatting lacks a thousand separator, must pre-render with .format() - log.info(msg.replace("%d", ifmt).replace("%f", ffmt).format(*a)) - - log_info( - "Statistics:\n%f seconds\n%d log lines processed\n%d commits evaluated", - time.time() - start, - stats["loglines"], - stats["commits"], - ) - - if args.dirs: - if stats["direrrors"]: - log_info("%d directory update errors", stats["direrrors"]) - log_info("%d directories updated", stats["dirtouches"]) - - if stats["touches"] != stats["totalfiles"]: - log_info("%d files", stats["totalfiles"]) - if stats["skip"]: - log_info("%d files skipped", stats["skip"]) - if stats["files"]: - log_info("%d files missing", stats["files"]) - if stats["errors"]: - log_info("%d file update errors", stats["errors"]) - - log_info("%d files updated", stats["touches"]) - - if args.test: - log.info("TEST RUN - No files modified!") - - -# Keep only essential, global assignments here. Any other logic must be in main() -log = setup_logging() -args = parse_args() - -# Set the actual touch() and other functions based on command-line arguments -if args.unique_times: - touch = touch_ns - isodate = isodate_ns - -# Make sure this is always set last to ensure --test behaves as intended -if args.test: - touch = dummy - -# UI done, it's showtime! -try: - sys.exit(main()) -except KeyboardInterrupt: - log.info("\nAborting") - signal.signal(signal.SIGINT, signal.SIG_DFL) - os.kill(os.getpid(), signal.SIGINT) diff --git a/.github/workflows/_refresh_model_profiles.yml b/.github/workflows/_refresh_model_profiles.yml deleted file mode 100644 index ef29805ab9..0000000000 --- a/.github/workflows/_refresh_model_profiles.yml +++ /dev/null @@ -1,228 +0,0 @@ -# Reusable workflow: refreshes model profile data for any repo that uses the -# `langchain-profiles` CLI. Creates (or updates) a pull request with the -# resulting changes. -# -# Callers MUST set `permissions: { contents: write, pull-requests: write }` — -# reusable workflows cannot escalate the caller's token permissions. -# -# ── Example: external repo (langchain-google) ────────────────────────── -# -# jobs: -# refresh-profiles: -# uses: langchain-ai/langchain/.github/workflows/_refresh_model_profiles.yml@master -# with: -# providers: >- -# [ -# {"provider":"google", "data_dir":"libs/genai/langchain_google_genai/data"}, -# ] -# secrets: -# MODEL_PROFILE_BOT_CLIENT_ID: ${{ secrets.MODEL_PROFILE_BOT_CLIENT_ID }} -# MODEL_PROFILE_BOT_PRIVATE_KEY: ${{ secrets.MODEL_PROFILE_BOT_PRIVATE_KEY }} - -name: "Refresh Model Profiles (reusable)" - -on: - workflow_call: - inputs: - providers: - description: >- - JSON array of objects, each with `provider` (models.dev provider ID) - and `data_dir` (path relative to repo root where `_profiles.py` and - `profile_augmentations.toml` live). - required: true - type: string - cli-path: - description: >- - Path (relative to workspace) to an existing `libs/model-profiles` - checkout. When set the workflow skips cloning the langchain repo and - uses this directory for the CLI instead. Useful when the caller IS - the langchain monorepo. - required: false - type: string - default: "" - cli-ref: - description: >- - Git ref of langchain-ai/langchain to checkout for the CLI. - Ignored when `cli-path` is set. - required: false - type: string - default: master - add-paths: - description: "Glob for files to stage in the PR commit." - required: false - type: string - default: "**/_profiles.py" - pr-branch: - description: "Branch name for the auto-created PR." - required: false - type: string - default: bot/refresh-model-profiles - pr-title: - description: "PR / commit title." - required: false - type: string - default: "chore(model-profiles): refresh model profile data" - pr-body: - description: "PR body." - required: false - type: string - default: | - Automated refresh of model profile data via `langchain-profiles refresh`. - - 🤖 Generated by the [`refresh_model_profiles` workflow](https://github.com/langchain-ai/langchain/blob/master/.github/workflows/refresh_model_profiles.yml). - pr-labels: - description: "Comma-separated labels to apply to the PR." - required: false - type: string - default: bot - secrets: - MODEL_PROFILE_BOT_CLIENT_ID: - required: true - MODEL_PROFILE_BOT_PRIVATE_KEY: - required: true - -permissions: - contents: write - pull-requests: write - -jobs: - refresh-profiles: - name: refresh model profiles - runs-on: ubuntu-latest - steps: - - name: "📋 Checkout" - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v6 - - - name: "📋 Checkout langchain-profiles CLI" - if: inputs.cli-path == '' - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v6 - with: - repository: langchain-ai/langchain - ref: ${{ inputs.cli-ref }} - sparse-checkout: libs/model-profiles - path: _langchain-cli - - - name: "🔧 Resolve CLI directory" - id: cli - env: - CLI_PATH: ${{ inputs.cli-path }} - run: | - if [ -n "${CLI_PATH}" ]; then - resolved="${GITHUB_WORKSPACE}/${CLI_PATH}" - if [ ! -d "${resolved}" ]; then - echo "::error::cli-path '${CLI_PATH}' does not exist at ${resolved}" - exit 1 - fi - echo "dir=${CLI_PATH}" >> "$GITHUB_OUTPUT" - else - echo "dir=_langchain-cli/libs/model-profiles" >> "$GITHUB_OUTPUT" - fi - - - name: "🐍 Set up Python + uv" - uses: astral-sh/setup-uv@0ca8f610542aa7f4acaf39e65cf4eb3c35091883 # v7 - with: - version: "0.5.25" - python-version: "3.12" - enable-cache: true - cache-dependency-glob: "**/model-profiles/uv.lock" - - - name: "📦 Install langchain-profiles CLI" - working-directory: ${{ steps.cli.outputs.dir }} - run: uv sync --frozen --no-group test --no-group dev --no-group lint - - - name: "✅ Validate providers input" - env: - PROVIDERS_JSON: ${{ inputs.providers }} - run: | - echo "${PROVIDERS_JSON}" | jq -e 'type == "array" and length > 0' > /dev/null || { - echo "::error::providers input must be a non-empty JSON array" - exit 1 - } - echo "${PROVIDERS_JSON}" | jq -e 'all(has("provider") and has("data_dir"))' > /dev/null || { - echo "::error::every entry in providers must have 'provider' and 'data_dir' keys" - exit 1 - } - - - name: "🔄 Refresh profiles" - env: - PROVIDERS_JSON: ${{ inputs.providers }} - run: | - cli_dir="${GITHUB_WORKSPACE}/${{ steps.cli.outputs.dir }}" - failed="" - mapfile -t rows < <(echo "${PROVIDERS_JSON}" | jq -c '.[]') - for row in "${rows[@]}"; do - provider=$(echo "${row}" | jq -r '.provider') - data_dir=$(echo "${row}" | jq -r '.data_dir') - echo "--- Refreshing ${provider} -> ${data_dir} ---" - if ! echo y | uv run --frozen --project "${cli_dir}" \ - langchain-profiles refresh \ - --provider "${provider}" \ - --data-dir "${GITHUB_WORKSPACE}/${data_dir}"; then - echo "::error::Failed to refresh provider: ${provider}" - failed="${failed} ${provider}" - fi - done - if [ -n "${failed}" ]; then - echo "::error::The following providers failed:${failed}" - exit 1 - fi - - - name: "📝 Build PR body with change summary" - id: pr-body - env: - PROVIDERS_JSON: ${{ inputs.providers }} - PR_BODY: ${{ inputs.pr-body }} - run: | - # The refresh step modified the working tree without committing, so - # comparing against HEAD yields exactly the refresh's changes. - cli_dir="${GITHUB_WORKSPACE}/${{ steps.cli.outputs.dir }}" - body_file="${RUNNER_TEMP}/pr_body.md" - printf '%s\n\n' "${PR_BODY}" > "${body_file}" - # `summarize` builds the whole summary in memory and prints it once, - # so a failure exits non-zero before any stdout reaches the append — - # the body keeps only the static note, never a half-written summary. - if ! uv run --frozen --project "${cli_dir}" \ - langchain-profiles summarize \ - --providers "${PROVIDERS_JSON}" \ - --base-ref HEAD \ - --repo-root "${GITHUB_WORKSPACE}" >> "${body_file}"; then - echo "::warning::Could not generate change summary; see job log." - # Surface the degradation in the PR body too: the warning above only - # lands in the Actions log, which a PR reviewer won't see. - printf '\n> [!NOTE]\n> Automated change summary unavailable — see the workflow run log.\n' >> "${body_file}" - fi - echo "path=${body_file}" >> "$GITHUB_OUTPUT" - - - name: "🔑 Generate GitHub App token" - id: app-token - uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3 - with: - client-id: ${{ secrets.MODEL_PROFILE_BOT_CLIENT_ID }} - private-key: ${{ secrets.MODEL_PROFILE_BOT_PRIVATE_KEY }} - - - name: "🔀 Create pull request" - id: create-pr - uses: peter-evans/create-pull-request@5f6978faf089d4d20b00c7766989d076bb2fc7f1 # v8 - with: - token: ${{ steps.app-token.outputs.token }} - branch: ${{ inputs.pr-branch }} - commit-message: ${{ inputs.pr-title }} - title: ${{ inputs.pr-title }} - body-path: ${{ steps.pr-body.outputs.path }} - labels: ${{ inputs.pr-labels }} - add-paths: ${{ inputs.add-paths }} - - - name: "📝 Summary" - if: always() - env: - PR_OP: ${{ steps.create-pr.outputs.pull-request-operation }} - PR_URL: ${{ steps.create-pr.outputs.pull-request-url }} - JOB_STATUS: ${{ job.status }} - run: | - if [ "${PR_OP}" = "created" ] || [ "${PR_OP}" = "updated" ]; then - echo "### ✅ PR ${PR_OP}: ${PR_URL}" >> "$GITHUB_STEP_SUMMARY" - elif [ -z "${PR_OP}" ] && [ "${JOB_STATUS}" = "success" ]; then - echo "### ⏭️ Skipped: profiles already up to date" >> "$GITHUB_STEP_SUMMARY" - elif [ "${JOB_STATUS}" = "failure" ]; then - echo "### ❌ Job failed — check step logs for details" >> "$GITHUB_STEP_SUMMARY" - fi diff --git a/.github/workflows/_release.yml b/.github/workflows/_release.yml deleted file mode 100644 index a58f91da95..0000000000 --- a/.github/workflows/_release.yml +++ /dev/null @@ -1,917 +0,0 @@ -# Builds and publishes LangChain packages to PyPI. -# -# Manually triggered, though can be used as a reusable workflow (workflow_call). -# -# Handles version bumping, building, and publishing to PyPI with authentication. - -name: "🚀 Package Release" -# Run title resolves dropdown values to the published package name (e.g. -# `core` -> `langchain-core`, `openai` -> `langchain-openai`). Falls back to -# the raw input for override and `workflow_call` cases, which already pass -# a full path. Three dropdown values don't follow `langchain-{name}`: -# `langchain` -> `langchain-classic`, `langchain_v1` -> `langchain`, -# `standard-tests` -> `langchain-tests`. -run-name: >- - Release ${{ inputs.working-directory-override || - (startsWith(inputs.working-directory, 'libs/') && inputs.working-directory) || - (inputs.working-directory == 'langchain' && 'langchain-classic') || - (inputs.working-directory == 'langchain_v1' && 'langchain') || - (inputs.working-directory == 'standard-tests' && 'langchain-tests') || - format('langchain-{0}', inputs.working-directory) }} ${{ - inputs.release-version }} -on: - workflow_call: - inputs: - working-directory: - required: true - type: string - description: "From which folder this pipeline executes" - release-version: - required: false - type: string - default: "" - description: "Expected package version. If provided, must match pyproject.toml." - allow-prereleases: - required: false - type: boolean - default: false - description: "Pass `--prerelease=allow` to wheel-install steps so - transitive prerelease deps (e.g. langgraph-checkpoint>=4.1.0a3 pulled - in by an alpha langgraph) resolve. Use only when the release itself - is a prerelease and at least one dep is also a prerelease." - # `workflow_call` callers must pass an exact lowercase value: `none` or a - # partner name from the `test-prior-published-packages-against-new-core` - # matrix (or `all`). Unrecognized values fail safe (the check still runs). - # Keep this list in sync with that matrix and the `workflow_dispatch` - # `options` below. - skip-prior-published-package-checks: - required: false - type: string - default: "none" - description: "Prior published partner check to skip for core releases: - none, anthropic, openai, or all." - workflow_dispatch: - inputs: - working-directory: - required: true - type: choice - description: "From which folder this pipeline executes" - default: "langchain_v1" - # Short names only — `EFFECTIVE_WORKING_DIR` below re-adds the `libs/` - # or `libs/partners/` prefix. When adding a new option, also update the - # non-partner allowlist in `EFFECTIVE_WORKING_DIR` if it isn't a partner - # package (partners are the default branch). - options: - - core - - langchain - - langchain_v1 - - text-splitters - - standard-tests - - model-profiles - - anthropic - - chroma - - deepseek - - exa - - fireworks - - groq - - huggingface - - mistralai - - nomic - - ollama - - openai - - openrouter - - decodo - - perplexity - - qdrant - - xai - working-directory-override: - required: false - type: string - description: "Manual override — takes precedence over dropdown (e.g. - libs/partners/partner-xyz)" - release-version: - required: true - type: string - default: "0.1.0" - description: "New version of package being released" - dangerous-nonmaster-release: - required: false - type: boolean - default: false - description: "Release from a non-master branch (danger!) - Only use for hotfixes" - allow-prereleases: - required: false - type: boolean - default: false - description: "Pass `--prerelease=allow` to wheel-install steps so - transitive prerelease deps (e.g. langgraph-checkpoint>=4.1.0a3 pulled - in by an alpha langgraph) resolve. Use only when the release itself - is a prerelease and at least one dep is also a prerelease." - skip-prior-published-package-checks: - required: false - type: choice - default: none - description: "Prior published partner check to skip for core releases" - options: - - none - - anthropic - - openai - - all - -env: - PYTHON_VERSION: "3.11" - UV_FROZEN: "true" - UV_NO_SYNC: "true" - # Resolves to a full path. Accepts either: - # - `working-directory-override` as a full path (e.g. `libs/partners/partner-xyz`) - # - `working-directory` as a full path (from `workflow_call` callers) - # - `working-directory` as a short dropdown name (from `workflow_dispatch`) - EFFECTIVE_WORKING_DIR: >- - ${{ - inputs.working-directory-override - || (startsWith(inputs.working-directory, 'libs/') && inputs.working-directory) - || (contains(fromJSON('["core","langchain","langchain_v1","text-splitters","standard-tests","model-profiles"]'), inputs.working-directory) && format('libs/{0}', inputs.working-directory)) - || format('libs/partners/{0}', inputs.working-directory) - }} - -permissions: - contents: read # Job-level overrides grant write only where needed (mark-release) - -jobs: - # Build the distribution package and extract version info - # Runs in isolated environment with minimal permissions for security - build: - name: 📦 Build distribution - if: github.repository_owner == 'langchain-ai' && (github.ref == 'refs/heads/master' || inputs.dangerous-nonmaster-release) - environment: Release - runs-on: ubuntu-latest - permissions: - contents: read - - outputs: - pkg-name: ${{ steps.check-version.outputs.pkg-name }} - version: ${{ steps.check-version.outputs.version }} - - steps: - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v6 - - - name: Set up Python + uv - uses: "./.github/actions/uv_setup" - with: - python-version: ${{ env.PYTHON_VERSION }} - enable-cache: "false" - - - name: Summarize release bypasses - if: >- - inputs.dangerous-nonmaster-release || inputs.allow-prereleases || - inputs.skip-prior-published-package-checks != 'none' - env: - ALLOW_PRERELEASES: ${{ inputs.allow-prereleases }} - DANGEROUS_NONMASTER_RELEASE: ${{ inputs.dangerous-nonmaster-release }} - SKIP_PRIOR_PUBLISHED_PACKAGE_CHECKS: ${{ inputs.skip-prior-published-package-checks }} - run: | - echo "::warning::Release bypass input(s) enabled. See job summary." - { - echo "## ⚠️ Release bypasses enabled" - echo - echo "One or more release safety bypasses were selected for this run:" - echo - if [ "$DANGEROUS_NONMASTER_RELEASE" = "true" ]; then - echo "- \`dangerous-nonmaster-release\`: release jobs may run from a non-\`master\` ref." - fi - if [ "$ALLOW_PRERELEASES" = "true" ]; then - echo "- \`allow-prereleases\`: install checks use \`--prerelease=allow\`." - fi - if [ -n "$SKIP_PRIOR_PUBLISHED_PACKAGE_CHECKS" ] && [ "$SKIP_PRIOR_PUBLISHED_PACKAGE_CHECKS" != "none" ]; then - echo "- \`skip-prior-published-package-checks\`: \`$SKIP_PRIOR_PUBLISHED_PACKAGE_CHECKS\`." - fi - } >> "$GITHUB_STEP_SUMMARY" - - - name: Check version - id: check-version - shell: python - working-directory: ${{ env.EFFECTIVE_WORKING_DIR }} - env: - RELEASE_VERSION_INPUT: ${{ inputs.release-version }} - run: | - import os - import re - import sys - import tomllib - import urllib.error - import urllib.request - - with open("pyproject.toml", "rb") as f: - data = tomllib.load(f) - - pkg_name = data["project"]["name"] - version = data["project"]["version"] - requested_version = os.environ.get("RELEASE_VERSION_INPUT", "").strip() - - - def normalize(v): - # Lightweight PEP 440 comparison key: lowercase and drop the `-`, - # `_`, or `.` separators that precede a pre/post/dev segment so that - # e.g. `0.1.0-rc1` and `0.1.0rc1` compare equal. Full canonicalization - # lives in `packaging`, which isn't installed in this bare release step. - return re.sub(r"[-_.]+(?=[a-z])", "", v.lower()) - - - if requested_version and normalize(requested_version) != normalize(version): - print( - f"::error::Requested release version {requested_version!r} does " - f"not match {pkg_name} pyproject.toml version {version!r}." - ) - sys.exit(1) - - # Query the per-version endpoint so PyPI applies PEP 440 normalization - # (e.g. `0.1.0-rc1` and `0.1.0rc1` resolve to the same release): HTTP 200 - # means the version is already published, 404 means it's available - # (including the first-ever release of a new package). Only the status - # code is used, so a malicious or malformed response body can't mislead us. - url = f"https://pypi.org/pypi/{pkg_name}/{version}/json" - try: - with urllib.request.urlopen(url, timeout=10): - already_published = True - except urllib.error.HTTPError as err: - if err.code == 404: - already_published = False - else: - # Fail closed: an unexpected status means we can't verify. - print( - f"::error::PyPI returned HTTP {err.code} checking whether " - f"{pkg_name}=={version} exists; cannot verify, aborting." - ) - sys.exit(1) - except urllib.error.URLError as err: - # Fail closed: if PyPI is unreachable we must not assume the version - # is free, or we risk re-publishing an existing release. - print( - f"::error::Could not reach PyPI to verify {pkg_name}=={version} " - f"({err.reason}); cannot verify, aborting." - ) - sys.exit(1) - - if already_published: - print(f"::error::{pkg_name}=={version} already exists on PyPI.") - sys.exit(1) - - - with open(os.environ["GITHUB_OUTPUT"], "a") as f: - f.write(f"pkg-name={pkg_name}\n") - f.write(f"version={version}\n") - - # We want to keep this build stage *separate* from the release stage, - # so that there's no sharing of permissions between them. - # (Release stage has trusted publishing and GitHub repo contents write access, - # which the build stage must not have access to.) - # - # Otherwise, a malicious `build` step (e.g. via a compromised dependency) - # could get access to our GitHub or PyPI credentials. - # - # Per the trusted publishing GitHub Action: - # > It is strongly advised to separate jobs for building [...] - # > from the publish job. - # https://github.com/pypa/gh-action-pypi-publish#non-goals - - name: Build project for distribution - run: uv build - working-directory: ${{ env.EFFECTIVE_WORKING_DIR }} - - - name: Upload build - uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7 - with: - name: dist - path: ${{ env.EFFECTIVE_WORKING_DIR }}/dist/ - release-notes: - name: 📝 Generate release notes - # release-notes must run before publishing because its check-tags step - # validates version/tag state — do not remove this dependency. - needs: - - build - runs-on: ubuntu-latest - permissions: - contents: read - outputs: - release-body: ${{ steps.generate-release-body.outputs.release-body }} - steps: - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v6 - with: - repository: langchain-ai/langchain - path: langchain - sparse-checkout: | # this only grabs files for relevant dir - ${{ env.EFFECTIVE_WORKING_DIR }} - ref: ${{ github.ref }} # this scopes to just ref'd branch - fetch-depth: 0 # this fetches entire commit history - - name: Check tags - id: check-tags - shell: bash - working-directory: langchain/${{ env.EFFECTIVE_WORKING_DIR }} - env: - PKG_NAME: ${{ needs.build.outputs.pkg-name }} - VERSION: ${{ needs.build.outputs.version }} - run: | - # Handle regular versions and pre-release versions differently - if [[ "$VERSION" == *"-"* ]]; then - # This is a pre-release version (contains a hyphen) - # Extract the base version without the pre-release suffix - BASE_VERSION=${VERSION%%-*} - # Look for the latest release of the same base version - REGEX="^$PKG_NAME==$BASE_VERSION\$" - PREV_TAG=$(git tag --sort=-creatordate | (grep -P "$REGEX" || true) | head -1) - - # If no exact base version match, look for the latest release of any kind - if [ -z "$PREV_TAG" ]; then - REGEX="^$PKG_NAME==\\d+\\.\\d+\\.\\d+\$" - PREV_TAG=$(git tag --sort=-creatordate | (grep -P "$REGEX" || true) | head -1) - fi - else - # Regular version handling - PREV_TAG="$PKG_NAME==${VERSION%.*}.$(( ${VERSION##*.} - 1 ))"; [[ "${VERSION##*.}" -eq 0 ]] && PREV_TAG="" - - # backup case if releasing e.g. 0.3.0, looks up last release - # note if last release (chronologically) was e.g. 0.1.47 it will get - # that instead of the last 0.2 release - if [ -z "$PREV_TAG" ]; then - REGEX="^$PKG_NAME==\\d+\\.\\d+\\.\\d+\$" - echo $REGEX - PREV_TAG=$(git tag --sort=-creatordate | (grep -P $REGEX || true) | head -1) - fi - fi - - # if PREV_TAG is empty or came out to 0.0.0, let it be empty - if [ -z "$PREV_TAG" ] || [ "$PREV_TAG" = "$PKG_NAME==0.0.0" ]; then - echo "No previous tag found - first release" - else - # confirm prev-tag actually exists in git repo with git tag - GIT_TAG_RESULT=$(git tag -l "$PREV_TAG") - if [ -z "$GIT_TAG_RESULT" ]; then - echo "Previous tag $PREV_TAG not found in git repo" - exit 1 - fi - fi - - - TAG="${PKG_NAME}==${VERSION}" - if [ "$TAG" == "$PREV_TAG" ]; then - echo "No new version to release" - exit 1 - fi - echo tag="$TAG" >> $GITHUB_OUTPUT - echo prev-tag="$PREV_TAG" >> $GITHUB_OUTPUT - - name: Generate release body - id: generate-release-body - working-directory: langchain - env: - WORKING_DIR: ${{ env.EFFECTIVE_WORKING_DIR }} - PKG_NAME: ${{ needs.build.outputs.pkg-name }} - TAG: ${{ steps.check-tags.outputs.tag }} - PREV_TAG: ${{ steps.check-tags.outputs.prev-tag }} - run: | - PREAMBLE="Changes since $PREV_TAG" - # if PREV_TAG is empty or 0.0.0, then we are releasing the first version - if [ -z "$PREV_TAG" ] || [ "$PREV_TAG" = "$PKG_NAME==0.0.0" ]; then - PREAMBLE="Initial release" - PREV_TAG=$(git rev-list --max-parents=0 HEAD) - fi - { - echo 'release-body<> "$GITHUB_OUTPUT" - - pre-release-checks: - name: ✅ Pre-release checks - needs: - - build - - release-notes - environment: Release - runs-on: ubuntu-latest - permissions: - contents: read - timeout-minutes: 20 - steps: - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v6 - - # We explicitly *don't* set up caching here. This ensures our tests are - # maximally sensitive to catching breakage. - # - # For example, here's a way that caching can cause a falsely-passing test: - # - Make the langchain package manifest no longer list a dependency package - # as a requirement. This means it won't be installed by `pip install`, - # and attempting to use it would cause a crash. - # - That dependency used to be required, so it may have been cached. - # When restoring the venv packages from cache, that dependency gets included. - # - Tests pass, because the dependency is present even though it wasn't specified. - # - The package is published, and it breaks on the missing dependency when - # used in the real world. - - - name: Set up Python + uv - uses: "./.github/actions/uv_setup" - id: setup-python - with: - python-version: ${{ env.PYTHON_VERSION }} - enable-cache: "false" - - - uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8 - with: - name: dist - path: ${{ env.EFFECTIVE_WORKING_DIR }}/dist/ - - - name: Import dist package - shell: bash - working-directory: ${{ env.EFFECTIVE_WORKING_DIR }} - env: - PKG_NAME: ${{ needs.build.outputs.pkg-name }} - VERSION: ${{ needs.build.outputs.version }} - PRERELEASE_FLAG: ${{ inputs.allow-prereleases && '--prerelease=allow' || '' }} - # Install directly from the locally-built wheel (no index resolution needed). - # `PRERELEASE_FLAG` is empty by default; opt-in via the `allow-prereleases` - # workflow input lets transitive prerelease deps resolve during alpha - # release cycles. Stable-release safety is still enforced by the - # `Check for prerelease versions` step below. - run: | - uv venv - VIRTUAL_ENV=.venv uv pip install $PRERELEASE_FLAG dist/*.whl - - # Replace all dashes in the package name with underscores, - # since that's how Python imports packages with dashes in the name. - # also remove _official suffix - IMPORT_NAME="$(echo "$PKG_NAME" | sed s/-/_/g | sed s/_official//g)" - - uv run python -c "import $IMPORT_NAME; print(dir($IMPORT_NAME))" - - - name: Import test dependencies - run: uv sync --group test - working-directory: ${{ env.EFFECTIVE_WORKING_DIR }} - - # Overwrite the local version of the package with the built version - - name: Import published package (again) - working-directory: ${{ env.EFFECTIVE_WORKING_DIR }} - shell: bash - env: - PKG_NAME: ${{ needs.build.outputs.pkg-name }} - VERSION: ${{ needs.build.outputs.version }} - PRERELEASE_FLAG: ${{ inputs.allow-prereleases && '--prerelease=allow' || '' }} - run: | - VIRTUAL_ENV=.venv uv pip install $PRERELEASE_FLAG dist/*.whl - - - name: Check for prerelease versions - # Block release if any dependencies allow prerelease versions - # (unless this is itself a prerelease version) - working-directory: ${{ env.EFFECTIVE_WORKING_DIR }} - run: | - uv run python $GITHUB_WORKSPACE/.github/scripts/check_prerelease_dependencies.py pyproject.toml - - - name: Run unit tests - run: make tests - working-directory: ${{ env.EFFECTIVE_WORKING_DIR }} - - - name: Get minimum versions - # Find the minimum published versions that satisfies the given constraints - working-directory: ${{ env.EFFECTIVE_WORKING_DIR }} - id: min-version - run: | - VIRTUAL_ENV=.venv uv pip install packaging requests - python_version="$(uv run python --version | awk '{print $2}')" - min_versions="$(uv run python $GITHUB_WORKSPACE/.github/scripts/get_min_versions.py pyproject.toml release $python_version)" - echo "min-versions=$min_versions" >> "$GITHUB_OUTPUT" - echo "min-versions=$min_versions" - - - name: Run unit tests with minimum dependency versions - if: ${{ steps.min-version.outputs.min-versions != '' }} - env: - MIN_VERSIONS: ${{ steps.min-version.outputs.min-versions }} - PRERELEASE_FLAG: ${{ inputs.allow-prereleases && '--prerelease=allow' || '' }} - run: | - VIRTUAL_ENV=.venv uv pip install $PRERELEASE_FLAG --force-reinstall --editable . - VIRTUAL_ENV=.venv uv pip install $PRERELEASE_FLAG --force-reinstall $MIN_VERSIONS - make tests PYTEST_EXTRA="-q -k 'not test_serdes'" - working-directory: ${{ env.EFFECTIVE_WORKING_DIR }} - - - name: Import integration test dependencies - run: uv sync --group test --group test_integration - working-directory: ${{ env.EFFECTIVE_WORKING_DIR }} - - - name: Run integration tests - # Uses the Makefile's `integration_tests` target for the specified package - if: ${{ startsWith(env.EFFECTIVE_WORKING_DIR, 'libs/partners/') }} - env: - LANGSMITH_GATEWAY: ${{ secrets.LANGSMITH_GATEWAY }} - LANGSMITH_GATEWAY_API_KEY: ${{ secrets.LANGSMITH_GATEWAY_API_KEY }} - AI21_API_KEY: ${{ secrets.AI21_API_KEY }} - GOOGLE_API_KEY: ${{ secrets.GOOGLE_API_KEY }} - MISTRAL_API_KEY: ${{ secrets.MISTRAL_API_KEY }} - TOGETHER_API_KEY: ${{ secrets.TOGETHER_API_KEY }} - OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} - AZURE_OPENAI_API_VERSION: ${{ secrets.AZURE_OPENAI_API_VERSION }} - AZURE_OPENAI_API_BASE: ${{ secrets.AZURE_OPENAI_API_BASE }} - AZURE_OPENAI_API_KEY: ${{ secrets.AZURE_OPENAI_API_KEY }} - AZURE_OPENAI_CHAT_DEPLOYMENT_NAME: ${{ secrets.AZURE_OPENAI_CHAT_DEPLOYMENT_NAME }} - AZURE_OPENAI_LEGACY_CHAT_DEPLOYMENT_NAME: ${{ secrets.AZURE_OPENAI_LEGACY_CHAT_DEPLOYMENT_NAME }} - AZURE_OPENAI_LLM_DEPLOYMENT_NAME: ${{ secrets.AZURE_OPENAI_LLM_DEPLOYMENT_NAME }} - AZURE_OPENAI_EMBEDDINGS_DEPLOYMENT_NAME: ${{ secrets.AZURE_OPENAI_EMBEDDINGS_DEPLOYMENT_NAME }} - NVIDIA_API_KEY: ${{ secrets.NVIDIA_API_KEY }} - GOOGLE_SEARCH_API_KEY: ${{ secrets.GOOGLE_SEARCH_API_KEY }} - GOOGLE_CSE_ID: ${{ secrets.GOOGLE_CSE_ID }} - GROQ_API_KEY: ${{ secrets.GROQ_API_KEY }} - HUGGINGFACEHUB_API_TOKEN: ${{ secrets.HUGGINGFACEHUB_API_TOKEN }} - EXA_API_KEY: ${{ secrets.EXA_API_KEY }} - NOMIC_API_KEY: ${{ secrets.NOMIC_API_KEY }} - WATSONX_APIKEY: ${{ secrets.WATSONX_APIKEY }} - WATSONX_PROJECT_ID: ${{ secrets.WATSONX_PROJECT_ID }} - ASTRA_DB_API_ENDPOINT: ${{ secrets.ASTRA_DB_API_ENDPOINT }} - ASTRA_DB_APPLICATION_TOKEN: ${{ secrets.ASTRA_DB_APPLICATION_TOKEN }} - ASTRA_DB_KEYSPACE: ${{ secrets.ASTRA_DB_KEYSPACE }} - ES_URL: ${{ secrets.ES_URL }} - ES_CLOUD_ID: ${{ secrets.ES_CLOUD_ID }} - ES_API_KEY: ${{ secrets.ES_API_KEY }} - MONGODB_ATLAS_URI: ${{ secrets.MONGODB_ATLAS_URI }} - UPSTAGE_API_KEY: ${{ secrets.UPSTAGE_API_KEY }} - FIREWORKS_API_KEY: ${{ secrets.FIREWORKS_API_KEY }} - XAI_API_KEY: ${{ secrets.XAI_API_KEY }} - DEEPSEEK_API_KEY: ${{ secrets.DEEPSEEK_API_KEY }} - PPLX_API_KEY: ${{ secrets.PPLX_API_KEY }} - OLLAMA_API_KEY: ${{ secrets.OLLAMA_API_KEY }} - OPENROUTER_API_KEY: ${{ secrets.OPENROUTER_API_KEY }} - LANGCHAIN_TESTS_USER_AGENT: ${{ secrets.LANGCHAIN_TESTS_USER_AGENT }} - run: make integration_tests - working-directory: ${{ env.EFFECTIVE_WORKING_DIR }} - - test-pypi-publish: - name: 🧪 Publish to TestPyPI - # release-notes must run before publishing because its check-tags step - # validates version/tag state — do not remove this dependency. - needs: - - build - - release-notes - - pre-release-checks - environment: Release - runs-on: ubuntu-latest - permissions: - # This permission is used for trusted publishing: - # https://blog.pypi.org/posts/2023-04-20-introducing-trusted-publishers/ - # - # Trusted publishing has to also be configured on PyPI for each package: - # https://docs.pypi.org/trusted-publishers/adding-a-publisher/ - id-token: write - - steps: - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v6 - - - uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8 - with: - name: dist - path: ${{ env.EFFECTIVE_WORKING_DIR }}/dist/ - - - name: Publish to test PyPI - uses: pypa/gh-action-pypi-publish@dc37677b2e1c63e2034f94d8a5b11f265b73ba33 # release/v1 - with: - packages-dir: ${{ env.EFFECTIVE_WORKING_DIR }}/dist/ - verbose: true - print-hash: true - repository-url: https://test.pypi.org/legacy/ - # We overwrite any existing distributions with the same name and version. - # This is *only for CI use* and is *extremely dangerous* otherwise! - # https://github.com/pypa/gh-action-pypi-publish#tolerating-release-package-file-duplicates - skip-existing: true - # Temp workaround since attestations are on by default as of gh-action-pypi-publish v1.11.0 - attestations: false - - # Test select published packages against new core - # Done when code changes are made to langchain-core - test-prior-published-packages-against-new-core: - name: 🔄 Test prior partners against new core - # Installs the new core with old partners: Installs the new unreleased core - # alongside the previously published partner packages and runs unit and integration tests - needs: - - build - - release-notes - - test-pypi-publish - - pre-release-checks - environment: Release - runs-on: ubuntu-latest - permissions: - contents: read - strategy: - matrix: - # When adding a partner, also update the `skip-prior-published-package-checks` - # input (the `workflow_dispatch` `options` list and the `workflow_call` - # description) so the per-partner skip remains selectable. - partner: [ anthropic, openai ] - fail-fast: false # Continue testing other partners if one fails - env: - LANGSMITH_GATEWAY: ${{ secrets.LANGSMITH_GATEWAY }} - LANGSMITH_GATEWAY_API_KEY: ${{ secrets.LANGSMITH_GATEWAY_API_KEY }} - ANTHROPIC_FILES_API_IMAGE_ID: ${{ secrets.ANTHROPIC_FILES_API_IMAGE_ID }} - ANTHROPIC_FILES_API_PDF_ID: ${{ secrets.ANTHROPIC_FILES_API_PDF_ID }} - OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} - AZURE_OPENAI_API_VERSION: ${{ secrets.AZURE_OPENAI_API_VERSION }} - AZURE_OPENAI_API_BASE: ${{ secrets.AZURE_OPENAI_API_BASE }} - AZURE_OPENAI_API_KEY: ${{ secrets.AZURE_OPENAI_API_KEY }} - AZURE_OPENAI_CHAT_DEPLOYMENT_NAME: ${{ secrets.AZURE_OPENAI_CHAT_DEPLOYMENT_NAME }} - AZURE_OPENAI_LEGACY_CHAT_DEPLOYMENT_NAME: ${{ secrets.AZURE_OPENAI_LEGACY_CHAT_DEPLOYMENT_NAME }} - AZURE_OPENAI_LLM_DEPLOYMENT_NAME: ${{ secrets.AZURE_OPENAI_LLM_DEPLOYMENT_NAME }} - AZURE_OPENAI_EMBEDDINGS_DEPLOYMENT_NAME: ${{ secrets.AZURE_OPENAI_EMBEDDINGS_DEPLOYMENT_NAME }} - LANGCHAIN_TESTS_USER_AGENT: ${{ secrets.LANGCHAIN_TESTS_USER_AGENT }} - steps: - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v6 - - # We implement this conditional as Github Actions does not have good support - # for conditionally needing steps. https://github.com/actions/runner/issues/491 - # TODO: this seems to be resolved upstream, so we can probably remove this workaround - - name: Check if libs/core - run: | - if [ "${{ startsWith(env.EFFECTIVE_WORKING_DIR, 'libs/core') }}" != "true" ]; then - echo "Not in libs/core. Exiting successfully." - exit 0 - fi - - - name: Set up Python + uv - if: startsWith(env.EFFECTIVE_WORKING_DIR, 'libs/core') - uses: "./.github/actions/uv_setup" - with: - python-version: ${{ env.PYTHON_VERSION }} - enable-cache: "false" - - - uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8 - if: startsWith(env.EFFECTIVE_WORKING_DIR, 'libs/core') - with: - name: dist - path: ${{ env.EFFECTIVE_WORKING_DIR }}/dist/ - - - name: Skip prior published ${{ matrix.partner }} check - if: >- - startsWith(env.EFFECTIVE_WORKING_DIR, 'libs/core') && - (inputs.skip-prior-published-package-checks == matrix.partner || - inputs.skip-prior-published-package-checks == 'all') - run: | - echo "Skipping prior published ${{ matrix.partner }} check as requested." - - - name: Test against ${{ matrix.partner }} - if: >- - startsWith(env.EFFECTIVE_WORKING_DIR, 'libs/core') && - inputs.skip-prior-published-package-checks != matrix.partner && - inputs.skip-prior-published-package-checks != 'all' - env: - PARTNER: ${{ matrix.partner }} - PRERELEASE_FLAG: ${{ inputs.allow-prereleases && '--prerelease=allow' || '' }} - run: | - PACKAGE_NAME="langchain-$PARTNER" - - # Identify the latest non-yanked published package release, excluding pre-releases. - # Fail closed (matching the `Check version` step) so a PyPI outage or a - # missing release aborts with a clear message rather than an empty version. - LATEST_PACKAGE_VERSION="$(PACKAGE_NAME="$PACKAGE_NAME" python - <<'PY' - import json - import os - import re - import sys - import urllib.error - import urllib.request - - package_name = os.environ["PACKAGE_NAME"] - url = f"https://pypi.org/pypi/{package_name}/json" - try: - with urllib.request.urlopen(url, timeout=10) as response: - data = json.load(response) - except urllib.error.HTTPError as err: - print( - f"::error::PyPI returned HTTP {err.code} listing {package_name} " - f"releases; cannot determine latest version, aborting.", - file=sys.stderr, - ) - sys.exit(1) - except urllib.error.URLError as err: - print( - f"::error::Could not reach PyPI to list {package_name} releases " - f"({err.reason}); cannot determine latest version, aborting.", - file=sys.stderr, - ) - sys.exit(1) - - versions: list[tuple[int, int, int, str]] = [] - for version, files in data["releases"].items(): - if not re.fullmatch(r"\d+\.\d+\.\d+", version): - continue - if not files or all(file.get("yanked", False) for file in files): - continue - versions.append((*map(int, version.split(".")), version)) - - if not versions: - print(f"::error::No non-yanked final releases found for {package_name}", file=sys.stderr) - sys.exit(1) - - print(max(versions)[3]) - PY - )" - - # Belt-and-suspenders: a bare assignment masks the heredoc's exit status - # in some shells, so guard explicitly rather than relying on `set -e`. - if [ -z "$LATEST_PACKAGE_VERSION" ]; then - echo "::error::Could not determine latest published $PACKAGE_NAME version; aborting." - exit 1 - fi - - LATEST_PACKAGE_TAG="$PACKAGE_NAME==$LATEST_PACKAGE_VERSION" - echo "Latest non-yanked package tag: $LATEST_PACKAGE_TAG" - - # Ensure the PyPI release maps to a source tag before running tests. - git ls-remote --exit-code --tags origin "refs/tags/$LATEST_PACKAGE_TAG" - - # Shallow-fetch just that single tag - git fetch --depth=1 origin tag "$LATEST_PACKAGE_TAG" - - # Checkout the latest package files - rm -rf "$GITHUB_WORKSPACE/libs/partners/$PARTNER"/* - rm -rf $GITHUB_WORKSPACE/libs/standard-tests/* - cd $GITHUB_WORKSPACE/libs/ - git checkout "$LATEST_PACKAGE_TAG" -- standard-tests/ - git checkout "$LATEST_PACKAGE_TAG" -- "partners/$PARTNER/" - cd "partners/$PARTNER" - - # Print as a sanity check - echo "Version number from pyproject.toml: " - cat pyproject.toml | grep "version = " - - # Run tests - uv sync --group test --group test_integration - uv pip install $PRERELEASE_FLAG ../../core/dist/*.whl - make test - make integration_tests - - # Test external packages that depend on langchain-core/langchain against the new release - # Only runs for core and langchain_v1 releases to catch breaking changes before publish - test-dependents: - name: "🐍 Test dependent: ${{ matrix.package.path }} (Python ${{ - matrix.python-version }})" - needs: - - build - - release-notes - - test-pypi-publish - - pre-release-checks - runs-on: ubuntu-latest - permissions: - contents: read - # Only run for core or langchain_v1 releases. - # Job-level 'if' does not support env context, so EFFECTIVE_WORKING_DIR is - # unavailable; must use inputs directly and match both forms: short dropdown - # names (workflow_dispatch, e.g. 'core') and full 'libs/' paths - # (workflow_call / working-directory-override). - if: >- - contains(fromJSON('["core","langchain_v1"]'), - inputs.working-directory-override || inputs.working-directory) || - startsWith(inputs.working-directory-override || inputs.working-directory, - 'libs/core') || startsWith(inputs.working-directory-override || - inputs.working-directory, 'libs/langchain_v1') - strategy: - fail-fast: false - matrix: - python-version: [ "3.11", "3.13" ] - package: - - name: deepagents - repo: langchain-ai/deepagents - path: libs/deepagents - # No API keys needed for now - deepagents `make test` only runs unit tests - - steps: - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v6 - with: - path: langchain - - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v6 - with: - repository: ${{ matrix.package.repo }} - path: ${{ matrix.package.name }} - - - name: Set up Python + uv - uses: "./langchain/.github/actions/uv_setup" - with: - python-version: ${{ matrix.python-version }} - enable-cache: "false" - - - uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8 - with: - name: dist - path: dist/ - - - name: Install ${{ matrix.package.name }} with local packages - # External dependents don't have [tool.uv.sources] pointing to this repo, - # so we install the package normally then override with the built wheel. - env: - PRERELEASE_FLAG: ${{ inputs.allow-prereleases && '--prerelease=allow' || '' }} - run: | - cd ${{ matrix.package.name }}/${{ matrix.package.path }} - - # Install the package with test dependencies - uv sync --group test - - # Override with the built wheel from this release - uv pip install $PRERELEASE_FLAG $GITHUB_WORKSPACE/dist/*.whl - - - name: Run ${{ matrix.package.name }} tests - run: | - cd ${{ matrix.package.name }}/${{ matrix.package.path }} - make test - - publish: - name: 🚀 Publish to PyPI - # Publishes the package to PyPI - needs: - - build - - release-notes - - test-pypi-publish - - pre-release-checks - - test-dependents - - test-prior-published-packages-against-new-core - # Run if all needed jobs succeeded or were skipped (test-dependents and - # test-prior-published-packages-against-new-core only run for core/langchain_v1) - if: ${{ !cancelled() && !failure() }} - environment: Release - runs-on: ubuntu-latest - permissions: - # This permission is used for trusted publishing: - # https://blog.pypi.org/posts/2023-04-20-introducing-trusted-publishers/ - # - # Trusted publishing has to also be configured on PyPI for each package: - # https://docs.pypi.org/trusted-publishers/adding-a-publisher/ - id-token: write - - defaults: - run: - working-directory: ${{ env.EFFECTIVE_WORKING_DIR }} - - steps: - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v6 - - - name: Set up Python + uv - uses: "./.github/actions/uv_setup" - with: - python-version: ${{ env.PYTHON_VERSION }} - enable-cache: "false" - - - uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8 - with: - name: dist - path: ${{ env.EFFECTIVE_WORKING_DIR }}/dist/ - - - name: Publish package distributions to PyPI - uses: pypa/gh-action-pypi-publish@dc37677b2e1c63e2034f94d8a5b11f265b73ba33 # release/v1 - with: - packages-dir: ${{ env.EFFECTIVE_WORKING_DIR }}/dist/ - verbose: true - print-hash: true - # Temp workaround since attestations are on by default as of gh-action-pypi-publish v1.11.0 - attestations: false - - mark-release: - name: 🏷️ Tag GitHub release - # Marks the GitHub release with the new version tag - needs: - - build - - release-notes - - test-pypi-publish - - pre-release-checks - - publish - # Run if all needed jobs succeeded or were skipped - if: ${{ !cancelled() && !failure() }} - environment: Release - runs-on: ubuntu-latest - permissions: - # This permission is needed by `ncipollo/release-action` to - # create the GitHub release/tag - contents: write - - defaults: - run: - working-directory: ${{ env.EFFECTIVE_WORKING_DIR }} - - steps: - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v6 - - - name: Set up Python + uv - uses: "./.github/actions/uv_setup" - with: - python-version: ${{ env.PYTHON_VERSION }} - enable-cache: "false" - - - uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8 - with: - name: dist - path: ${{ env.EFFECTIVE_WORKING_DIR }}/dist/ - - - name: Create Tag - uses: ncipollo/release-action@339a81892b84b4eeb0f6e744e4574d79d0d9b8dd # v1 - with: - # JS actions ignore `defaults.run.working-directory`, so this glob is - # resolved from the repo root. Point it at the package's `dist/` - # (where `download-artifact` placed the wheels) instead of a bare - # `dist/*`, which never matched and attached no assets to releases. - artifacts: "${{ env.EFFECTIVE_WORKING_DIR }}/dist/*" - token: ${{ secrets.GITHUB_TOKEN }} - generateReleaseNotes: false - tag: ${{needs.build.outputs.pkg-name}}==${{ needs.build.outputs.version }} - body: ${{ needs.release-notes.outputs.release-body }} - commit: ${{ github.sha }} - makeLatest: ${{ needs.build.outputs.pkg-name == 'langchain-core'}} diff --git a/.github/workflows/auto-label-by-package.yml b/.github/workflows/auto-label-by-package.yml deleted file mode 100644 index f3c9ae2490..0000000000 --- a/.github/workflows/auto-label-by-package.yml +++ /dev/null @@ -1,117 +0,0 @@ -name: Auto Label Issues by Package - -on: - issues: - types: [opened, edited] - -permissions: - contents: read - -jobs: - label-by-package: - if: github.repository_owner == 'langchain-ai' - permissions: - issues: write - runs-on: ubuntu-latest - - steps: - - name: Sync package labels - uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 - with: - script: | - const body = context.payload.issue.body || ""; - - // Extract text under "## Package" or "### Package" (handles " (Required)" suffix and being last section) - const match = body.match(/#{2,3} Package[^\n]*\n([\s\S]*?)(?:\n#{2,3} |$)/i); - if (!match) { - core.setFailed( - `Could not find "## Package" section in issue #${context.issue.number} body. ` + - `The issue template may have changed — update the regex in this workflow.` - ); - return; - } - - const packageSection = match[1].trim(); - - // Mapping table for package names to labels - const mapping = { - "langchain": "langchain", - "langchain-openai": "openai", - "langchain-anthropic": "anthropic", - "langchain-classic": "langchain-classic", - "langchain-core": "core", - "langchain-model-profiles": "model-profiles", - "langchain-tests": "standard-tests", - "langchain-text-splitters": "text-splitters", - "langchain-chroma": "chroma", - "langchain-deepseek": "deepseek", - "langchain-exa": "exa", - "langchain-fireworks": "fireworks", - "langchain-groq": "groq", - "langchain-huggingface": "huggingface", - "langchain-mistralai": "mistralai", - "langchain-nomic": "nomic", - "langchain-ollama": "ollama", - "langchain-openrouter": "openrouter", - "langchain-decodo": "decodo", - "langchain-perplexity": "perplexity", - "langchain-qdrant": "qdrant", - "langchain-xai": "xai", - }; - - // All possible package labels we manage - const allPackageLabels = Object.values(mapping); - const selectedLabels = []; - - // Check if this is checkbox format (multiple selection) - const checkboxMatches = packageSection.match(/- \[x\]\s+([^\n\r]+)/gi); - if (checkboxMatches) { - // Handle checkbox format - for (const match of checkboxMatches) { - const packageName = match.replace(/- \[x\]\s+/i, '').trim(); - const label = mapping[packageName]; - if (label && !selectedLabels.includes(label)) { - selectedLabels.push(label); - } - } - } else { - // Handle dropdown format (single selection) - const label = mapping[packageSection]; - if (label) { - selectedLabels.push(label); - } - } - - // Get current issue labels - const issue = await github.rest.issues.get({ - owner: context.repo.owner, - repo: context.repo.repo, - issue_number: context.issue.number - }); - - const currentLabels = issue.data.labels.map(label => label.name); - const currentPackageLabels = currentLabels.filter(label => allPackageLabels.includes(label)); - - // Determine labels to add and remove - const labelsToAdd = selectedLabels.filter(label => !currentPackageLabels.includes(label)); - const labelsToRemove = currentPackageLabels.filter(label => !selectedLabels.includes(label)); - - // Add new labels - if (labelsToAdd.length > 0) { - await github.rest.issues.addLabels({ - owner: context.repo.owner, - repo: context.repo.repo, - issue_number: context.issue.number, - labels: labelsToAdd - }); - } - - // Remove old labels - for (const label of labelsToRemove) { - await github.rest.issues.removeLabel({ - owner: context.repo.owner, - repo: context.repo.repo, - issue_number: context.issue.number, - name: label - }); - } diff --git a/.github/workflows/block_fork_main_prs.yml b/.github/workflows/block_fork_main_prs.yml deleted file mode 100644 index 5ff6b9a5a1..0000000000 --- a/.github/workflows/block_fork_main_prs.yml +++ /dev/null @@ -1,146 +0,0 @@ -# Block PRs whose head ref is `main` (or `master`) from a fork. This topology -# (`:master -> langchain-ai/langchain:master`) lets contributors click -# "Update branch" on the PR, producing a `Merge branch 'master' into master` -# commit on the source side that — under admin merge override — can land -# directly on `master` as a 2-parent merge commit, bypassing the repo's -# squash-only policy and polluting the changelog. -# -# `pull_request_target` is required so the job receives a token scoped to -# write PR labels/comments on fork PRs (the standard `pull_request` token is -# read-only for forks). This also means the job MUST NOT check out PR code — -# see the inline warning in the trigger block below. -# -# Maintainer bypass: add the `bypass-fork-main-check` label to the PR. - -name: Block fork main PRs - -on: - pull_request_target: - # NEVER CHECK OUT UNTRUSTED CODE FROM A PR's HEAD IN A pull_request_target JOB. - # Doing so would allow attackers to execute arbitrary code in the context of your repository. - types: [opened, reopened, synchronize, labeled, unlabeled] - -permissions: - contents: read - -jobs: - guard: - if: >- - github.repository_owner == 'langchain-ai' && - github.event.pull_request.head.repo.fork == true && - (github.event.pull_request.head.ref == 'main' || github.event.pull_request.head.ref == 'master') && - !contains(github.event.pull_request.labels.*.name, 'bypass-fork-main-check') - runs-on: ubuntu-latest - permissions: - pull-requests: write - steps: - - name: Close PR and post guidance - uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 - with: - script: | - const { owner, repo } = context.repo; - const prNumber = context.payload.pull_request.number; - const headRef = context.payload.pull_request.head.ref; - const marker = ''; - - // Ensure the warning label exists and apply it - const labelName = 'fork-main-head'; - try { - await github.rest.issues.getLabel({ owner, repo, name: labelName }); - } catch (e) { - if (e.status !== 404) { - throw new Error(`getLabel(${labelName}) failed: ${e.message}`); - } - try { - await github.rest.issues.createLabel({ - owner, repo, name: labelName, color: 'b76e79', - }); - } catch (createErr) { - // A 422 with code `already_exists` means a race created the - // label between getLabel and createLabel — safe to ignore. - // Any other 422 (bad color, name too long) indicates a real - // bug introduced by editing this step, so rethrow. - const alreadyExists = - createErr.status === 422 && - Array.isArray(createErr.errors) && - createErr.errors.some(e => e.code === 'already_exists'); - if (!alreadyExists) throw createErr; - } - } - await github.rest.issues.addLabels({ - owner, repo, issue_number: prNumber, labels: [labelName], - }); - - const defaultBranch = context.payload.repository.default_branch; - const lines = [ - marker, - `**This PR has been automatically closed** because its head branch is \`${headRef}\` on a fork.`, - '', - 'PRs opened from a fork\'s `main` (or `master`) branch can produce a `Merge branch \'main\' into main` commit on the source side. Under an admin merge override that commit can land directly on this repo\'s default branch, bypassing the squash-only policy and polluting the changelog.', - '', - 'To fix:', - `1. Sync your fork's \`${defaultBranch}\` first (\`git fetch upstream && git switch ${defaultBranch} && git merge --ff-only upstream/${defaultBranch}\`)`, - '2. Create a feature branch: `git switch -c feat/my-change`', - '3. Push it: `git push -u origin feat/my-change`', - `4. Open a new PR from \`feat/my-change\` → \`langchain-ai/langchain:${defaultBranch}\``, - '', - '*Maintainers: add the `bypass-fork-main-check` label to override.*', - ]; - const body = lines.join('\n'); - - // Dedup: update existing marker comment instead of stacking. - const comments = await github.paginate( - github.rest.issues.listComments, - { owner, repo, issue_number: prNumber, per_page: 100 }, - ); - const existing = comments.find(c => c.body && c.body.includes(marker)); - - if (!existing) { - await github.rest.issues.createComment({ - owner, repo, issue_number: prNumber, body, - }); - } else if (existing.body !== body) { - await github.rest.issues.updateComment({ - owner, repo, comment_id: existing.id, body, - }); - } - - if (context.payload.pull_request.state === 'open') { - await github.rest.pulls.update({ - owner, repo, pull_number: prNumber, state: 'closed', - }); - } - - // Cancel still-queued/in-progress checks on this PR head. - // Best-effort: new runs may still queue after this loop (e.g., other - // pull_request triggers fanning out). The PR is already closed above, - // so leftover runs are wasted compute, not a correctness issue. - // We track the cancel ratio so a wholesale failure (token-scope - // regression making EVERY cancel return 403) is surfaced rather - // than silently producing N warnings + green job. - const headSha = context.payload.pull_request.head.sha; - let attempted = 0; - let cancelled = 0; - for (const status of ['in_progress', 'queued']) { - const runs = await github.paginate( - github.rest.actions.listWorkflowRunsForRepo, - { owner, repo, head_sha: headSha, status, per_page: 100 }, - ); - for (const run of runs) { - if (run.id === context.runId) continue; - attempted++; - try { - await github.rest.actions.cancelWorkflowRun({ - owner, repo, run_id: run.id, - }); - cancelled++; - } catch (err) { - core.warning(`Could not cancel run ${run.id}: ${err.message}`); - } - } - } - if (attempted > 0 && cancelled === 0) { - core.warning(`Attempted to cancel ${attempted} run(s) on head ${headSha} but none succeeded — check token scope.`); - } - - core.setFailed(`PR head ref is \`${headRef}\` on a fork — open from a feature branch instead.`); diff --git a/.github/workflows/bump_uv_pin.yml b/.github/workflows/bump_uv_pin.yml deleted file mode 100644 index 2c2a3a4c0a..0000000000 --- a/.github/workflows/bump_uv_pin.yml +++ /dev/null @@ -1,210 +0,0 @@ -# Monthly bump of the uv pin in `.github/actions/uv_setup/action.yml`. -# -# We pin uv (rather than letting setup-uv resolve latest) because -# `releases.astral.sh` lags GitHub Releases on new uv versions, causing CI -# to flap on fresh-release days. This workflow keeps the pin fresh without -# exposing that race. -# -# Dependabot's `github-actions` ecosystem only updates `uses:` SHA pins, not -# the `UV_VERSION` env value the action passes to `astral-sh/setup-uv`, so we -# open the PR ourselves. Idempotent: if a PR for the target version already -# exists, the workflow exits without creating a duplicate. - -name: "Bump uv pin" - -on: - schedule: - - cron: "0 9 1 * *" - workflow_dispatch: - -permissions: - contents: read - -concurrency: - group: bump-uv-pin - cancel-in-progress: false - -jobs: - bump: - if: github.repository_owner == 'langchain-ai' - name: "Open PR if uv has a newer release" - runs-on: ubuntu-latest - permissions: - contents: write - pull-requests: write - steps: - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v6 - - - name: Resolve current and latest uv versions - id: versions - env: - GH_TOKEN: ${{ github.token }} - run: | - set -euo pipefail - action_file=".github/actions/uv_setup/action.yml" - current=$(grep -oE 'UV_VERSION: "[0-9]+\.[0-9]+\.[0-9]+"' "$action_file" \ - | sed -E 's/UV_VERSION: "([^"]+)"/\1/' | head -n1) - latest=$(gh api repos/astral-sh/uv/releases/latest --jq .tag_name) - semver='^[0-9]+\.[0-9]+\.[0-9]+$' - if [[ ! "$current" =~ $semver ]]; then - echo "::error::Could not parse current uv pin from $action_file (got '$current')" - exit 1 - fi - if [[ ! "$latest" =~ $semver ]]; then - echo "::error::Unexpected uv tag from GitHub API (got '$latest')" - exit 1 - fi - echo "current=$current" >> "$GITHUB_OUTPUT" - echo "latest=$latest" >> "$GITHUB_OUTPUT" - echo "branch=chore/bump-uv-$latest" >> "$GITHUB_OUTPUT" - echo "Current pin: $current" - echo "Latest uv: $latest" - - - name: Log if already up to date - # The actual skip is implemented by the `if:` guards on every - # subsequent step; this step only emits a log line so the run - # history shows why no PR was opened. - if: steps.versions.outputs.current == steps.versions.outputs.latest - run: echo "uv pin already at ${{ steps.versions.outputs.latest }}; nothing to do." - - - name: Skip if PR already open for this version - id: existing - if: steps.versions.outputs.current != steps.versions.outputs.latest - env: - GH_TOKEN: ${{ github.token }} - BRANCH: ${{ steps.versions.outputs.branch }} - run: | - set -euo pipefail - existing_json=$(gh pr list --head "$BRANCH" --state open --json number,url) - count=$(printf '%s' "$existing_json" | jq 'length') - echo "count=$count" >> "$GITHUB_OUTPUT" - if [ "$count" -gt 0 ]; then - pr_url=$(printf '%s' "$existing_json" | jq -r '.[0].url') - echo "Open PR already exists for $BRANCH; skipping." - echo "::notice::Open uv bump PR already exists: $pr_url" - fi - - - name: Wait for astral mirror to replicate - id: mirror - if: steps.versions.outputs.current != steps.versions.outputs.latest && steps.existing.outputs.count == '0' - env: - LATEST: ${{ steps.versions.outputs.latest }} - run: | - set -euo pipefail - # The mirror can lag GitHub Releases. If it hasn't replicated yet, - # defer the bump rather than landing a pin that races the mirror - # on every CI run. We probe several arches because partial - # replication (linux ready, macOS/aarch64 not) would still race - # CI on other runners. - assets=( - "uv-x86_64-unknown-linux-gnu.tar.gz" - "uv-aarch64-unknown-linux-gnu.tar.gz" - "uv-x86_64-apple-darwin.tar.gz" - "uv-aarch64-apple-darwin.tar.gz" - ) - ready=true - for asset in "${assets[@]}"; do - url="https://releases.astral.sh/github/uv/releases/download/${LATEST}/${asset}" - # `curl -sI` returns nothing on stderr at -s; capture exit code so a - # permanently broken DNS/TLS path is surfaced instead of collapsing - # to an opaque "000". - set +e - status=$(curl -sIo /dev/null -w '%{http_code}' --max-time 30 "$url" 2>/tmp/curl.err) - curl_rc=$? - set -e - echo "Mirror HEAD $url -> HTTP $status (curl exit=$curl_rc)" - if [ "$status" != "200" ]; then - ready=false - if [ "$curl_rc" -ne 0 ]; then - echo "::warning::curl failed for $asset (exit=$curl_rc): $(cat /tmp/curl.err 2>/dev/null || true)" - else - echo "::warning::astral mirror has not replicated $asset for uv $LATEST yet (HTTP $status)." - fi - fi - done - if [ "$ready" = "true" ]; then - echo "ready=true" >> "$GITHUB_OUTPUT" - else - echo "ready=false" >> "$GITHUB_OUTPUT" - echo "::warning::Deferring uv bump to $LATEST until all probed arches are mirrored." - fi - - - name: Open bump PR - if: steps.versions.outputs.current != steps.versions.outputs.latest && steps.existing.outputs.count == '0' && steps.mirror.outputs.ready == 'true' - env: - GH_TOKEN: ${{ github.token }} - CURRENT: ${{ steps.versions.outputs.current }} - LATEST: ${{ steps.versions.outputs.latest }} - BRANCH: ${{ steps.versions.outputs.branch }} - DEFAULT_BRANCH: ${{ github.event.repository.default_branch }} - run: | - set -euo pipefail - action_file=".github/actions/uv_setup/action.yml" - - # `grep -c` returns 1 on no-match and 2 on read errors. We want - # "no match" surfaced as the explicit count-of-zero check below; - # read errors must abort. Capture the exit code separately so - # `set -e` doesn't swallow either case. - set +e - before=$(grep -cE "UV_VERSION: \"${CURRENT}\"" "$action_file") - before_rc=$? - set -e - if [ "$before_rc" -gt 1 ]; then - echo "::error::grep read error on $action_file (exit=$before_rc)" - exit 1 - fi - if [ "$before" -ne 1 ]; then - echo "::error::Expected exactly 1 'UV_VERSION: \"$CURRENT\"' in $action_file, found $before" - exit 1 - fi - sed -i -E "s/UV_VERSION: \"${CURRENT}\"/UV_VERSION: \"${LATEST}\"/" "$action_file" - set +e - after=$(grep -cE "UV_VERSION: \"${LATEST}\"" "$action_file") - after_rc=$? - set -e - if [ "$after_rc" -gt 1 ]; then - echo "::error::grep read error on $action_file (exit=$after_rc)" - exit 1 - fi - if [ "$after" -ne 1 ]; then - echo "::error::Expected exactly 1 'UV_VERSION: \"$LATEST\"' after sed, found $after" - exit 1 - fi - if git diff --quiet "$action_file"; then - echo "No changes after sed; bailing out (current=$CURRENT, latest=$LATEST)." - exit 1 - fi - - # Reuse-or-recreate orphan branch from a prior run that pushed - # but failed before `gh pr create` (no open PR sits on it). - # The delete can race a concurrent run (manual workflow_dispatch - # firing while the cron is mid-flight, since concurrency group - # does not cancel-in-progress); fall through with a warning so a - # losing race does not kill an otherwise-clean job mid-state. - if git ls-remote --exit-code --heads origin "$BRANCH" >/dev/null 2>&1; then - echo "::warning::Branch $BRANCH exists on origin without an open PR; deleting before recreating." - if ! git push origin --delete "$BRANCH"; then - echo "::warning::Delete of $BRANCH failed (concurrent run, or branch already gone); the subsequent push will surface any real conflict." - fi - fi - - git config --local user.name "github-actions[bot]" - git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com" - git checkout -b "$BRANCH" - git add "$action_file" - git commit -m "chore(deps): bump uv to $LATEST" - git push --set-upstream origin "$BRANCH" - - body_file="$(mktemp)" - { - printf 'Bumps the uv pin in `.github/actions/uv_setup/action.yml` from `%s` to [`%s`](https://github.com/astral-sh/uv/releases/tag/%s).\n\n' "$CURRENT" "$LATEST" "$LATEST" - printf 'Opened automatically by `bump_uv_pin.yml`. Mirror availability on `releases.astral.sh` was verified before this PR was created, so CI should not race the fallback.\n' - } > "$body_file" - - pr_url=$(gh pr create \ - --head "$BRANCH" \ - --base "$DEFAULT_BRANCH" \ - --title "chore(deps): bump uv to $LATEST" \ - --body-file "$body_file") - echo "Opened uv bump PR: $pr_url" - echo "::notice::Opened uv bump PR: $pr_url" diff --git a/.github/workflows/check_agents_sync.yml b/.github/workflows/check_agents_sync.yml deleted file mode 100644 index 2d895d8ca5..0000000000 --- a/.github/workflows/check_agents_sync.yml +++ /dev/null @@ -1,43 +0,0 @@ -# Ensures CLAUDE.md and AGENTS.md stay synchronized. -# -# These files contain the same development guidelines but are named differently -# for compatibility with different AI coding assistants (Claude Code uses CLAUDE.md, -# other tools may use AGENTS.md). - -name: "🔄 Check CLAUDE.md / AGENTS.md Sync" - -on: - push: - branches: [master] - paths: - - "CLAUDE.md" - - "AGENTS.md" - pull_request: - paths: - - "CLAUDE.md" - - "AGENTS.md" - -permissions: - contents: read - -jobs: - check-sync: - name: "verify files are identical" - if: github.repository_owner == 'langchain-ai' - runs-on: ubuntu-latest - steps: - - name: "📋 Checkout Code" - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v6 - - - name: "🔍 Check CLAUDE.md and AGENTS.md are in sync" - run: | - if ! diff -q CLAUDE.md AGENTS.md > /dev/null 2>&1; then - echo "❌ CLAUDE.md and AGENTS.md are out of sync!" - echo "" - echo "These files must contain identical content." - echo "Differences:" - echo "" - diff --color=always CLAUDE.md AGENTS.md || true - exit 1 - fi - echo "✅ CLAUDE.md and AGENTS.md are in sync" diff --git a/.github/workflows/check_diffs.yml b/.github/workflows/check_diffs.yml index 6307c94250..24bf0b35c8 100644 --- a/.github/workflows/check_diffs.yml +++ b/.github/workflows/check_diffs.yml @@ -189,22 +189,6 @@ jobs: # and `set -e` above will cause the step to fail. echo "$STATUS" | grep 'nothing to commit, working tree clean' - # Verify _release.yml dropdown options stay in sync with package directories - check-release-options: - name: "Validate Release Options" - if: github.repository_owner == 'langchain-ai' - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v6 - - name: "🐍 Setup Python 3.11" - uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0 - with: - python-version: "3.11" - - name: "📦 Install Dependencies" - run: python -m pip install pyyaml pytest - - name: "🔍 Check release dropdown matches packages" - run: python -m pytest .github/scripts/test_release_options.py -v - # Final status check - ensures all required jobs passed before allowing merge ci_success: name: "✅ CI Success" @@ -217,7 +201,6 @@ jobs: vcr-tests, extended-tests, test-pydantic, - check-release-options, ] if: | always() diff --git a/.github/workflows/check_extras_sync.yml b/.github/workflows/check_extras_sync.yml deleted file mode 100644 index 089e80a23a..0000000000 --- a/.github/workflows/check_extras_sync.yml +++ /dev/null @@ -1,73 +0,0 @@ -# See `.github/scripts/check_extras_sync.py` for the rationale. - -name: "🔍 Check Extras Sync" - -on: - pull_request: - paths: - - "libs/**/pyproject.toml" - - ".github/scripts/check_extras_sync.py" - - ".github/workflows/check_extras_sync.yml" - push: - branches: [master] - paths: - - "libs/**/pyproject.toml" - - ".github/scripts/check_extras_sync.py" - - ".github/workflows/check_extras_sync.yml" - -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true - -permissions: - contents: read - -jobs: - check-extras-sync: - if: github.repository_owner == 'langchain-ai' - name: "Verify extras match required deps" - runs-on: ubuntu-latest - timeout-minutes: 2 - steps: - - name: "📋 Checkout Code" - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v6 - - - name: "🐍 Set up Python and uv" - uses: "./.github/actions/uv_setup" - with: - python-version: "3.13" - enable-cache: "false" - - - name: "🔍 Check extras sync" - # Iterate every package pyproject.toml under libs/. The script - # no-ops on packages without [project.optional-dependencies], so - # this is harmless on packages without extras and automatically - # picks up new partners as they're added. No `-maxdepth` cap so - # deeper future restructures (e.g. `libs/partners///`) - # are picked up automatically. - run: | - set -euo pipefail - mapfile -t files < <( - find libs -name pyproject.toml \ - -not -path "*/.venv/*" \ - -not -path "*/node_modules/*" \ - -not -path "*/build/*" \ - -not -path "*/dist/*" \ - -not -path "*/.tox/*" \ - | sort - ) - if [ ${#files[@]} -eq 0 ]; then - echo "::error::No pyproject.toml files found under libs/" - exit 1 - fi - failed=() - for f in "${files[@]}"; do - if ! python .github/scripts/check_extras_sync.py "$f"; then - failed+=("$f") - fi - done - if [ ${#failed[@]} -gt 0 ]; then - echo "::error::Extras-sync check failed for ${#failed[@]} package(s):" - printf '::error:: %s\n' "${failed[@]}" - exit 1 - fi diff --git a/.github/workflows/check_release_deps.yml b/.github/workflows/check_release_deps.yml deleted file mode 100644 index 28b0ad047c..0000000000 --- a/.github/workflows/check_release_deps.yml +++ /dev/null @@ -1,288 +0,0 @@ -# Validate that a release PR's declared dependencies are actually published on -# PyPI *before* the package itself is released. -# -# WHY: `release(scope): x.y.z` PRs frequently bump intra-monorepo minimum pins -# (e.g. `langchain-core>=1.4.4`). The regular PR test suite deliberately SKIPS -# minimum-version resolution for langchain-core / langchain / langchain-text-splitters -# (see `SKIP_IF_PULL_REQUEST` in `.github/scripts/get_min_versions.py`) because normal -# feature PRs may bump those in lockstep with an as-yet-unpublished sibling release. -# -# For a `release` PR, though, every runtime dependency should already be on PyPI -# unless that dependency is another package version introduced by the same PR. -# If a pin points at any other version that does not exist yet, the published wheel's -# metadata is unresolvable and `pip install ==x.y.z` breaks for end users. Without this -# workflow, that is only caught at release-trigger time, when `get_min_versions.py` -# resolves the pins against PyPI (its companion change in this PR now exits loudly on -# an unpublished pin instead of emitting `pkg==None`). This workflow adds a second, -# earlier guard: it shifts the same check left onto the release PR, so the author -# finds out before merge rather than when the release job runs. -# -# HOW: for each changed manifest, diff it against the PR base to find packages whose -# own version is bumped by this PR, then resolve each package's runtime dependencies -# against real PyPI with `uv pip compile --no-sources` — which ignores the editable -# `[tool.uv.sources]` workspace overrides so intra-monorepo deps resolve from the index -# exactly as an end user's installer would see them. Dependencies that a same-PR version -# bump satisfies are stripped first (their wheels are not published until merge); -# everything else must resolve. This reads package index, git, and TOML metadata only — -# it does not build or run the PR's own project code. - -name: "🚀 Check Release Dependencies" - -on: - pull_request: - types: [opened, synchronize, reopened, edited, labeled, unlabeled] - paths: - - "libs/**/pyproject.toml" - -permissions: - contents: read - -jobs: - check-release-deps: - name: "✅ Verify release dependencies exist on PyPI" - # Only run for release PRs (`release(scope): x.y.z`). Other PRs may bump - # intra-monorepo pins ahead of a sibling release on purpose. Maintainers can - # acknowledge an unusual coordinated release with the bypass label. - if: >- - github.repository_owner == 'langchain-ai' && - startsWith(github.event.pull_request.title, 'release') && - !contains(github.event.pull_request.labels.*.name, 'release-deps: acknowledged') - runs-on: ubuntu-latest - timeout-minutes: 10 - steps: - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v6 - with: - fetch-depth: 0 - - - name: "🐍 Set up Python + uv" - uses: "./.github/actions/uv_setup" - with: - python-version: "3.12" - enable-cache: "false" - - - name: "🔍 Resolve runtime dependencies against PyPI" - shell: bash - env: - # Sourced from env so the `${{ }}` expansion never lands in the `run:` - # block; the SHAs reach git only via list-form subprocess (no shell). - BASE_SHA: ${{ github.event.pull_request.base.sha }} - HEAD_SHA: ${{ github.event.pull_request.head.sha }} - run: | - set -euo pipefail - - # pyproject.toml manifests changed by this PR. - mapfile -t changed < <( - git diff --name-only "$BASE_SHA" "$HEAD_SHA" -- 'libs/**/pyproject.toml' - ) - - if [ "${#changed[@]}" -eq 0 ]; then - # The `paths:` filter should prevent this, so an empty list is - # surprising — surface it loudly rather than passing silently. - echo "::notice::No libs/**/pyproject.toml changed in this PR; nothing to validate." - exit 0 - fi - - tmp_dir="$(mktemp -d)" - trap 'rm -rf "$tmp_dir"' EXIT - - # Step 1: detect packages whose own version is bumped by this PR. Their - # wheels are not on PyPI until merge, so dependencies the new version - # satisfies are stripped before resolving. Emits one TSV row per bump: - # `\t\t`. `uv run --with packaging` - # guarantees the PEP 508/440 parser is available on the runner. - printf '%s\n' "${changed[@]}" > "$tmp_dir/changed.txt" - uv run -q --no-project --with packaging python - "$BASE_SHA" "$tmp_dir/changed.txt" "$tmp_dir/released.txt" <<'PY' - import subprocess - import sys - import tomllib - from pathlib import Path - - from packaging.utils import canonicalize_name - - base_sha = sys.argv[1] - changed_path = Path(sys.argv[2]) - released_path = Path(sys.argv[3]) - - def project_table(text: str) -> dict: - return tomllib.loads(text).get("project") or {} - - released = [] - for manifest in changed_path.read_text(encoding="utf-8").splitlines(): - current = project_table(Path(manifest).read_text(encoding="utf-8")) - name, version = current.get("name"), current.get("version") - if name is None or version is None: - # No static name/version (e.g. a dynamic version) — it cannot be - # compared against the base, so cannot be a same-PR bump. - print(f"::warning file={manifest}::no static project.name/version; skipping bump detection") - continue - shown = subprocess.run( - ["git", "show", f"{base_sha}:{manifest}"], - capture_output=True, - text=True, - ) - if shown.returncode != 0: - stderr = shown.stderr.strip() - if "does not exist" in stderr or "exists on disk, but not in" in stderr: - # New manifest: absent at the base ref, so not a version bump. - continue - print(f"::error file={manifest}::failed to read base manifest: {stderr}") - sys.exit(1) - base = project_table(shown.stdout) - if base.get("name") == name and base.get("version") not in (None, version): - released.append(f"{canonicalize_name(name)}\t{name}\t{version}") - - released_path.write_text("".join(f"{row}\n" for row in released), encoding="utf-8") - PY - - if [ -s "$tmp_dir/released.txt" ]; then - echo "The following package versions are introduced by this PR and may be referenced before PyPI publication:" - cut -f2- "$tmp_dir/released.txt" | sed 's/^/ - /' - else - echo "No package version bumps found in changed manifests." - fi - - failed=0 - transient=0 - for manifest in "${changed[@]}"; do - pkg_dir="$(dirname "$manifest")" - filtered_dir="$tmp_dir/${manifest//\//__}.dir" - mkdir -p "$filtered_dir" - filtered_manifest="$filtered_dir/pyproject.toml" - # Step 2: rebuild a resolver-equivalent manifest that drops only the - # dependencies a same-PR version bump satisfies. `[tool.uv]` keys that - # affect resolution (prerelease, constraint/override deps) are preserved - # — e.g. `langchain-fireworks` needs `prerelease = "allow"` to resolve - # its prerelease-only `fireworks-ai` pin. Skipped deps print here, before - # the resolver group opens, so the exclusions stay visible on a green run. - uv run -q --no-project --with packaging python - "$manifest" "$filtered_manifest" "$tmp_dir/released.txt" <<'PY' - import json - import sys - import tomllib - from pathlib import Path - - from packaging.requirements import InvalidRequirement, Requirement - from packaging.utils import canonicalize_name - - manifest_path = Path(sys.argv[1]) - filtered_path = Path(sys.argv[2]) - released_path = Path(sys.argv[3]) - - released_versions = {} - for line in released_path.read_text(encoding="utf-8").splitlines(): - canonical_name, _name, version = line.split("\t", maxsplit=2) - released_versions[canonical_name] = version - - def is_same_pr_bump(dependency: str) -> bool: - try: - requirement = Requirement(dependency) - except InvalidRequirement: - # Keep anything we cannot parse so the resolver judges it. - return False - version = released_versions.get(canonicalize_name(requirement.name)) - if version is None: - return False - # Strip only when the just-bumped version satisfies the pin; a pin to - # any other (still unpublished) version must keep resolving. - return requirement.specifier.contains(version, prereleases=True) - - data = tomllib.loads(manifest_path.read_text(encoding="utf-8")) - project = data.get("project") - if project is None: - print(f"::error file={manifest_path}::no [project] table to resolve") - sys.exit(1) - - filtered_dependencies, skipped_dependencies = [], [] - for dependency in project.get("dependencies", []): - bucket = skipped_dependencies if is_same_pr_bump(dependency) else filtered_dependencies - bucket.append(dependency) - - def toml_string(value: str) -> str: - return json.dumps(value) - - lines = ["[project]"] - lines.append(f"name = {toml_string(project.get('name') or 'release-deps-check')}") - lines.append(f"version = {toml_string(project.get('version') or '0.0.0')}") - if "requires-python" in project: - lines.append(f"requires-python = {toml_string(project['requires-python'])}") - lines.append("dependencies = [") - lines += [f" {toml_string(dependency)}," for dependency in filtered_dependencies] - lines.append("]") - - # Preserve the `[tool.uv]` keys that change PyPI resolution. `[tool.uv.sources]` - # is intentionally dropped — `uv pip compile --no-sources` ignores it anyway. - tool_uv = (data.get("tool") or {}).get("uv") or {} - uv_lines = [] - if isinstance(tool_uv.get("prerelease"), str): - uv_lines.append(f"prerelease = {toml_string(tool_uv['prerelease'])}") - for key in ("constraint-dependencies", "override-dependencies"): - values = tool_uv.get(key) or [] - if values: - uv_lines.append(f"{key} = [") - uv_lines += [f" {toml_string(value)}," for value in values] - uv_lines.append("]") - if uv_lines: - lines.append("") - lines.append("[tool.uv]") - lines += uv_lines - - filtered_path.write_text("\n".join(lines) + "\n", encoding="utf-8") - - if skipped_dependencies: - print("Ignoring dependencies satisfied by package versions introduced by this PR:") - for dependency in skipped_dependencies: - print(f" - {dependency}") - PY - - echo "::group::Resolving ${manifest} against PyPI" - # --no-sources ignores [tool.uv.sources] editable workspace overrides, - # so intra-monorepo deps resolve from PyPI like an end-user install. - # --universal resolves across the full requires-python range, so deps - # gated behind Python-version markers are validated too. - if uv pip compile --no-sources --universal "$filtered_manifest" > "$filtered_dir/compile.log" 2>&1; then - echo "✅ ${pkg_dir}: all runtime dependencies resolve on PyPI or are released by this PR" - else - # Surface the resolver's reason (stdout+stderr were captured) and tell a - # likely-transient index/network error apart from a genuinely bad pin. - cat "$filtered_dir/compile.log" - if grep -qiE 'error sending request|failed to fetch|error trying to connect|connection|timed out|temporarily unavailable|status code (429|50[0-9])' "$filtered_dir/compile.log"; then - echo "❌ ${pkg_dir}: resolver hit a possible transient PyPI/index error" - transient=1 - else - echo "❌ ${pkg_dir}: a dependency pin is not satisfiable on PyPI" - fi - failed=1 - fi - echo "::endgroup::" - done - - if [ "$failed" -ne 0 ]; then - if [ "$transient" -ne 0 ]; then - echo "::warning::A failure looked like a network/index error rather than an unsatisfiable pin — re-running the job may clear it." - fi - cat >&2 <<'EOF' - - ┌──────────────────────────────────────────────────────────────────┐ - │ One or more dependency pins could not be resolved from PyPI. │ - │ See the per-package resolver output above for the exact reason. │ - └──────────────────────────────────────────────────────────────────┘ - - Dependencies on package versions introduced by this PR are ignored, - because coordinated release metadata may point at wheels that are not - published until this PR merges. Any remaining failure means the released - wheel metadata may be unresolvable for end users. - - Fix by: - • Releasing the dependency package first so the pinned version exists - on PyPI, then re-running this check; or - • Relaxing the version pin to a published version. - - If this is an intentional coordinated release outside the detected - package version bumps, a maintainer may add the label - `release-deps: acknowledged` to bypass this check after reviewing the - install risk. - - If the resolver output above shows a network/index error (rather than - "No solution found"), this may be a transient PyPI issue — re-run the job. - EOF - exit 1 - fi diff --git a/.github/workflows/check_versions.yml b/.github/workflows/check_versions.yml deleted file mode 100644 index e99d4a1b3c..0000000000 --- a/.github/workflows/check_versions.yml +++ /dev/null @@ -1,55 +0,0 @@ -# Ensures version numbers in pyproject.toml and _version.py stay in sync. -# -# (Prevents releases with mismatched version numbers) - -name: "Check Version Equality" - -on: - pull_request: - paths: - - "libs/core/pyproject.toml" - - "libs/core/langchain_core/version.py" - - "libs/langchain_v1/pyproject.toml" - - "libs/langchain_v1/langchain/__init__.py" - - "libs/partners/*/pyproject.toml" - - "libs/partners/**/_version.py" - -permissions: - contents: read - -jobs: - check_version_equality: - if: github.repository_owner == 'langchain-ai' - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v6 - - - uses: astral-sh/setup-uv@0ca8f610542aa7f4acaf39e65cf4eb3c35091883 # v7 - with: - python-version: "3.12" - - - name: "Verify pyproject.toml & version files match" - run: | - FAILED=0 - - for dir in libs/core libs/langchain_v1 libs/partners/*; do - [ -f "$dir/Makefile" ] || continue - if grep -q '^check_version:' "$dir/Makefile"; then - echo "--- $dir ---" - make -C "$dir" check_version || FAILED=1 - elif find "$dir" -maxdepth 2 -name '_version.py' -not -path '*/tests/*' \ - | grep -q .; then - # A package ships a _version.py but has no way to verify it stays - # in sync with pyproject.toml. Don't let it pass unchecked. - echo "--- $dir ---" - echo "Error: $dir has a _version.py but no 'check_version' Makefile target" - FAILED=1 - fi - done - - if [ "$FAILED" -ne 0 ]; then - echo "" - echo "One or more version checks failed!" - exit 1 - fi diff --git a/.github/workflows/close_unchecked_issues.yml b/.github/workflows/close_unchecked_issues.yml deleted file mode 100644 index 28b9ac9388..0000000000 --- a/.github/workflows/close_unchecked_issues.yml +++ /dev/null @@ -1,197 +0,0 @@ -# Auto-close issues that bypass or ignore the issue template checkboxes. -# -# GitHub issue forms enforce `required: true` checkboxes in the web UI, -# but the API bypasses form validation entirely — bots/scripts can open -# issues with every box unchecked or skip the template altogether. -# -# Rules: -# 0. No issue type -> close unless author is an org member -# 1. No checkboxes at all -> close unless author is an org member or bot -# 2. Checkboxes present but none checked -> close -# 3. "Submission checklist" section incomplete -> close -# 4. "Package (Required)" section has no selection -> close -# -# Org membership check reuses the shared helper from pr-labeler.js and -# the same GitHub App used by tag-external-issues.yml. - -name: Close Unchecked Issues - -on: - issues: - types: [opened] - -permissions: - contents: read - -concurrency: - group: ${{ github.workflow }}-${{ github.event.issue.number }} - cancel-in-progress: true - -jobs: - check-boxes: - if: github.repository_owner == 'langchain-ai' - runs-on: ubuntu-latest - permissions: - contents: read - issues: write - - steps: - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v6 - - - name: Generate GitHub App token - id: app-token - uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3 - with: - client-id: ${{ secrets.ORG_MEMBERSHIP_APP_CLIENT_ID }} - private-key: ${{ secrets.ORG_MEMBERSHIP_APP_PRIVATE_KEY }} - - - name: Validate issue checkboxes - if: steps.app-token.outcome == 'success' - uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 - with: - github-token: ${{ steps.app-token.outputs.token }} - script: | - const { owner, repo } = context.repo; - const issue_number = context.payload.issue.number; - const body = context.payload.issue.body ?? ''; - const allChecked = (body.match(/- \[x\]/gi) || []).length; - const allUnchecked = (body.match(/- \[ \]/g) || []).length; - const total = allChecked + allUnchecked; - - // ── Helpers ───────────────────────────────────────────────── - // Extract checkboxes under a markdown H2/H3 heading. - // Returns { checked, unchecked } counts, or null if the - // section heading is not found in the body. - function parseSection(heading) { - const escaped = heading.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); - // Find the heading line - const headingRe = new RegExp(`^#{2,3}\\s+${escaped}\\s*$`, 'm'); - const headingMatch = headingRe.exec(body); - if (!headingMatch) return null; - // Slice from after the heading to the next heading or end - const rest = body.slice(headingMatch.index + headingMatch[0].length); - const nextHeading = rest.search(/\n#{2,3}\s/); - const block = nextHeading === -1 ? rest : rest.slice(0, nextHeading); - return { - checked: (block.match(/- \[x\]/gi) || []).length, - unchecked: (block.match(/- \[ \]/g) || []).length, - }; - } - - let _cachedMember; - async function isOrgMember() { - if (_cachedMember) return _cachedMember; - const { h } = require('./.github/scripts/pr-labeler.js') - .loadAndInit(github, owner, repo, core); - const author = context.payload.sender.login; - const { isExternal } = await h.checkMembership( - author, context.payload.sender.type, - ); - _cachedMember = { internal: !isExternal, author }; - return _cachedMember; - } - - async function closeWithComment(lines) { - const templateUrl = `https://github.com/${owner}/${repo}/issues/new/choose`; - lines.push( - '', - `Please use one of the [issue templates](${templateUrl}).`, - ); - - // Post comment first so the author sees the reason even if - // the subsequent close call fails. - await github.rest.issues.createComment({ - owner, repo, issue_number, - body: lines.join('\n'), - }); - - await github.rest.issues.update({ - owner, repo, issue_number, - state: 'closed', - state_reason: 'not_planned', - }); - } - - // ── Rule 0: no issue type (API/CLI bypass) ────────────────── - // Issue types are set automatically when using web UI templates. - // External users cannot set issue types via the API (requires - // write/triage permissions), so a missing type reliably indicates - // programmatic submission. - if (!context.payload.issue.type) { - let membership; - try { - membership = await isOrgMember(); - } catch (e) { - // Org membership check failed — skip Rule 0 and let - // Rules 1-4 handle validation via checkboxes. - core.warning(`Rule 0: org membership check failed, skipping: ${e.message}`); - } - if (membership?.internal) { - console.log(`No issue type, but ${membership.author} is internal — OK`); - } else if (membership) { - console.log(`No issue type and ${membership.author} is external — closing`); - await closeWithComment([ - 'This issue was automatically closed because it appears to have been submitted programmatically — issue types are automatically set when using the GitHub web interface, and this issue has none.', - '', - 'We do not allow automated issue submission at this time.', - ]); - return; - } - } - - // ── Rule 1: no checkboxes at all ──────────────────────────── - if (total === 0) { - const { internal, author } = await isOrgMember(); - if (internal) { - console.log(`No checkboxes, but ${author} is internal — OK`); - return; - } - console.log(`No checkboxes and ${author} is external — closing`); - await closeWithComment([ - 'This issue was automatically closed because no issue template was used.', - ]); - return; - } - - // ── Rule 2: checkboxes present but none checked ───────────── - if (allChecked === 0) { - console.log(`${allUnchecked} checkbox(es) present, none checked — closing`); - await closeWithComment([ - 'This issue was automatically closed because none of the required checkboxes were checked. Please re-file using an issue template and complete the checklist.', - ]); - return; - } - - // ── Rules 3–4: parse sections for targeted feedback ───────── - const checklist = parseSection('Submission checklist'); - const pkg = parseSection('Package (Required)'); - console.log(`Section parse — checklist: ${JSON.stringify(checklist)}, pkg: ${JSON.stringify(pkg)}`); - - const problems = []; - - if (checklist && checklist.unchecked > 0) { - problems.push( - 'the submission checklist is incomplete — please confirm you searched for duplicates, included a reproduction, etc.' - ); - } - if (pkg !== null && pkg.checked === 0) { - problems.push( - 'no package was selected (e.g. langchain-core, langchain, langgraph) — this helps us route the issue to the right team' - ); - } else if (pkg === null) { - problems.push( - 'the package selection is missing (e.g. langchain-core, langchain, langgraph) — this helps us route the issue to the right team' - ); - } - - if (problems.length === 0) { - console.log(`All section checks passed (${allChecked} checked) — OK`); - return; - } - - console.log(`Closing — problems: ${problems.join('; ')}`); - await closeWithComment([ - 'Thanks for opening an issue! It was automatically closed because:', - '', - ...problems.map(p => `- ${p}`), - ]); diff --git a/.github/workflows/codspeed.yml b/.github/workflows/codspeed.yml deleted file mode 100644 index ff3c97a817..0000000000 --- a/.github/workflows/codspeed.yml +++ /dev/null @@ -1,85 +0,0 @@ -# CodSpeed performance benchmarks. -# -# Runs benchmarks on changed packages and uploads results to CodSpeed. -# Separated from the main CI workflow so that push-to-master baseline runs -# are never cancelled by subsequent merges (cancel-in-progress is only -# enabled for pull_request events). - -name: "⚡ CodSpeed" - -on: - push: - branches: [master] - pull_request: - -# On PRs, cancel stale runs when new commits are pushed. -# On push-to-master, never cancel — these runs populate CodSpeed baselines. -concurrency: - group: ${{ github.workflow }}-${{ github.event_name == 'push' && github.sha || github.ref }} - cancel-in-progress: ${{ github.event_name == 'pull_request' }} - -permissions: - contents: read - -env: - UV_FROZEN: "true" - UV_NO_SYNC: "true" - -jobs: - build: - name: "Detect Changes" - runs-on: ubuntu-latest - if: ${{ github.repository_owner == 'langchain-ai' && !contains(github.event.pull_request.labels.*.name, 'codspeed-ignore') }} - steps: - - name: "📋 Checkout Code" - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v6 - - name: "🐍 Setup Python 3.11" - uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0 - with: - python-version: "3.11" - - name: "📂 Get Changed Files" - id: files - uses: Ana06/get-changed-files@25f79e676e7ea1868813e21465014798211fad8c # v2.3.0 - with: - format: json - - name: "🔍 Analyze Changed Files" - id: set-matrix - env: - ALL_CHANGED_FILES: ${{ steps.files.outputs.all }} - run: | - python -m pip install packaging requests - python .github/scripts/check_diff.py "$ALL_CHANGED_FILES" >> $GITHUB_OUTPUT - outputs: - codspeed: ${{ steps.set-matrix.outputs.codspeed }} - - benchmarks: - name: "⚡ CodSpeed Benchmarks" - needs: [build] - if: ${{ needs.build.outputs.codspeed != '[]' }} - runs-on: codspeed-macro - strategy: - matrix: - job-configs: ${{ fromJson(needs.build.outputs.codspeed) }} - fail-fast: false - steps: - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v6 - - - name: "📦 Install UV Package Manager" - uses: astral-sh/setup-uv@0ca8f610542aa7f4acaf39e65cf4eb3c35091883 # v7 - with: - # Pinned to 3.13.11 to work around CodSpeed walltime segfault on 3.13.12+ - # See: https://github.com/CodSpeedHQ/pytest-codspeed/issues/106 - python-version: "3.13.11" - - - name: "📦 Install Test Dependencies" - run: uv sync --group test - working-directory: ${{ matrix.job-configs.working-directory }} - - - name: "⚡ Run Benchmarks: ${{ matrix.job-configs.working-directory }}" - uses: CodSpeedHQ/action@a50965600eafa04edcd6717761f55b77e52aafbd # v4 - with: - token: ${{ secrets.CODSPEED_TOKEN }} - run: | - cd ${{ matrix.job-configs.working-directory }} - uv run --no-sync pytest ./tests/benchmarks --codspeed - mode: ${{ matrix.job-configs.codspeed-mode }} diff --git a/.github/workflows/pr_labeler.yml b/.github/workflows/pr_labeler.yml deleted file mode 100644 index 9982500310..0000000000 --- a/.github/workflows/pr_labeler.yml +++ /dev/null @@ -1,214 +0,0 @@ -# Unified PR labeler — applies size, file-based, title-based, and -# contributor classification labels in a single sequential workflow. -# -# Consolidates pr_labeler_file.yml, pr_labeler_title.yml, -# pr_size_labeler.yml, and PR-handling from tag-external-contributions.yml -# into one workflow to eliminate race conditions from concurrent label -# mutations. tag-external-issues.yml remains active for issue-only -# labeling. Backfill lives in pr_labeler_backfill.yml. -# -# Config and shared logic live in .github/scripts/pr-labeler-config.json -# and .github/scripts/pr-labeler.js — update those when adding partners. -# -# Setup Requirements: -# 1. Create a GitHub App with permissions: -# - Repository: Pull requests (write) -# - Repository: Issues (write) -# - Organization: Members (read) -# 2. Install the app on your organization and this repository -# 3. Add these repository secrets: -# - ORG_MEMBERSHIP_APP_CLIENT_ID: Your app's client ID -# - ORG_MEMBERSHIP_APP_PRIVATE_KEY: Your app's private key -# -# The GitHub App token is required to check private organization membership -# and to propagate label events to downstream workflows. - -name: "🏷️ PR Labeler" - -on: - # Safe since we're not checking out or running the PR's code. - # NEVER CHECK OUT UNTRUSTED CODE FROM A PR's HEAD IN A pull_request_target JOB. - # Doing so would allow attackers to execute arbitrary code in the context of your repository. - pull_request_target: - types: [opened, synchronize, reopened, edited] - -permissions: - contents: read - -concurrency: - # Separate opened events so external/tier labels are never lost to cancellation - group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.run_id }}-${{ github.event.action == 'opened' && 'opened' || 'update' }} - cancel-in-progress: ${{ github.event.action != 'opened' }} - -jobs: - label: - if: github.repository_owner == 'langchain-ai' - runs-on: ubuntu-latest - permissions: - contents: read - pull-requests: write - issues: write - - steps: - # Checks out the BASE branch (safe for pull_request_target — never - # the PR head). Needed to load .github/scripts/pr-labeler*. - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v6 - - - name: Generate GitHub App token - if: github.event.action == 'opened' - id: app-token - uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3 - with: - client-id: ${{ secrets.ORG_MEMBERSHIP_APP_CLIENT_ID }} - private-key: ${{ secrets.ORG_MEMBERSHIP_APP_PRIVATE_KEY }} - - - name: Verify App token - if: github.event.action == 'opened' - run: | - if [ -z "${{ steps.app-token.outputs.token }}" ]; then - echo "::error::GitHub App token generation failed — cannot classify contributor" - exit 1 - fi - - - name: Check org membership - if: github.event.action == 'opened' - id: check-membership - uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 - with: - github-token: ${{ steps.app-token.outputs.token }} - script: | - const { owner, repo } = context.repo; - const { h } = require('./.github/scripts/pr-labeler.js').loadAndInit(github, owner, repo, core); - - const author = context.payload.sender.login; - const { isExternal } = await h.checkMembership( - author, context.payload.sender.type, - ); - core.setOutput('is-external', isExternal ? 'true' : 'false'); - - - name: Apply PR labels - uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 - env: - IS_EXTERNAL: ${{ steps.check-membership.outputs.is-external }} - with: - github-token: ${{ secrets.GITHUB_TOKEN }} - script: | - const { owner, repo } = context.repo; - const { h } = require('./.github/scripts/pr-labeler.js').loadAndInit(github, owner, repo, core); - - const pr = context.payload.pull_request; - if (!pr) return; - const prNumber = pr.number; - const action = context.payload.action; - - const toAdd = new Set(); - const toRemove = new Set(); - - const currentLabels = (await github.paginate( - github.rest.issues.listLabelsOnIssue, - { owner, repo, issue_number: prNumber, per_page: 100 }, - )).map(l => l.name ?? ''); - - // ── Size + file labels (skip on 'edited' — files unchanged) ── - if (action !== 'edited') { - for (const sl of h.sizeLabels) await h.ensureLabel(sl); - - const files = await github.paginate(github.rest.pulls.listFiles, { - owner, repo, pull_number: prNumber, per_page: 100, - }); - - const { totalChanged, sizeLabel } = h.computeSize(files); - toAdd.add(sizeLabel); - for (const sl of h.sizeLabels) { - if (currentLabels.includes(sl) && sl !== sizeLabel) toRemove.add(sl); - } - console.log(`Size: ${totalChanged} changed lines → ${sizeLabel}`); - - for (const label of h.matchFileLabels(files)) { - toAdd.add(label); - } - } - - // ── Title-based labels ── - const { labels: titleLabels, typeLabel } = h.matchTitleLabels(pr.title || ''); - for (const label of titleLabels) toAdd.add(label); - - // Remove stale type labels only when a type was detected - if (typeLabel) { - for (const tl of h.allTypeLabels) { - if (currentLabels.includes(tl) && !titleLabels.has(tl)) toRemove.add(tl); - } - } - - // ── Internal label (only on open, non-external contributors) ── - // IS_EXTERNAL is empty string on non-opened events (step didn't - // run), so this guard is only true for opened + internal. - if (action === 'opened' && process.env.IS_EXTERNAL === 'false') { - toAdd.add('internal'); - } - - // ── Apply changes ── - // Ensure all labels we're about to add exist (addLabels returns - // 422 if any label in the batch is missing, which would prevent - // ALL labels from being applied). - for (const name of toAdd) { - await h.ensureLabel(name); - } - - for (const name of toRemove) { - if (toAdd.has(name)) continue; - try { - await github.rest.issues.removeLabel({ - owner, repo, issue_number: prNumber, name, - }); - } catch (e) { - if (e.status !== 404) throw e; - } - } - - const addList = [...toAdd]; - if (addList.length > 0) { - await github.rest.issues.addLabels({ - owner, repo, issue_number: prNumber, labels: addList, - }); - } - - const removed = [...toRemove].filter(r => !toAdd.has(r)); - console.log(`PR #${prNumber}: +[${addList.join(', ')}] -[${removed.join(', ')}]`); - - # Apply tier label BEFORE the external label so that - # "trusted-contributor" is already present when the "external" labeled - # event fires and triggers require_issue_link.yml. - - name: Apply contributor tier label - if: github.event.action == 'opened' && steps.check-membership.outputs.is-external == 'true' - uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 - with: - github-token: ${{ steps.app-token.outputs.token }} - script: | - const { owner, repo } = context.repo; - const { h } = require('./.github/scripts/pr-labeler.js').loadAndInit(github, owner, repo, core); - - const pr = context.payload.pull_request; - await h.applyTierLabel(pr.number, pr.user.login); - - - name: Add external label - if: github.event.action == 'opened' && steps.check-membership.outputs.is-external == 'true' - uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 - with: - # Use App token so the "labeled" event propagates to downstream - # workflows (e.g. require_issue_link.yml). Events created by the - # default GITHUB_TOKEN do not trigger additional workflow runs. - github-token: ${{ steps.app-token.outputs.token }} - script: | - const { owner, repo } = context.repo; - const prNumber = context.payload.pull_request.number; - - const { h } = require('./.github/scripts/pr-labeler.js').loadAndInit(github, owner, repo, core); - - await h.ensureLabel('external'); - await github.rest.issues.addLabels({ - owner, repo, - issue_number: prNumber, - labels: ['external'], - }); - console.log(`Added 'external' label to PR #${prNumber}`); diff --git a/.github/workflows/pr_labeler_backfill.yml b/.github/workflows/pr_labeler_backfill.yml deleted file mode 100644 index 31f5343f53..0000000000 --- a/.github/workflows/pr_labeler_backfill.yml +++ /dev/null @@ -1,131 +0,0 @@ -# Backfill PR labels on all open PRs. -# -# Manual-only workflow that applies the same labels as pr_labeler.yml -# (size, file, title, contributor classification) to existing open PRs. -# Reuses shared logic from .github/scripts/pr-labeler.js. - -name: "🏷️ PR Labeler Backfill" - -on: - workflow_dispatch: - inputs: - max_items: - description: "Maximum number of open PRs to process" - default: "100" - type: string - -permissions: - contents: read - -jobs: - backfill: - if: github.repository_owner == 'langchain-ai' - runs-on: ubuntu-latest - permissions: - contents: read - pull-requests: write - issues: write - - steps: - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v6 - - - name: Generate GitHub App token - id: app-token - uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3 - with: - client-id: ${{ secrets.ORG_MEMBERSHIP_APP_CLIENT_ID }} - private-key: ${{ secrets.ORG_MEMBERSHIP_APP_PRIVATE_KEY }} - - - name: Backfill labels on open PRs - uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 - with: - github-token: ${{ steps.app-token.outputs.token }} - script: | - const { owner, repo } = context.repo; - const rawMax = '${{ inputs.max_items }}'; - const maxItems = parseInt(rawMax, 10); - if (isNaN(maxItems) || maxItems <= 0) { - core.setFailed(`Invalid max_items: "${rawMax}" — must be a positive integer`); - return; - } - - const { h } = require('./.github/scripts/pr-labeler.js').loadAndInit(github, owner, repo, core); - - for (const name of [...h.sizeLabels, ...h.tierLabels]) { - await h.ensureLabel(name); - } - - const contributorCache = new Map(); - const fileRules = h.buildFileRules(); - - const prs = await github.paginate(github.rest.pulls.list, { - owner, repo, state: 'open', per_page: 100, - }); - - let processed = 0; - let failures = 0; - for (const pr of prs) { - if (processed >= maxItems) break; - try { - const author = pr.user.login; - const info = await h.getContributorInfo(contributorCache, author, pr.user.type); - const labels = new Set(); - - labels.add(info.isExternal ? 'external' : 'internal'); - if (info.isExternal && info.mergedCount != null && info.mergedCount >= h.trustedThreshold) { - labels.add('trusted-contributor'); - } else if (info.isExternal && info.mergedCount === 0) { - labels.add('new-contributor'); - } - - // Size + file labels - const files = await github.paginate(github.rest.pulls.listFiles, { - owner, repo, pull_number: pr.number, per_page: 100, - }); - const { sizeLabel } = h.computeSize(files); - labels.add(sizeLabel); - - for (const label of h.matchFileLabels(files, fileRules)) { - labels.add(label); - } - - // Title labels - const { labels: titleLabels } = h.matchTitleLabels(pr.title ?? ''); - for (const tl of titleLabels) labels.add(tl); - - // Ensure all labels exist before batch add - for (const name of labels) { - await h.ensureLabel(name); - } - - // Remove stale managed labels - const currentLabels = (await github.paginate( - github.rest.issues.listLabelsOnIssue, - { owner, repo, issue_number: pr.number, per_page: 100 }, - )).map(l => l.name ?? ''); - - const managed = [...h.sizeLabels, ...h.tierLabels, ...h.allTypeLabels]; - for (const name of currentLabels) { - if (managed.includes(name) && !labels.has(name)) { - try { - await github.rest.issues.removeLabel({ - owner, repo, issue_number: pr.number, name, - }); - } catch (e) { - if (e.status !== 404) throw e; - } - } - } - - await github.rest.issues.addLabels({ - owner, repo, issue_number: pr.number, labels: [...labels], - }); - console.log(`PR #${pr.number} (${author}): ${[...labels].join(', ')}`); - processed++; - } catch (e) { - failures++; - core.warning(`Failed to process PR #${pr.number}: ${e.message}`); - } - } - - console.log(`\nBackfill complete. Processed ${processed} PRs, ${failures} failures. ${contributorCache.size} unique authors.`); diff --git a/.github/workflows/pr_lint_trailer.yml b/.github/workflows/pr_lint_trailer.yml deleted file mode 100644 index 17f6f09902..0000000000 --- a/.github/workflows/pr_lint_trailer.yml +++ /dev/null @@ -1,175 +0,0 @@ -# Pre-merge banned-trailer check. - -name: "🏷️ PR trailer lint" - -on: - pull_request: - types: [ opened, edited, synchronize, reopened ] - -permissions: - pull-requests: write - -jobs: - trailer-check: - if: github.repository_owner == 'langchain-ai' - name: "validate squash-merge has no banned trailers" - runs-on: ubuntu-latest - # Serialize per-PR. Rapid `edited`/`synchronize` events on a PR open can - # otherwise produce two concurrent runs that both observe "no existing - # sticky" and both call `createComment`, leaving a duplicate failure - # comment that the find-first updater will never reconcile. We queue - # (cancel-in-progress: false) rather than cancel, so the in-flight run - # finishes its sticky write before the next event evaluates. - concurrency: - group: pr-trailer-lint-${{ github.event.pull_request.number }} - cancel-in-progress: false - steps: - - name: Check PR title and body for banned trailer - uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 - # Bound the comment-write tail so a hung GitHub API call cannot leave - # the check stuck "in progress" past the runner default. `core.setFailed` - # is invoked before the sticky write, so the failure status is already - # recorded if this timeout fires. - timeout-minutes: 5 - with: - script: | - if (!context.payload.pull_request) { - core.setFailed('No pull_request payload — workflow must run on pull_request events.'); - return; - } - const { title, body, number } = context.payload.pull_request; - // Normalize line endings — GitHub returns whatever the editor used, - // and CRLF leaves stray \r chars in offending-line displays. - const fullBody = (body || '').replace(/\r\n/g, '\n'); - const STICKY_MARKER = ''; - - // Mirrors the org ruleset regex on the default branch. Keep in lock-step: - // the live source of truth is the ruleset's `commit_message_pattern.pattern` - // field at GitHub org settings → Rulesets → `block-anthropic-coauthor` - // (or whichever ruleset blocks this trailer on the default branch). - // The pattern below is informational; verify against the live ruleset - // when updating either side, or this check silently passes pushes - // that the ruleset will then reject (defeating the entire purpose). - // - // Case-folding is intentionally narrow (`[Aa]`/`[Bb]`) because the - // ruleset's pattern is narrow. Do NOT add the `i` flag — that would - // catch cases the ruleset does not, surfacing false positives the - // ruleset would let through. - const BANNED_REGEX = /Co-[Aa]uthored-[Bb]y:.*/; - - const squashMessage = `${title} (#${number})\n\n${fullBody}`; - - async function findStickyComment() { - const comments = await github.paginate(github.rest.issues.listComments, { - ...context.repo, - issue_number: number, - per_page: 100, - }); - return comments.find(c => c.body && c.body.startsWith(STICKY_MARKER)); - } - - // Comment write paths can fail for several reasons that should not - // turn this advisory job red on its own: fork PRs run with - // restricted tokens, secondary rate limits, transient API errors. - // Fall back to `core.summary` so a maintainer can paste the - // remediation manually. The check still fails — `setFailed` is - // invoked before this function, so the failure signal is already - // recorded by the time the comment write is attempted. - // - // The try/catch wraps ONLY the write call so that a bug in - // `findStickyComment` (e.g., pagination throwing) surfaces with - // its true cause instead of being misattributed to "fork PR token". - async function postStickyOrSummary(commentBody, summaryHeading) { - const existing = await findStickyComment(); - try { - if (existing) { - if (existing.body !== commentBody) { - await github.rest.issues.updateComment({ - ...context.repo, - comment_id: existing.id, - body: commentBody, - }); - } - } else { - await github.rest.issues.createComment({ - ...context.repo, - issue_number: number, - body: commentBody, - }); - } - } catch (commentErr) { - core.warning(`Could not post sticky comment (fork PR token, rate limit, or transient API error): ${commentErr.message}`); - await core.summary - .addHeading(summaryHeading) - .addRaw('Paste the following into the PR as a comment:') - .addCodeBlock(commentBody, 'markdown') - .write(); - } - } - - const lines = squashMessage.split('\n'); - const offendingIndices = []; - for (let i = 0; i < lines.length; i++) { - if (BANNED_REGEX.test(lines[i])) { - offendingIndices.push(i); - } - } - - if (offendingIndices.length === 0) { - core.info('No banned trailer in squash-merge message.'); - // Mark any prior failure comment as resolved. We update rather - // than delete because `deleteComment` 403s under restricted - // fork-PR tokens, whereas `updateComment` on a bot-authored - // comment works in both modes. Wrapped in try/catch because a - // transient API failure during cleanup must NOT turn a green - // check into red. - try { - const existing = await findStickyComment(); - if (existing) { - const resolvedBody = [ - STICKY_MARKER, - '✅ **Trailer fixed.** The previous warning is resolved.', - ].join('\n'); - if (existing.body !== resolvedBody) { - await github.rest.issues.updateComment({ - ...context.repo, - comment_id: existing.id, - body: resolvedBody, - }); - } - } - } catch (cleanupErr) { - core.warning(`Check passed but could not update prior failure comment to resolved: ${cleanupErr.message}`); - } - return; - } - - const offendingExcerpt = offendingIndices - .map(i => `Line ${i + 1}: ${lines[i]}`) - .join('\n'); - - const commentBody = [ - STICKY_MARKER, - '⚠️ **Banned trailer in PR — would block the squash-merge push to the default branch.**', - '', - 'The would-be squash-merge commit message contains a `Co-authored-by: ... ` line. An organization ruleset on the default branch rejects any push whose commit message matches that pattern, so this PR cannot be merged until the trailer is removed.', - '', - '**Found:**', - '```', - offendingExcerpt, - '```', - '', - '### Fix', - '', - 'Edit the PR description and remove the offending line(s). The trailer is auto-inserted by some Claude-based authoring tools — strip it before opening or merging the PR. Save the description; this check will re-run automatically.', - ].join('\n'); - - // Set the failure signal BEFORE the sticky write — if the comment - // API hangs, the runner-level timeout fires with the failure - // status already recorded. Reversing the order leaves the check - // stuck "in progress" instead of red. - core.setFailed(`PR contains banned trailer matching ${BANNED_REGEX}`); - await postStickyOrSummary( - commentBody, - 'Banned trailer in PR; comment could not be posted', - ); diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 2c7ae3d8ee..7bc66b4c55 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -4,29 +4,74 @@ on: push: branches: - master + paths: + - "libs/partners/decodo/**" + - ".github/workflows/publish.yml" workflow_dispatch: +permissions: + contents: read + +concurrency: + group: release + cancel-in-progress: false + +env: + UV_FROZEN: "true" + jobs: publish: runs-on: ubuntu-latest environment: pypi permissions: + contents: write id-token: write - contents: read + defaults: + run: + working-directory: libs/partners/decodo steps: - - uses: actions/checkout@v4 + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v6 + with: + ref: ${{ github.ref_name }} + fetch-depth: 0 + + # PSR needs a checked-out branch, not a detached HEAD, to match + # `branches.master`. Resetting to the triggering SHA keeps a push that + # landed in the meantime out of this release. + - run: git reset --hard ${{ github.sha }} - - uses: actions/setup-python@v5 + - uses: "./.github/actions/uv_setup" with: python-version: "3.12" + cache-suffix: publish-libs/partners/decodo + working-directory: libs/partners/decodo - - name: Build - working-directory: libs/partners/decodo + - name: Install dependencies + run: uv sync --group lint --group typing --group test --group test_integration + + - name: Lint run: | - pip install build - python -m build + make lint_package + make lint_tests + + - name: Test + run: make test PYTEST_EXTRA=-q + + - name: Release + id: release + uses: python-semantic-release/python-semantic-release@b700dbeb1f431a0fcc30a79f3f0869407fe07278 # v10.7.0 + with: + directory: libs/partners/decodo + github_token: ${{ secrets.GITHUB_TOKEN }} + commit: "false" + changelog: "false" + + - name: Build + if: steps.release.outputs.released == 'true' + run: uv build - name: Publish - uses: pypa/gh-action-pypi-publish@release/v1 + if: steps.release.outputs.released == 'true' + uses: pypa/gh-action-pypi-publish@dc37677b2e1c63e2034f94d8a5b11f265b73ba33 # release/v1 with: packages-dir: libs/partners/decodo/dist/ diff --git a/.github/workflows/refresh_model_profiles.yml b/.github/workflows/refresh_model_profiles.yml deleted file mode 100644 index ae0f5d70d6..0000000000 --- a/.github/workflows/refresh_model_profiles.yml +++ /dev/null @@ -1,159 +0,0 @@ -# Refreshes model profile data for in-monorepo partner integrations by -# pulling the latest metadata from models.dev via the `langchain-profiles` CLI. -# -# Creates a pull request with any changes. Runs daily (all providers) and can -# be triggered manually from the Actions UI with an optional provider filter. -# Uses a fixed branch so each run supersedes any stale PR from a previous run. - -name: "🔄 Refresh Model Profiles" - -on: - schedule: - - cron: "0 8 * * *" # daily at 08:00 UTC - workflow_dispatch: - inputs: - provider: - type: choice - description: "Provider package to refresh (select from dropdown)" - default: all - # models.dev provider IDs — must match the `provider` keys in - # ALL_PROVIDERS below. When adding a package, update both lists. - options: - - all - - anthropic - - deepseek - - fireworks-ai - - groq - - huggingface - - mistral - - openai - - openrouter - - perplexity - - xai - providers-override: - type: string - required: false - description: >- - Optional comma-separated provider IDs override (e.g. openai,anthropic). - Takes precedence over the dropdown. Accepts models.dev IDs; package - aliases fireworks and mistralai are also accepted. - -permissions: - contents: write - pull-requests: write - -jobs: - resolve-providers: - name: resolve providers - if: github.repository_owner == 'langchain-ai' - runs-on: ubuntu-latest - outputs: - providers: ${{ steps.resolve.outputs.providers }} - pr-title: ${{ steps.resolve.outputs.pr-title }} - pr-body: ${{ steps.resolve.outputs.pr-body }} - steps: - - name: "🎯 Resolve provider filter" - id: resolve - env: - # Scheduled runs have no inputs — default to all providers. - PROVIDER: ${{ github.event_name == 'workflow_dispatch' && inputs.provider || 'all' }} - # Bracket access required: bare `inputs.providers-override` is parsed as subtraction. - PROVIDERS_OVERRIDE: ${{ github.event_name == 'workflow_dispatch' && inputs['providers-override'] || '' }} - run: | - set -euo pipefail - - ALL_PROVIDERS='[ - {"provider":"anthropic", "data_dir":"libs/partners/anthropic/langchain_anthropic/data"}, - {"provider":"deepseek", "data_dir":"libs/partners/deepseek/langchain_deepseek/data"}, - {"provider":"fireworks-ai", "data_dir":"libs/partners/fireworks/langchain_fireworks/data"}, - {"provider":"groq", "data_dir":"libs/partners/groq/langchain_groq/data"}, - {"provider":"huggingface", "data_dir":"libs/partners/huggingface/langchain_huggingface/data"}, - {"provider":"mistral", "data_dir":"libs/partners/mistralai/langchain_mistralai/data"}, - {"provider":"openai", "data_dir":"libs/partners/openai/langchain_openai/data"}, - {"provider":"openrouter", "data_dir":"libs/partners/openrouter/langchain_openrouter/data"}, - {"provider":"perplexity", "data_dir":"libs/partners/perplexity/langchain_perplexity/data"}, - {"provider":"xai", "data_dir":"libs/partners/xai/langchain_xai/data"} - ]' - - normalize_provider() { - case "$1" in - fireworks) echo "fireworks-ai" ;; - mistralai) echo "mistral" ;; - *) echo "$1" ;; - esac - } - - selected=() - # Prefer free-text override when non-empty; otherwise use dropdown. - if [ -n "${PROVIDERS_OVERRIDE//[[:space:]]/}" ]; then - while IFS= read -r raw; do - [ -z "${raw}" ] && continue - selected+=("$(normalize_provider "${raw}")") - done < <( - echo "${PROVIDERS_OVERRIDE}" \ - | tr ',' '\n' \ - | sed 's/^[[:space:]]*//;s/[[:space:]]*$//' \ - | grep -v '^$' || true - ) - elif [ "${PROVIDER}" != "all" ]; then - selected+=("$(normalize_provider "${PROVIDER}")") - fi - - if [ ${#selected[@]} -eq 0 ]; then - filtered="$(echo "${ALL_PROVIDERS}" | jq -c .)" - label="all in-monorepo partner integrations" - title="chore(model-profiles): refresh model profile data" - else - ids_json="$(printf '%s\n' "${selected[@]}" | jq -R . | jq -s -c .)" - unknown="$(echo "${ALL_PROVIDERS}" | jq -r --argjson ids "${ids_json}" ' - ($ids - map(.provider)) | join(", ") - ')" - if [ -n "${unknown}" ]; then - known="$(echo "${ALL_PROVIDERS}" | jq -r 'map(.provider) | join(", ")')" - echo "::error::Unknown provider ID(s): ${unknown}. Known: ${known}" - exit 1 - fi - - filtered="$(echo "${ALL_PROVIDERS}" | jq -c --argjson ids "${ids_json}" ' - map(select(.provider as $p | ($ids | index($p)) != null)) - ')" - names="$(echo "${filtered}" | jq -r 'map(.provider) | join(", ")')" - label="${names}" - if [ "$(echo "${filtered}" | jq 'length')" -eq 1 ]; then - title="chore(model-profiles): refresh ${names} model profile data" - else - title="chore(model-profiles): refresh model profile data (${names})" - fi - fi - - count="$(echo "${filtered}" | jq 'length')" - if [ "${count}" -eq 0 ]; then - echo "::error::No providers matched the filter" - exit 1 - fi - - { - echo "providers=${filtered}" - echo "pr-title=${title}" - echo "pr-body<> "${GITHUB_OUTPUT}" - - echo "### Providers to refresh" >> "${GITHUB_STEP_SUMMARY}" - echo "${filtered}" | jq -r '.[].provider' | sed 's/^/- /' >> "${GITHUB_STEP_SUMMARY}" - - refresh-profiles: - needs: resolve-providers - uses: ./.github/workflows/_refresh_model_profiles.yml - with: - providers: ${{ needs.resolve-providers.outputs.providers }} - cli-path: libs/model-profiles - add-paths: libs/partners/**/data/_profiles.py - pr-title: ${{ needs.resolve-providers.outputs.pr-title }} - pr-body: ${{ needs.resolve-providers.outputs.pr-body }} - secrets: - MODEL_PROFILE_BOT_CLIENT_ID: ${{ secrets.MODEL_PROFILE_BOT_CLIENT_ID }} - MODEL_PROFILE_BOT_PRIVATE_KEY: ${{ secrets.MODEL_PROFILE_BOT_PRIVATE_KEY }} diff --git a/.github/workflows/remove_waiting_on_author.yml b/.github/workflows/remove_waiting_on_author.yml deleted file mode 100644 index 2f19ad224b..0000000000 --- a/.github/workflows/remove_waiting_on_author.yml +++ /dev/null @@ -1,61 +0,0 @@ -# Remove the `waiting-on-author` label from an issue or PR when the original -# author replies. Fires on every issue/PR comment; the job's `if:` filter skips -# runs unless the item is open, carries the label, and the commenter is the -# original author (and not a bot). -# -# Uses the default GITHUB_TOKEN so the label-removal event does NOT re-trigger -# other workflows: GitHub does not trigger new workflow runs from actions -# performed by the default GITHUB_TOKEN (with narrow exceptions like -# workflow_dispatch), which prevents infinite loops. - -name: Remove waiting-on-author on Author Reply - -on: - issue_comment: - types: [created] - -permissions: - contents: read - -jobs: - remove-label: - if: >- - github.repository_owner == 'langchain-ai' && - github.event.issue.state == 'open' && - contains(github.event.issue.labels.*.name, 'waiting-on-author') && - github.event.comment.user.type != 'Bot' && - github.event.comment.user.login == github.event.issue.user.login - runs-on: ubuntu-latest - permissions: - issues: write - - steps: - - name: Remove waiting-on-author label - uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 - with: - script: | - const { owner, repo } = context.repo; - const issue_number = context.payload.issue.number; - const author = context.payload.issue.user.login; - - console.log( - `Author ${author} commented on #${issue_number} — removing waiting-on-author`, - ); - - try { - await github.rest.issues.removeLabel({ - owner, - repo, - issue_number, - name: 'waiting-on-author', - }); - } catch (e) { - // 404: typically label not present (already removed or never - // applied). Could also indicate issue/repo not found — include - // e.message to disambiguate. - if (e.status === 404) { - console.log(`Label already absent (404) — nothing to do: ${e.message}`); - return; - } - throw e; - } diff --git a/.github/workflows/reopen_on_assignment.yml b/.github/workflows/reopen_on_assignment.yml deleted file mode 100644 index 6799f6d365..0000000000 --- a/.github/workflows/reopen_on_assignment.yml +++ /dev/null @@ -1,196 +0,0 @@ -# Reopen PRs that were auto-closed by require_issue_link.yml when the -# contributor was not assigned to the linked issue. When a maintainer -# assigns the contributor to the issue, this workflow finds matching -# closed PRs, verifies the issue link, and reopens them. -# -# Uses the default GITHUB_TOKEN (not a PAT or app token) so that the -# reopen and label-removal events do NOT re-trigger other workflows. -# GitHub suppresses events created by the default GITHUB_TOKEN within -# workflow runs to prevent infinite loops. - -name: Reopen PR on Issue Assignment - -on: - issues: - types: [assigned] - -permissions: - contents: read - -jobs: - reopen-linked-prs: - if: github.repository_owner == 'langchain-ai' - runs-on: ubuntu-latest - permissions: - actions: write - pull-requests: write - - steps: - - name: Find and reopen matching PRs - uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 - with: - script: | - const { owner, repo } = context.repo; - const issueNumber = context.payload.issue.number; - const assignee = context.payload.assignee.login; - - console.log( - `Issue #${issueNumber} assigned to ${assignee} — searching for closed PRs to reopen`, - ); - - const q = [ - `is:pr`, - `is:closed`, - `author:${assignee}`, - `label:missing-issue-link`, - `repo:${owner}/${repo}`, - ].join(' '); - - let data; - try { - ({ data } = await github.rest.search.issuesAndPullRequests({ - q, - per_page: 30, - })); - } catch (e) { - throw new Error( - `Failed to search for closed PRs to reopen after assigning ${assignee} ` + - `to #${issueNumber} (HTTP ${e.status ?? 'unknown'}): ${e.message}`, - ); - } - - if (data.total_count === 0) { - console.log('No matching closed PRs found'); - return; - } - - console.log(`Found ${data.total_count} candidate PR(s)`); - - // Must stay in sync with the identical pattern in require_issue_link.yml - const pattern = /(?:close[sd]?|fix(?:e[sd])?|resolve[sd]?)\s*#(\d+)/gi; - - for (const item of data.items) { - const prNumber = item.number; - const body = item.body || ''; - const matches = [...body.matchAll(pattern)]; - const referencedIssues = matches.map(m => parseInt(m[1], 10)); - - if (!referencedIssues.includes(issueNumber)) { - console.log(`PR #${prNumber} does not reference #${issueNumber} — skipping`); - continue; - } - - // Skip if already bypassed - const labels = item.labels.map(l => l.name); - if (labels.includes('bypass-issue-check')) { - console.log(`PR #${prNumber} already has bypass-issue-check — skipping`); - continue; - } - - // Reopen first, remove label second — a closed PR that still has - // missing-issue-link is recoverable; a closed PR with the label - // stripped is invisible to both workflows. - try { - await github.rest.pulls.update({ - owner, - repo, - pull_number: prNumber, - state: 'open', - }); - console.log(`Reopened PR #${prNumber}`); - } catch (e) { - if (e.status === 422) { - // Head branch deleted — PR is unrecoverable. Notify the - // contributor so they know to open a new PR. - core.warning(`Cannot reopen PR #${prNumber}: head branch was likely deleted`); - try { - await github.rest.issues.createComment({ - owner, - repo, - issue_number: prNumber, - body: - `You have been assigned to #${issueNumber}, but this PR could not be ` + - `reopened because the head branch has been deleted. Please open a new ` + - `PR referencing the issue.`, - }); - } catch (commentErr) { - core.warning( - `Also failed to post comment on PR #${prNumber}: ${commentErr.message}`, - ); - } - continue; - } - // Transient errors (rate limit, 5xx) should fail the job so - // the label is NOT removed and the run can be retried. - throw e; - } - - // Remove missing-issue-link label only after successful reopen - try { - await github.rest.issues.removeLabel({ - owner, - repo, - issue_number: prNumber, - name: 'missing-issue-link', - }); - console.log(`Removed missing-issue-link from PR #${prNumber}`); - } catch (e) { - if (e.status !== 404) throw e; - } - - // Minimize stale enforcement comment (best-effort; - // sync w/ require_issue_link.yml minimize blocks) - try { - const marker = ''; - const comments = await github.paginate( - github.rest.issues.listComments, - { owner, repo, issue_number: prNumber, per_page: 100 }, - ); - const stale = comments.find(c => c.body && c.body.includes(marker)); - if (stale) { - await github.graphql(` - mutation($id: ID!) { - minimizeComment(input: {subjectId: $id, classifier: OUTDATED}) { - minimizedComment { isMinimized } - } - } - `, { id: stale.node_id }); - console.log(`Minimized stale enforcement comment ${stale.id} as outdated`); - } - } catch (e) { - core.warning(`Could not minimize stale comment on PR #${prNumber}: ${e.message}`); - } - - // Re-run the failed require_issue_link check so it picks up the - // new assignment. The re-run uses the original event payload but - // fetches live issue data, so the assignment check will pass. - // - // Limitation: we look up runs by the PR's current head SHA. If the - // contributor pushed new commits while the PR was closed, head.sha - // won't match the SHA of the original failed run and the query will - // return 0 results. This is acceptable because any push after reopen - // triggers a fresh require_issue_link run against the new SHA. - try { - const { data: pr } = await github.rest.pulls.get({ - owner, repo, pull_number: prNumber, - }); - const { data: runs } = await github.rest.actions.listWorkflowRuns({ - owner, repo, - workflow_id: 'require_issue_link.yml', - head_sha: pr.head.sha, - status: 'failure', - per_page: 1, - }); - if (runs.workflow_runs.length > 0) { - await github.rest.actions.reRunWorkflowFailedJobs({ - owner, repo, - run_id: runs.workflow_runs[0].id, - }); - console.log(`Re-ran failed require_issue_link run ${runs.workflow_runs[0].id} for PR #${prNumber}`); - } else { - console.log(`No failed require_issue_link runs found for PR #${prNumber} — skipping re-run`); - } - } catch (e) { - core.warning(`Could not re-run require_issue_link check for PR #${prNumber} (HTTP ${e.status ?? 'unknown'}): ${e.message}`); - } - } diff --git a/.github/workflows/require_issue_link.yml b/.github/workflows/require_issue_link.yml deleted file mode 100644 index 6ccecf2846..0000000000 --- a/.github/workflows/require_issue_link.yml +++ /dev/null @@ -1,468 +0,0 @@ -# Require external PRs to reference an approved issue (e.g. Fixes #NNN) and -# the PR author to be assigned to that issue. On failure the PR is -# labeled "missing-issue-link", commented on, and closed. -# -# Maintainer override: an org member can reopen the PR or remove -# "missing-issue-link" — both add "bypass-issue-check" and reopen. -# -# Dependency: pr_labeler.yml must apply the "external" label first. This -# workflow does NOT trigger on "opened" (new PRs have no labels yet, so the -# gate would always skip). - -name: Require Issue Link - -on: - pull_request_target: - # NEVER CHECK OUT UNTRUSTED CODE FROM A PR's HEAD IN A pull_request_target JOB. - # Doing so would allow attackers to execute arbitrary code in the context of your repository. - types: [edited, reopened, labeled, unlabeled] - -# ────────────────────────────────────────────────────────────────────────────── -# Enforcement gate: set to 'true' to activate the issue link requirement. -# When 'false', the workflow still runs the check logic (useful for dry-run -# visibility) but will NOT label, comment, close, or fail PRs. -# ────────────────────────────────────────────────────────────────────────────── -env: - ENFORCE_ISSUE_LINK: "true" - -permissions: - contents: read - -jobs: - check-issue-link: - # Run when the "external" label is added, on edit/reopen if already labeled, - # or when "missing-issue-link" is removed (triggers maintainer override check). - # Skip entirely when the PR already carries "trusted-contributor" or - # "bypass-issue-check". - if: >- - github.repository_owner == 'langchain-ai' && - !contains(github.event.pull_request.labels.*.name, 'trusted-contributor') && - !contains(github.event.pull_request.labels.*.name, 'bypass-issue-check') && - ( - (github.event.action == 'labeled' && github.event.label.name == 'external') || - (github.event.action == 'unlabeled' && github.event.label.name == 'missing-issue-link' && contains(github.event.pull_request.labels.*.name, 'external')) || - (github.event.action != 'labeled' && github.event.action != 'unlabeled' && contains(github.event.pull_request.labels.*.name, 'external')) - ) - runs-on: ubuntu-latest - permissions: - actions: write - pull-requests: write - - steps: - - name: Check for issue link and assignee - id: check-link - uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 - with: - script: | - const { owner, repo } = context.repo; - const prNumber = context.payload.pull_request.number; - const action = context.payload.action; - - // ── Helper: ensure a label exists, then add it to the PR ──────── - async function ensureAndAddLabel(labelName, color) { - try { - await github.rest.issues.getLabel({ owner, repo, name: labelName }); - } catch (e) { - if (e.status !== 404) throw e; - try { - await github.rest.issues.createLabel({ owner, repo, name: labelName, color }); - } catch (createErr) { - // 422 = label was created by a concurrent run between our - // GET and POST — safe to ignore. - if (createErr.status !== 422) throw createErr; - } - } - await github.rest.issues.addLabels({ - owner, repo, issue_number: prNumber, labels: [labelName], - }); - } - - // ── Helper: check if the user who triggered this event (reopened - // the PR / removed the label) has write+ access on the repo ─── - // Uses the repo collaborator permission endpoint instead of the - // org membership endpoint. The org endpoint requires the caller - // to be an org member, which GITHUB_TOKEN (an app installation - // token) never is — so it always returns 403. - async function senderIsOrgMember() { - const sender = context.payload.sender?.login; - if (!sender) { - throw new Error('Event has no sender — cannot check permissions'); - } - try { - const { data } = await github.rest.repos.getCollaboratorPermissionLevel({ - owner, repo, username: sender, - }); - const perm = data.permission; - if (['admin', 'maintain', 'write'].includes(perm)) { - console.log(`${sender} has ${perm} permission — treating as maintainer`); - return { isMember: true, login: sender }; - } - console.log(`${sender} has ${perm} permission — not a maintainer`); - return { isMember: false, login: sender }; - } catch (e) { - if (e.status === 404) { - console.log(`Cannot check permissions for ${sender} — treating as non-maintainer`); - return { isMember: false, login: sender }; - } - const status = e.status ?? 'unknown'; - throw new Error( - `Permission check failed for ${sender} (HTTP ${status}): ${e.message}`, - ); - } - } - - // ── Helper: apply maintainer bypass (shared by both override paths) ── - async function applyMaintainerBypass(reason) { - console.log(reason); - - // Remove missing-issue-link if present - try { - await github.rest.issues.removeLabel({ - owner, repo, issue_number: prNumber, name: 'missing-issue-link', - }); - } catch (e) { - if (e.status !== 404) throw e; - } - - // Reopen before adding bypass label — a failed reopen is more - // actionable than a closed PR with a bypass label stuck on it. - if (context.payload.pull_request.state === 'closed') { - try { - await github.rest.pulls.update({ - owner, repo, pull_number: prNumber, state: 'open', - }); - console.log(`Reopened PR #${prNumber}`); - } catch (e) { - // 422 if head branch deleted; 403 if permissions insufficient. - // Bypass labels still apply — maintainer can reopen manually. - core.warning( - `Could not reopen PR #${prNumber} (HTTP ${e.status ?? 'unknown'}): ${e.message}. ` + - `Bypass labels were applied — a maintainer may need to reopen manually.`, - ); - } - } - - // Add bypass-issue-check so future triggers skip enforcement - await ensureAndAddLabel('bypass-issue-check', '0e8a16'); - - // Minimize stale enforcement comment (best-effort; must not - // abort bypass — sync w/ reopen_on_assignment.yml & step below) - try { - const marker = ''; - const comments = await github.paginate( - github.rest.issues.listComments, - { owner, repo, issue_number: prNumber, per_page: 100 }, - ); - const stale = comments.find(c => c.body && c.body.includes(marker)); - if (stale) { - await github.graphql(` - mutation($id: ID!) { - minimizeComment(input: {subjectId: $id, classifier: OUTDATED}) { - minimizedComment { isMinimized } - } - } - `, { id: stale.node_id }); - console.log(`Minimized stale enforcement comment ${stale.id} as outdated`); - } - } catch (e) { - core.warning(`Could not minimize stale comment on PR #${prNumber}: ${e.message}`); - } - - core.setOutput('has-link', 'true'); - core.setOutput('is-assigned', 'true'); - } - - // ── Maintainer override: removed "missing-issue-link" label ───── - if (action === 'unlabeled') { - const { isMember, login } = await senderIsOrgMember(); - if (isMember) { - await applyMaintainerBypass( - `Maintainer ${login} removed missing-issue-link from PR #${prNumber} — bypassing enforcement`, - ); - return; - } - // Non-member removed the label — re-add it defensively and - // set failure outputs so downstream steps (comment, close) fire. - // NOTE: addLabels fires a "labeled" event, but the job-level gate - // only matches labeled events for "external", so no re-trigger. - console.log(`Non-member ${login} removed missing-issue-link — re-adding`); - try { - await ensureAndAddLabel('missing-issue-link', 'b76e79'); - } catch (e) { - core.warning( - `Failed to re-add missing-issue-link (HTTP ${e.status ?? 'unknown'}): ${e.message}. ` + - `Downstream step will retry.`, - ); - } - core.setOutput('has-link', 'false'); - core.setOutput('is-assigned', 'false'); - return; - } - - // ── Maintainer override: reopened PR with "missing-issue-link" ── - const prLabels = context.payload.pull_request.labels.map(l => l.name); - if (action === 'reopened' && prLabels.includes('missing-issue-link')) { - const { isMember, login } = await senderIsOrgMember(); - if (isMember) { - await applyMaintainerBypass( - `Maintainer ${login} reopened PR #${prNumber} — bypassing enforcement`, - ); - return; - } - console.log(`Non-member ${login} reopened PR — proceeding with check`); - } - - // ── Fetch live labels (race guard) ────────────────────────────── - const { data: liveLabels } = await github.rest.issues.listLabelsOnIssue({ - owner, repo, issue_number: prNumber, - }); - const liveNames = liveLabels.map(l => l.name); - if (liveNames.includes('trusted-contributor') || liveNames.includes('bypass-issue-check')) { - console.log('PR has trusted-contributor or bypass-issue-check label — bypassing'); - core.setOutput('has-link', 'true'); - core.setOutput('is-assigned', 'true'); - return; - } - - const body = context.payload.pull_request.body || ''; - const pattern = /(?:close[sd]?|fix(?:e[sd])?|resolve[sd]?)\s*#(\d+)/gi; - const matches = [...body.matchAll(pattern)]; - - if (matches.length === 0) { - console.log('No issue link found in PR body'); - core.setOutput('has-link', 'false'); - core.setOutput('is-assigned', 'false'); - return; - } - - const issues = matches.map(m => `#${m[1]}`).join(', '); - console.log(`Found issue link(s): ${issues}`); - core.setOutput('has-link', 'true'); - - // Check whether the PR author is assigned to at least one linked issue - const prAuthor = context.payload.pull_request.user.login; - const MAX_ISSUES = 5; - const allIssueNumbers = [...new Set(matches.map(m => parseInt(m[1], 10)))]; - const issueNumbers = allIssueNumbers.slice(0, MAX_ISSUES); - if (allIssueNumbers.length > MAX_ISSUES) { - core.warning( - `PR references ${allIssueNumbers.length} issues — only checking the first ${MAX_ISSUES}`, - ); - } - - let assignedToAny = false; - for (const num of issueNumbers) { - try { - const { data: issue } = await github.rest.issues.get({ - owner, repo, issue_number: num, - }); - const assignees = issue.assignees.map(a => a.login.toLowerCase()); - if (assignees.includes(prAuthor.toLowerCase())) { - console.log(`PR author "${prAuthor}" is assigned to #${num}`); - assignedToAny = true; - break; - } else { - console.log(`PR author "${prAuthor}" is NOT assigned to #${num} (assignees: ${assignees.join(', ') || 'none'})`); - } - } catch (error) { - if (error.status === 404) { - console.log(`Issue #${num} not found — skipping`); - } else { - // Non-404 errors (rate limit, server error) must not be - // silently skipped — they could cause false enforcement - // (closing a legitimate PR whose assignment can't be verified). - throw new Error( - `Cannot verify assignee for issue #${num} (${error.status}): ${error.message}`, - ); - } - } - } - - core.setOutput('is-assigned', assignedToAny ? 'true' : 'false'); - - - name: Add missing-issue-link label - if: >- - env.ENFORCE_ISSUE_LINK == 'true' && - (steps.check-link.outputs.has-link != 'true' || steps.check-link.outputs.is-assigned != 'true') - uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 - with: - script: | - const { owner, repo } = context.repo; - const prNumber = context.payload.pull_request.number; - const labelName = 'missing-issue-link'; - - // Ensure the label exists (no checkout/shared helper available) - try { - await github.rest.issues.getLabel({ owner, repo, name: labelName }); - } catch (e) { - if (e.status !== 404) throw e; - try { - await github.rest.issues.createLabel({ - owner, repo, name: labelName, color: 'b76e79', - }); - } catch (createErr) { - if (createErr.status !== 422) throw createErr; - } - } - - await github.rest.issues.addLabels({ - owner, repo, issue_number: prNumber, labels: [labelName], - }); - - - name: Remove missing-issue-link label and reopen PR - if: >- - env.ENFORCE_ISSUE_LINK == 'true' && - steps.check-link.outputs.has-link == 'true' && steps.check-link.outputs.is-assigned == 'true' - uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 - with: - script: | - const { owner, repo } = context.repo; - const prNumber = context.payload.pull_request.number; - try { - await github.rest.issues.removeLabel({ - owner, repo, issue_number: prNumber, name: 'missing-issue-link', - }); - } catch (error) { - if (error.status !== 404) throw error; - } - - // Reopen if this workflow previously closed the PR. We check the - // event payload labels (not live labels) because we already removed - // missing-issue-link above; the payload still reflects pre-step state. - const labels = context.payload.pull_request.labels.map(l => l.name); - if (context.payload.pull_request.state === 'closed' && labels.includes('missing-issue-link')) { - await github.rest.pulls.update({ - owner, - repo, - pull_number: prNumber, - state: 'open', - }); - console.log(`Reopened PR #${prNumber}`); - } - - // Minimize stale enforcement comment (best-effort; - // sync w/ applyMaintainerBypass above & reopen_on_assignment.yml) - try { - const marker = ''; - const comments = await github.paginate( - github.rest.issues.listComments, - { owner, repo, issue_number: prNumber, per_page: 100 }, - ); - const stale = comments.find(c => c.body && c.body.includes(marker)); - if (stale) { - await github.graphql(` - mutation($id: ID!) { - minimizeComment(input: {subjectId: $id, classifier: OUTDATED}) { - minimizedComment { isMinimized } - } - } - `, { id: stale.node_id }); - console.log(`Minimized stale enforcement comment ${stale.id} as outdated`); - } - } catch (e) { - core.warning(`Could not minimize stale comment on PR #${prNumber}: ${e.message}`); - } - - - name: Post comment, close PR, and fail - if: >- - env.ENFORCE_ISSUE_LINK == 'true' && - (steps.check-link.outputs.has-link != 'true' || steps.check-link.outputs.is-assigned != 'true') - uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 - with: - script: | - const { owner, repo } = context.repo; - const prNumber = context.payload.pull_request.number; - const hasLink = '${{ steps.check-link.outputs.has-link }}' === 'true'; - const isAssigned = '${{ steps.check-link.outputs.is-assigned }}' === 'true'; - const marker = ''; - - let lines; - if (!hasLink) { - lines = [ - marker, - '**This PR has been automatically closed** because it does not link to an approved issue.', - '', - 'All external contributions must reference an approved issue or discussion. Opening a PR before maintainer approval and assignment is discouraged. Please:', - '1. Find or [open an issue](https://github.com/' + owner + '/' + repo + '/issues/new/choose) describing the change', - '2. Wait for a maintainer to approve the approach and assign you', - '3. After assignment, open a PR. If this PR was opened early, add `Fixes #`, `Closes #`, or `Resolves #` to the description and it can be reopened automatically', - '', - '*Maintainers: reopen this PR or remove the `missing-issue-link` label to bypass this check.*', - ]; - } else { - lines = [ - marker, - '**This PR has been automatically closed** because you are not assigned to the linked issue.', - '', - 'Opening a PR before assignment is discouraged and is **not** an indication that it will be accepted. This process exists so maintainers can confirm a change is aligned with the project direction *before* contributors invest time implementing it. Please:', - '1. Comment on the linked issue explaining the approach you would like to take and why — include enough detail for a maintainer to evaluate the design. Do **not** post a drive-by "please assign me" comment with no substance; those will be ignored.', - '2. Wait for a maintainer to approve the approach and assign you. Once assigned, this PR can be reopened automatically.', - '', - '*Maintainers: reopen this PR or remove the `missing-issue-link` label to bypass this check.*', - ]; - } - - const body = lines.join('\n'); - - // Deduplicate: check for existing comment with the marker - const comments = await github.paginate( - github.rest.issues.listComments, - { owner, repo, issue_number: prNumber, per_page: 100 }, - ); - const existing = comments.find(c => c.body && c.body.includes(marker)); - - if (!existing) { - await github.rest.issues.createComment({ - owner, - repo, - issue_number: prNumber, - body, - }); - console.log('Posted requirement comment'); - } else if (existing.body !== body) { - await github.rest.issues.updateComment({ - owner, - repo, - comment_id: existing.id, - body, - }); - console.log('Updated existing comment with new message'); - } else { - console.log('Comment already exists — skipping'); - } - - // Close the PR - if (context.payload.pull_request.state === 'open') { - await github.rest.pulls.update({ - owner, - repo, - pull_number: prNumber, - state: 'closed', - }); - console.log(`Closed PR #${prNumber}`); - } - - // Cancel all other in-progress and queued workflow runs for this PR - const headSha = context.payload.pull_request.head.sha; - for (const status of ['in_progress', 'queued']) { - const runs = await github.paginate( - github.rest.actions.listWorkflowRunsForRepo, - { owner, repo, head_sha: headSha, status, per_page: 100 }, - ); - for (const run of runs) { - if (run.id === context.runId) continue; - try { - await github.rest.actions.cancelWorkflowRun({ - owner, repo, run_id: run.id, - }); - console.log(`Cancelled ${status} run ${run.id} (${run.name})`); - } catch (err) { - console.log(`Could not cancel run ${run.id}: ${err.message}`); - } - } - } - - const reason = !hasLink - ? 'PR must reference an issue using auto-close keywords (e.g., "Fixes #123").' - : 'PR author must be assigned to the linked issue.'; - core.setFailed(reason); diff --git a/.github/workflows/tag-external-issues.yml b/.github/workflows/tag-external-issues.yml deleted file mode 100644 index ef5a83cc24..0000000000 --- a/.github/workflows/tag-external-issues.yml +++ /dev/null @@ -1,205 +0,0 @@ -# Automatically tag issues as "external" or "internal" based on whether -# the author is a member of the langchain-ai GitHub organization, and -# apply contributor tier labels to external contributors based on their -# merged PR history. -# -# NOTE: PR labeling (including external/internal, tier, size, file, and -# title labels) is handled by pr_labeler.yml. This workflow handles -# issues only. -# -# Config (trustedThreshold, labelColor) is read from -# .github/scripts/pr-labeler-config.json to stay in sync with -# pr_labeler.yml. -# -# Setup Requirements: -# 1. Create a GitHub App with permissions: -# - Repository: Issues (write) -# - Organization: Members (read) -# 2. Install the app on your organization and this repository -# 3. Add these repository secrets: -# - ORG_MEMBERSHIP_APP_CLIENT_ID: Your app's client ID -# - ORG_MEMBERSHIP_APP_PRIVATE_KEY: Your app's private key -# -# The GitHub App token is required to check private organization membership. -# Without it, the workflow will fail. - -name: Tag External Issues - -on: - issues: - types: [opened] - workflow_dispatch: - inputs: - max_items: - description: "Maximum number of open issues to process" - default: "100" - type: string - -permissions: - contents: read - -concurrency: - group: ${{ github.workflow }}-${{ github.event.issue.number || github.run_id }} - cancel-in-progress: true - -jobs: - tag-external: - if: github.repository_owner == 'langchain-ai' && github.event_name != 'workflow_dispatch' - runs-on: ubuntu-latest - permissions: - contents: read - issues: write - - steps: - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v6 - - - name: Generate GitHub App token - id: app-token - uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3 - with: - client-id: ${{ secrets.ORG_MEMBERSHIP_APP_CLIENT_ID }} - private-key: ${{ secrets.ORG_MEMBERSHIP_APP_PRIVATE_KEY }} - - - name: Check if contributor is external - if: steps.app-token.outcome == 'success' - id: check-membership - uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 - with: - github-token: ${{ steps.app-token.outputs.token }} - script: | - const { owner, repo } = context.repo; - const { h } = require('./.github/scripts/pr-labeler.js').loadAndInit(github, owner, repo, core); - - const author = context.payload.sender.login; - const { isExternal } = await h.checkMembership( - author, context.payload.sender.type, - ); - core.setOutput('is-external', isExternal ? 'true' : 'false'); - - - name: Apply contributor tier label - if: steps.check-membership.outputs.is-external == 'true' - uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 - with: - # GITHUB_TOKEN is fine here — no downstream workflow chains - # off tier labels on issues (unlike PRs where App token is - # needed for require_issue_link.yml). - github-token: ${{ secrets.GITHUB_TOKEN }} - script: | - const { owner, repo } = context.repo; - const { h } = require('./.github/scripts/pr-labeler.js').loadAndInit(github, owner, repo, core); - - const issue = context.payload.issue; - // new-contributor is only meaningful on PRs, not issues - await h.applyTierLabel(issue.number, issue.user.login, { skipNewContributor: true }); - - - name: Add external/internal label - if: steps.check-membership.outputs.is-external != '' - uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 - with: - github-token: ${{ secrets.GITHUB_TOKEN }} - script: | - const { owner, repo } = context.repo; - const issue_number = context.payload.issue.number; - - const { h } = require('./.github/scripts/pr-labeler.js').loadAndInit(github, owner, repo, core); - - const label = '${{ steps.check-membership.outputs.is-external }}' === 'true' - ? 'external' : 'internal'; - await h.ensureLabel(label); - await github.rest.issues.addLabels({ - owner, repo, issue_number, labels: [label], - }); - console.log(`Added '${label}' label to issue #${issue_number}`); - - backfill: - if: github.repository_owner == 'langchain-ai' && github.event_name == 'workflow_dispatch' - runs-on: ubuntu-latest - permissions: - contents: read - issues: write - - steps: - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v6 - - - name: Generate GitHub App token - id: app-token - uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3 - with: - client-id: ${{ secrets.ORG_MEMBERSHIP_APP_CLIENT_ID }} - private-key: ${{ secrets.ORG_MEMBERSHIP_APP_PRIVATE_KEY }} - - - name: Backfill labels on open issues - uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0 - with: - github-token: ${{ steps.app-token.outputs.token }} - script: | - const { owner, repo } = context.repo; - const rawMax = '${{ inputs.max_items }}'; - const maxItems = parseInt(rawMax, 10); - if (isNaN(maxItems) || maxItems <= 0) { - core.setFailed(`Invalid max_items: "${rawMax}" — must be a positive integer`); - return; - } - - const { h } = require('./.github/scripts/pr-labeler.js').loadAndInit(github, owner, repo, core); - - const tierLabels = ['trusted-contributor']; - for (const name of tierLabels) { - await h.ensureLabel(name); - } - - const contributorCache = new Map(); - - const issues = await github.paginate(github.rest.issues.listForRepo, { - owner, repo, state: 'open', per_page: 100, - }); - - let processed = 0; - let failures = 0; - for (const issue of issues) { - if (processed >= maxItems) break; - if (issue.pull_request) continue; - - try { - const author = issue.user.login; - const info = await h.getContributorInfo(contributorCache, author, issue.user.type); - - const labels = [info.isExternal ? 'external' : 'internal']; - if (info.isExternal && info.mergedCount != null && info.mergedCount >= h.trustedThreshold) { - labels.push('trusted-contributor'); - } - - // Ensure all labels exist before batch add - for (const name of labels) { - await h.ensureLabel(name); - } - - // Remove stale tier labels - const currentLabels = (await github.paginate( - github.rest.issues.listLabelsOnIssue, - { owner, repo, issue_number: issue.number, per_page: 100 }, - )).map(l => l.name ?? ''); - for (const name of currentLabels) { - if (tierLabels.includes(name) && !labels.includes(name)) { - try { - await github.rest.issues.removeLabel({ - owner, repo, issue_number: issue.number, name, - }); - } catch (e) { - if (e.status !== 404) throw e; - } - } - } - - await github.rest.issues.addLabels({ - owner, repo, issue_number: issue.number, labels, - }); - console.log(`Issue #${issue.number} (${author}): ${labels.join(', ')}`); - processed++; - } catch (e) { - failures++; - core.warning(`Failed to process issue #${issue.number}: ${e.message}`); - } - } - - console.log(`\nBackfill complete. Processed ${processed} issues, ${failures} failures. ${contributorCache.size} unique authors.`); diff --git a/AGENTS.md b/AGENTS.md index 588d5c5917..8202db2dad 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -290,52 +290,17 @@ The `echo y |` pipe is required when `--data-dir` is outside the `libs/model-pro ### Release process -Each partner package is released independently. The full flow is: +`langchain-decodo` (`libs/partners/decodo`) is the only package released from this repo, and releases are automated by `.github/workflows/publish.yml`. Merging to `master` publishes a new version based on the PR title, which must follow [Conventional Commits](https://www.conventionalcommits.org): `fix:` → patch, `feat:` → minor, `feat!:` or a `BREAKING CHANGE:` footer → major. `chore:`, `docs:`, `ci:`, `refactor:`, `test:` don't release, and neither do changes outside `libs/partners/decodo`. -1. **Version bump PR.** Create a PR that bumps three files by one line each: - - `langchain_/_version.py` — `__version__` - - `pyproject.toml` — `version` - - `uv.lock` — run `uv lock` from the package directory. If the diff includes unrelated changes (e.g. environment-dependent marker lines from a different local Python version), revert them and keep only the `version = "..."` line for the package being released +Don't edit the version in `pyproject.toml` or `_version.py`, and don't create tags or GitHub releases by hand. Both version fields stay at `0.0.0`; the workflow computes the next version from the latest `vX.Y.Z` tag, tags it, creates the GitHub release with generated notes, and publishes to PyPI. - Title follows Conventional Commits: `release(): ` (e.g. `release(openrouter): 0.2.6`). Use the branch name `release/-`. +### PR title linting - Patch vs. minor bump follows in-repo precedent: within a `0.x` series, fixes and additive features get a patch bump (e.g. `session_id` field → 0.2.1→0.2.2, `parallel_tool_calls` → 0.2.3→0.2.4). - -2. **Merge the PR** to `master`. - -3. **Trigger the release workflow.** Run `gh workflow run` against the "🚀 Package Release" workflow (`_release.yml`, file ID `63880841`): - - ```bash - gh workflow run 63880841 --repo langchain-ai/langchain \ - -f working-directory= -f release-version= - ``` - - `working-directory` is the short partner name from the workflow's dropdown (e.g. `openrouter`, not `libs/partners/openrouter`). - -4. **The workflow handles everything else automatically** — do **not** create a GitHub release or tag manually. The `mark-release` job (using `ncipollo/release-action`) creates the GitHub release, tag, and release notes after PyPI publish succeeds. The release notes body is auto-generated from commit history between the previous tag and HEAD. - - Monitor the run: - - ```bash - gh run view --repo langchain-ai/langchain - ``` - - The full job chain is: build → release-notes → pre-release-checks → TestPyPI publish → PyPI publish → tag GitHub release. - -### PR labeling and linting - -**Title linting** (`.github/workflows/pr_lint.yml`) - -**Auto-labeling:** - -- `.github/workflows/pr_labeler.yml` – Unified PR labeler (size, file, title, external/internal, contributor tier) -- `.github/workflows/pr_labeler_backfill.yml` – Manual backfill of PR labels on open PRs -- `.github/workflows/auto-label-by-package.yml` – Issue labeling by package -- `.github/workflows/tag-external-issues.yml` – Issue external/internal classification +`.github/workflows/pr_lint.yml` checks that PR titles follow Conventional Commits. ### Integration test tracing (LangSmith) -Scheduled and manually dispatched integration tests (`integration_tests.yml`) trace every run to LangSmith so failures link back to the originating Actions run. (`_release.yml` runs integration tests too, but does not currently configure LangSmith tracing.) +Scheduled and manually dispatched integration tests (`integration_tests.yml`) trace every run to LangSmith so failures link back to the originating Actions run. **Env vars set by CI:** @@ -355,9 +320,6 @@ When adding a new partner package, update these files: - `.github/ISSUE_TEMPLATE/*.yml` – Add to package dropdown - `.github/dependabot.yml` – Add dependency update entry -- `.github/scripts/pr-labeler-config.json` – Add file rule and scope-to-label mapping -- `.github/workflows/_release.yml` – Add API key secrets if needed -- `.github/workflows/auto-label-by-package.yml` – Add package label - `.github/workflows/check_diffs.yml` – Add to change detection - `.github/workflows/integration_tests.yml` – Add integration test config - `.github/workflows/pr_lint.yml` – Add to allowed scopes diff --git a/CLAUDE.md b/CLAUDE.md index 588d5c5917..8202db2dad 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -290,52 +290,17 @@ The `echo y |` pipe is required when `--data-dir` is outside the `libs/model-pro ### Release process -Each partner package is released independently. The full flow is: +`langchain-decodo` (`libs/partners/decodo`) is the only package released from this repo, and releases are automated by `.github/workflows/publish.yml`. Merging to `master` publishes a new version based on the PR title, which must follow [Conventional Commits](https://www.conventionalcommits.org): `fix:` → patch, `feat:` → minor, `feat!:` or a `BREAKING CHANGE:` footer → major. `chore:`, `docs:`, `ci:`, `refactor:`, `test:` don't release, and neither do changes outside `libs/partners/decodo`. -1. **Version bump PR.** Create a PR that bumps three files by one line each: - - `langchain_/_version.py` — `__version__` - - `pyproject.toml` — `version` - - `uv.lock` — run `uv lock` from the package directory. If the diff includes unrelated changes (e.g. environment-dependent marker lines from a different local Python version), revert them and keep only the `version = "..."` line for the package being released +Don't edit the version in `pyproject.toml` or `_version.py`, and don't create tags or GitHub releases by hand. Both version fields stay at `0.0.0`; the workflow computes the next version from the latest `vX.Y.Z` tag, tags it, creates the GitHub release with generated notes, and publishes to PyPI. - Title follows Conventional Commits: `release(): ` (e.g. `release(openrouter): 0.2.6`). Use the branch name `release/-`. +### PR title linting - Patch vs. minor bump follows in-repo precedent: within a `0.x` series, fixes and additive features get a patch bump (e.g. `session_id` field → 0.2.1→0.2.2, `parallel_tool_calls` → 0.2.3→0.2.4). - -2. **Merge the PR** to `master`. - -3. **Trigger the release workflow.** Run `gh workflow run` against the "🚀 Package Release" workflow (`_release.yml`, file ID `63880841`): - - ```bash - gh workflow run 63880841 --repo langchain-ai/langchain \ - -f working-directory= -f release-version= - ``` - - `working-directory` is the short partner name from the workflow's dropdown (e.g. `openrouter`, not `libs/partners/openrouter`). - -4. **The workflow handles everything else automatically** — do **not** create a GitHub release or tag manually. The `mark-release` job (using `ncipollo/release-action`) creates the GitHub release, tag, and release notes after PyPI publish succeeds. The release notes body is auto-generated from commit history between the previous tag and HEAD. - - Monitor the run: - - ```bash - gh run view --repo langchain-ai/langchain - ``` - - The full job chain is: build → release-notes → pre-release-checks → TestPyPI publish → PyPI publish → tag GitHub release. - -### PR labeling and linting - -**Title linting** (`.github/workflows/pr_lint.yml`) - -**Auto-labeling:** - -- `.github/workflows/pr_labeler.yml` – Unified PR labeler (size, file, title, external/internal, contributor tier) -- `.github/workflows/pr_labeler_backfill.yml` – Manual backfill of PR labels on open PRs -- `.github/workflows/auto-label-by-package.yml` – Issue labeling by package -- `.github/workflows/tag-external-issues.yml` – Issue external/internal classification +`.github/workflows/pr_lint.yml` checks that PR titles follow Conventional Commits. ### Integration test tracing (LangSmith) -Scheduled and manually dispatched integration tests (`integration_tests.yml`) trace every run to LangSmith so failures link back to the originating Actions run. (`_release.yml` runs integration tests too, but does not currently configure LangSmith tracing.) +Scheduled and manually dispatched integration tests (`integration_tests.yml`) trace every run to LangSmith so failures link back to the originating Actions run. **Env vars set by CI:** @@ -355,9 +320,6 @@ When adding a new partner package, update these files: - `.github/ISSUE_TEMPLATE/*.yml` – Add to package dropdown - `.github/dependabot.yml` – Add dependency update entry -- `.github/scripts/pr-labeler-config.json` – Add file rule and scope-to-label mapping -- `.github/workflows/_release.yml` – Add API key secrets if needed -- `.github/workflows/auto-label-by-package.yml` – Add package label - `.github/workflows/check_diffs.yml` – Add to change detection - `.github/workflows/integration_tests.yml` – Add integration test config - `.github/workflows/pr_lint.yml` – Add to allowed scopes diff --git a/libs/partners/decodo/langchain_decodo/_version.py b/libs/partners/decodo/langchain_decodo/_version.py index bbab0242f6..6c8e6b979c 100644 --- a/libs/partners/decodo/langchain_decodo/_version.py +++ b/libs/partners/decodo/langchain_decodo/_version.py @@ -1 +1 @@ -__version__ = "0.1.4" +__version__ = "0.0.0" diff --git a/libs/partners/decodo/pyproject.toml b/libs/partners/decodo/pyproject.toml index fcac80c919..654d6cbda3 100644 --- a/libs/partners/decodo/pyproject.toml +++ b/libs/partners/decodo/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "hatchling.build" [project] name = "langchain-decodo" -version = "0.1.4" +version = "0.0.0" description = "LangChain integration for the Decodo web scraping API" readme = "README.md" license = { text = "MIT" } @@ -59,3 +59,20 @@ strict = true [tool.pytest.ini_options] asyncio_mode = "auto" + +[tool.semantic_release] +version_toml = ["pyproject.toml:project.version"] +version_variables = ["langchain_decodo/_version.py:__version__"] +commit_parser = "conventional-monorepo" +allow_zero_version = true + +[tool.semantic_release.commit_parser_options] +# Same types as .github/workflows/pr_lint.yml; PSR ignores commits of any type left out. +allowed_tags = [ + "feat", "fix", "docs", "style", "refactor", "perf", "test", "build", "ci", "chore", "revert", + "release", "hotfix", +] +patch_tags = ["fix", "perf", "hotfix"] + +[tool.semantic_release.branches.master] +match = "master" diff --git a/libs/partners/decodo/uv.lock b/libs/partners/decodo/uv.lock index 57534bfda7..aae16093e1 100644 --- a/libs/partners/decodo/uv.lock +++ b/libs/partners/decodo/uv.lock @@ -342,7 +342,7 @@ wheels = [ [[package]] name = "langchain-decodo" -version = "0.1.4" +version = "0.0.0" source = { editable = "." } dependencies = [ { name = "httpx" },