mirror of
https://github.com/hwchase17/langchain.git
synced 2025-07-17 10:13:29 +00:00
infra: simplify and fix CI for docs-only changes (#18058)
Current success check will fail on docs-only changes
This commit is contained in:
parent
1a3383fba1
commit
e566a3077e
63
.github/scripts/check_diff.py
vendored
63
.github/scripts/check_diff.py
vendored
@ -1,17 +1,23 @@
|
|||||||
import json
|
import json
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
|
from typing import Dict
|
||||||
|
|
||||||
LANGCHAIN_DIRS = {
|
LANGCHAIN_DIRS = [
|
||||||
"libs/core",
|
"libs/core",
|
||||||
"libs/langchain",
|
"libs/langchain",
|
||||||
"libs/experimental",
|
"libs/experimental",
|
||||||
"libs/community",
|
"libs/community",
|
||||||
}
|
]
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
files = sys.argv[1:]
|
files = sys.argv[1:]
|
||||||
dirs_to_run = set()
|
|
||||||
|
dirs_to_run: Dict[str, set] = {
|
||||||
|
"lint": set(),
|
||||||
|
"test": set(),
|
||||||
|
"extended-test": set(),
|
||||||
|
}
|
||||||
|
|
||||||
if len(files) == 300:
|
if len(files) == 300:
|
||||||
# max diff length is 300 files - there are likely files missing
|
# max diff length is 300 files - there are likely files missing
|
||||||
@ -24,31 +30,42 @@ if __name__ == "__main__":
|
|||||||
".github/workflows",
|
".github/workflows",
|
||||||
".github/tools",
|
".github/tools",
|
||||||
".github/actions",
|
".github/actions",
|
||||||
"libs/core",
|
|
||||||
".github/scripts/check_diff.py",
|
".github/scripts/check_diff.py",
|
||||||
)
|
)
|
||||||
):
|
):
|
||||||
dirs_to_run.update(LANGCHAIN_DIRS)
|
# add all LANGCHAIN_DIRS for infra changes
|
||||||
elif "libs/community" in file:
|
dirs_to_run["extended-test"].update(LANGCHAIN_DIRS)
|
||||||
dirs_to_run.update(
|
dirs_to_run["lint"].add(".")
|
||||||
("libs/community", "libs/langchain", "libs/experimental")
|
|
||||||
)
|
if any(file.startswith(dir_) for dir_ in LANGCHAIN_DIRS):
|
||||||
elif "libs/partners" in file:
|
# add that dir and all dirs after in LANGCHAIN_DIRS
|
||||||
|
# for extended testing
|
||||||
|
found = False
|
||||||
|
for dir_ in LANGCHAIN_DIRS:
|
||||||
|
if file.startswith(dir_):
|
||||||
|
found = True
|
||||||
|
if found:
|
||||||
|
dirs_to_run["extended-test"].add(dir_)
|
||||||
|
elif file.startswith("libs/partners"):
|
||||||
partner_dir = file.split("/")[2]
|
partner_dir = file.split("/")[2]
|
||||||
if os.path.isdir(f"libs/partners/{partner_dir}"):
|
if os.path.isdir(f"libs/partners/{partner_dir}"):
|
||||||
dirs_to_run.add(f"libs/partners/{partner_dir}")
|
dirs_to_run["test"].add(f"libs/partners/{partner_dir}")
|
||||||
# Skip if the directory was deleted
|
# Skip if the directory was deleted
|
||||||
elif "libs/langchain" in file:
|
|
||||||
dirs_to_run.update(("libs/langchain", "libs/experimental"))
|
|
||||||
elif "libs/experimental" in file:
|
|
||||||
dirs_to_run.add("libs/experimental")
|
|
||||||
elif file.startswith("libs/"):
|
elif file.startswith("libs/"):
|
||||||
dirs_to_run.update(LANGCHAIN_DIRS)
|
raise ValueError(
|
||||||
else:
|
f"Unknown lib: {file}. check_diff.py likely needs "
|
||||||
pass
|
"an update for this new library!"
|
||||||
json_output = json.dumps(list(dirs_to_run))
|
)
|
||||||
print(f"dirs-to-run={json_output}") # noqa: T201
|
elif any(file.startswith(p) for p in ["docs/", "templates/", "cookbook/"]):
|
||||||
|
dirs_to_run["lint"].add(".")
|
||||||
|
|
||||||
extended_test_dirs = [d for d in dirs_to_run if not d.startswith("libs/partners")]
|
outputs = {
|
||||||
json_output_extended = json.dumps(extended_test_dirs)
|
"dirs-to-lint": list(
|
||||||
print(f"dirs-to-run-extended={json_output_extended}") # noqa: T201
|
dirs_to_run["lint"] | dirs_to_run["test"] | dirs_to_run["extended-test"]
|
||||||
|
),
|
||||||
|
"dirs-to-test": list(dirs_to_run["test"] | dirs_to_run["extended-test"]),
|
||||||
|
"dirs-to-extended-test": list(dirs_to_run["extended-test"]),
|
||||||
|
}
|
||||||
|
for key, value in outputs.items():
|
||||||
|
json_output = json.dumps(value)
|
||||||
|
print(f"{key}={json_output}") # noqa: T201
|
||||||
|
21
.github/workflows/check_diffs.yml
vendored
21
.github/workflows/check_diffs.yml
vendored
@ -33,14 +33,16 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
python .github/scripts/check_diff.py ${{ steps.files.outputs.all }} >> $GITHUB_OUTPUT
|
python .github/scripts/check_diff.py ${{ steps.files.outputs.all }} >> $GITHUB_OUTPUT
|
||||||
outputs:
|
outputs:
|
||||||
dirs-to-run: ${{ steps.set-matrix.outputs.dirs-to-run }}
|
dirs-to-lint: ${{ steps.set-matrix.outputs.dirs-to-lint }}
|
||||||
dirs-to-run-extended: ${{ steps.set-matrix.outputs.dirs-to-run-extended }}
|
dirs-to-test: ${{ steps.set-matrix.outputs.dirs-to-test }}
|
||||||
|
dirs-to-extended-test: ${{ steps.set-matrix.outputs.dirs-to-extended-test }}
|
||||||
lint:
|
lint:
|
||||||
name: cd ${{ matrix.working-directory }}
|
name: cd ${{ matrix.working-directory }}
|
||||||
needs: [ build ]
|
needs: [ build ]
|
||||||
|
if: ${{ needs.build.outputs.dirs-to-lint != '[]' }}
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
working-directory: ${{ fromJson(needs.build.outputs.dirs-to-run) }}
|
working-directory: ${{ fromJson(needs.build.outputs.dirs-to-lint) }}
|
||||||
uses: ./.github/workflows/_lint.yml
|
uses: ./.github/workflows/_lint.yml
|
||||||
with:
|
with:
|
||||||
working-directory: ${{ matrix.working-directory }}
|
working-directory: ${{ matrix.working-directory }}
|
||||||
@ -49,9 +51,10 @@ jobs:
|
|||||||
test:
|
test:
|
||||||
name: cd ${{ matrix.working-directory }}
|
name: cd ${{ matrix.working-directory }}
|
||||||
needs: [ build ]
|
needs: [ build ]
|
||||||
|
if: ${{ needs.build.outputs.dirs-to-test != '[]' }}
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
working-directory: ${{ fromJson(needs.build.outputs.dirs-to-run) }}
|
working-directory: ${{ fromJson(needs.build.outputs.dirs-to-test) }}
|
||||||
uses: ./.github/workflows/_test.yml
|
uses: ./.github/workflows/_test.yml
|
||||||
with:
|
with:
|
||||||
working-directory: ${{ matrix.working-directory }}
|
working-directory: ${{ matrix.working-directory }}
|
||||||
@ -60,9 +63,10 @@ jobs:
|
|||||||
compile-integration-tests:
|
compile-integration-tests:
|
||||||
name: cd ${{ matrix.working-directory }}
|
name: cd ${{ matrix.working-directory }}
|
||||||
needs: [ build ]
|
needs: [ build ]
|
||||||
|
if: ${{ needs.build.outputs.dirs-to-test != '[]' }}
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
working-directory: ${{ fromJson(needs.build.outputs.dirs-to-run) }}
|
working-directory: ${{ fromJson(needs.build.outputs.dirs-to-test) }}
|
||||||
uses: ./.github/workflows/_compile_integration_test.yml
|
uses: ./.github/workflows/_compile_integration_test.yml
|
||||||
with:
|
with:
|
||||||
working-directory: ${{ matrix.working-directory }}
|
working-directory: ${{ matrix.working-directory }}
|
||||||
@ -71,9 +75,10 @@ jobs:
|
|||||||
dependencies:
|
dependencies:
|
||||||
name: cd ${{ matrix.working-directory }}
|
name: cd ${{ matrix.working-directory }}
|
||||||
needs: [ build ]
|
needs: [ build ]
|
||||||
|
if: ${{ needs.build.outputs.dirs-to-test != '[]' }}
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
working-directory: ${{ fromJson(needs.build.outputs.dirs-to-run) }}
|
working-directory: ${{ fromJson(needs.build.outputs.dirs-to-test) }}
|
||||||
uses: ./.github/workflows/_dependencies.yml
|
uses: ./.github/workflows/_dependencies.yml
|
||||||
with:
|
with:
|
||||||
working-directory: ${{ matrix.working-directory }}
|
working-directory: ${{ matrix.working-directory }}
|
||||||
@ -82,11 +87,11 @@ jobs:
|
|||||||
extended-tests:
|
extended-tests:
|
||||||
name: "cd ${{ matrix.working-directory }} / make extended_tests #${{ matrix.python-version }}"
|
name: "cd ${{ matrix.working-directory }} / make extended_tests #${{ matrix.python-version }}"
|
||||||
needs: [ build ]
|
needs: [ build ]
|
||||||
if: ${{ needs.build.outputs.dirs-to-run-extended != '[]' }}
|
if: ${{ needs.build.outputs.dirs-to-extended-test != '[]' }}
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
# note different variable for extended test dirs
|
# note different variable for extended test dirs
|
||||||
working-directory: ${{ fromJson(needs.build.outputs.dirs-to-run-extended) }}
|
working-directory: ${{ fromJson(needs.build.outputs.dirs-to-extended-test) }}
|
||||||
python-version:
|
python-version:
|
||||||
- "3.8"
|
- "3.8"
|
||||||
- "3.9"
|
- "3.9"
|
||||||
|
37
.github/workflows/doc_lint.yml
vendored
37
.github/workflows/doc_lint.yml
vendored
@ -1,37 +0,0 @@
|
|||||||
---
|
|
||||||
name: CI / cd .
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches: [ master ]
|
|
||||||
pull_request:
|
|
||||||
paths:
|
|
||||||
- 'docs/**'
|
|
||||||
- 'templates/**'
|
|
||||||
- 'cookbook/**'
|
|
||||||
- '.github/workflows/_lint.yml'
|
|
||||||
- '.github/workflows/doc_lint.yml'
|
|
||||||
workflow_dispatch:
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
check:
|
|
||||||
name: Check for "from langchain import x" imports
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: Checkout repository
|
|
||||||
uses: actions/checkout@v4
|
|
||||||
|
|
||||||
- name: Run import check
|
|
||||||
run: |
|
|
||||||
# We should not encourage imports directly from main init file
|
|
||||||
# Expect for hub
|
|
||||||
git grep 'from langchain import' {docs/docs,templates,cookbook} | grep -vE 'from langchain import (hub)' && exit 1 || exit 0
|
|
||||||
|
|
||||||
lint:
|
|
||||||
name: "-"
|
|
||||||
uses:
|
|
||||||
./.github/workflows/_lint.yml
|
|
||||||
with:
|
|
||||||
working-directory: "."
|
|
||||||
secrets: inherit
|
|
2
Makefile
2
Makefile
@ -50,11 +50,13 @@ lint lint_package lint_tests:
|
|||||||
poetry run ruff docs templates cookbook
|
poetry run ruff docs templates cookbook
|
||||||
poetry run ruff format docs templates cookbook --diff
|
poetry run ruff format docs templates cookbook --diff
|
||||||
poetry run ruff --select I docs templates cookbook
|
poetry run ruff --select I docs templates cookbook
|
||||||
|
git grep 'from langchain import' {docs/docs,templates,cookbook} | grep -vE 'from langchain import (hub)' && exit 1 || exit 0
|
||||||
|
|
||||||
format format_diff:
|
format format_diff:
|
||||||
poetry run ruff format docs templates cookbook
|
poetry run ruff format docs templates cookbook
|
||||||
poetry run ruff --select I --fix docs templates cookbook
|
poetry run ruff --select I --fix docs templates cookbook
|
||||||
|
|
||||||
|
|
||||||
######################
|
######################
|
||||||
# HELP
|
# HELP
|
||||||
######################
|
######################
|
||||||
|
Loading…
Reference in New Issue
Block a user