Skip to content

Commit ac204f8

Browse files
ci[patch]: Only run CI testsing if specific package touched (#5733)
* ci[patch]: Only run latest/lowest if specific package touched * matrix it! * docs for new integration ci testsing * make change to core to test * Update chat.ts * fix if statements * fix if integrations * test * revert * conditionally run test exports * conditionally run standard tests too and make oai change to trigger --------- Co-authored-by: Jacob Lee <[email protected]>
1 parent 13f392a commit ac204f8

8 files changed

+109
-64
lines changed

.github/workflows/compatibility.yml

+39-2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ on:
44
push:
55
branches: ["main"]
66
pull_request:
7-
# Do not run this workflow if only docs changed.
7+
# Do not run this workflow if only docs/examples changed.
88
paths-ignore:
99
- 'docs/**'
10+
- 'examples/**'
1011
workflow_dispatch: # Allows triggering the workflow manually in GitHub UI
1112

1213
# If another push to the same PR or branch happens while this workflow is still running,
@@ -28,9 +29,27 @@ env:
2829
# Run a separate job for each check in the docker-compose file,
2930
# so that they run in parallel instead of overwhelming the default 2 CPU runner.
3031
jobs:
32+
get-changed-files:
33+
runs-on: ubuntu-latest
34+
outputs:
35+
changed_files: ${{ steps.get_changes.outputs.changed_files }}
36+
steps:
37+
- name: Checkout
38+
uses: actions/checkout@v3
39+
with:
40+
fetch-depth: 2
41+
- name: Get changes
42+
id: get_changes
43+
run: |
44+
echo "changed_files<<EOF" >> $GITHUB_OUTPUT
45+
git diff --name-only -r HEAD^1 HEAD | while read line; do printf "%s\n" "$line"; done >> $GITHUB_OUTPUT
46+
echo "EOF" >> $GITHUB_OUTPUT
47+
3148
# LangChain
3249
langchain-latest-deps:
3350
runs-on: ubuntu-latest
51+
needs: get-changed-files
52+
if: contains(needs.get-changed-files.outputs.changed_files, 'langchain/') || contains(needs.get-changed-files.outputs.changed_files, 'langchain-core/') || contains(needs.get-changed-files.outputs.changed_files, 'libs/langchain-openai/') || contains(needs.get-changed-files.outputs.changed_files, 'libs/langchain-textsplitters/')
3453
steps:
3554
- uses: actions/checkout@v4
3655
- name: Use Node.js ${{ env.NODE_VERSION }}
@@ -43,6 +62,8 @@ jobs:
4362

4463
langchain-lowest-deps:
4564
runs-on: ubuntu-latest
65+
needs: get-changed-files
66+
if: contains(needs.get-changed-files.outputs.changed_files, 'langchain/')
4667
steps:
4768
- uses: actions/checkout@v4
4869
- name: Use Node.js ${{ env.NODE_VERSION }}
@@ -56,6 +77,8 @@ jobs:
5677
# Community
5778
community-latest-deps:
5879
runs-on: ubuntu-latest
80+
needs: get-changed-files
81+
if: contains(needs.get-changed-files.outputs.changed_files, 'langchain-core/') || contains(needs.get-changed-files.outputs.changed_files, 'libs/langchain-openai/') || contains(needs.get-changed-files.outputs.changed_files, 'libs/langchain-community/')
5982
steps:
6083
- uses: actions/checkout@v4
6184
- name: Use Node.js ${{ env.NODE_VERSION }}
@@ -72,6 +95,8 @@ jobs:
7295

7396
community-lowest-deps:
7497
runs-on: ubuntu-latest
98+
needs: get-changed-files
99+
if: contains(needs.get-changed-files.outputs.changed_files, 'libs/langchain-community/')
75100
steps:
76101
- uses: actions/checkout@v4
77102
- name: Use Node.js ${{ env.NODE_VERSION }}
@@ -89,6 +114,8 @@ jobs:
89114
# OpenAI
90115
openai-latest-deps:
91116
runs-on: ubuntu-latest
117+
needs: get-changed-files
118+
if: contains(needs.get-changed-files.outputs.changed_files, 'langchain-core/') || contains(needs.get-changed-files.outputs.changed_files, 'libs/langchain-openai/')
92119
steps:
93120
- uses: actions/checkout@v4
94121
- name: Use Node.js ${{ env.NODE_VERSION }}
@@ -105,6 +132,8 @@ jobs:
105132

106133
openai-lowest-deps:
107134
runs-on: ubuntu-latest
135+
needs: get-changed-files
136+
if: contains(needs.get-changed-files.outputs.changed_files, 'libs/langchain-openai/')
108137
steps:
109138
- uses: actions/checkout@v4
110139
- name: Use Node.js ${{ env.NODE_VERSION }}
@@ -122,6 +151,8 @@ jobs:
122151
# Anthropic
123152
anthropic-latest-deps:
124153
runs-on: ubuntu-latest
154+
needs: get-changed-files
155+
if: contains(needs.get-changed-files.outputs.changed_files, 'langchain-core/') || contains(needs.get-changed-files.outputs.changed_files, 'libs/langchain-anthropic/')
125156
steps:
126157
- uses: actions/checkout@v4
127158
- name: Use Node.js ${{ env.NODE_VERSION }}
@@ -138,6 +169,8 @@ jobs:
138169

139170
anthropic-lowest-deps:
140171
runs-on: ubuntu-latest
172+
needs: get-changed-files
173+
if: contains(needs.get-changed-files.outputs.changed_files, 'libs/langchain-anthropic/')
141174
steps:
142175
- uses: actions/checkout@v4
143176
- name: Use Node.js ${{ env.NODE_VERSION }}
@@ -155,6 +188,8 @@ jobs:
155188
# Google VertexAI
156189
google-vertexai-latest-deps:
157190
runs-on: ubuntu-latest
191+
needs: get-changed-files
192+
if: contains(needs.get-changed-files.outputs.changed_files, 'langchain-core/') || contains(needs.get-changed-files.outputs.changed_files, 'libs/langchain-google-vertexai/') || contains(needs.get-changed-files.outputs.changed_files, 'libs/langchain-google-gauth/') || contains(needs.get-changed-files.outputs.changed_files, 'libs/langchain-google-common/')
158193
steps:
159194
- uses: actions/checkout@v4
160195
- name: Use Node.js ${{ env.NODE_VERSION }}
@@ -171,6 +206,8 @@ jobs:
171206

172207
google-vertexai-lowest-deps:
173208
runs-on: ubuntu-latest
209+
needs: get-changed-files
210+
if: contains(needs.get-changed-files.outputs.changed_files, 'libs/langchain-google-vertexai/')
174211
steps:
175212
- uses: actions/checkout@v4
176213
- name: Use Node.js ${{ env.NODE_VERSION }}
@@ -183,4 +220,4 @@ jobs:
183220
- name: Build `@langchain/standard-tests`
184221
run: yarn build --filter=@langchain/standard-tests
185222
- name: Test `@langchain/google-vertexai` with lowest deps
186-
run: docker compose -f dependency_range_tests/docker-compose.yml run google-vertexai-lowest-deps
223+
run: docker compose -f dependency_range_tests/docker-compose.yml run google-vertexai-lowest-deps

.github/workflows/standard-tests.yml

+24
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,29 @@ on:
66
- cron: '0 13 * * *'
77

88
jobs:
9+
get-changed-files:
10+
runs-on: ubuntu-latest
11+
outputs:
12+
changed_files: ${{ steps.get_changes.outputs.changed_files }}
13+
steps:
14+
- name: Checkout
15+
uses: actions/checkout@v3
16+
with:
17+
fetch-depth: 2
18+
- name: Get changes
19+
id: get_changes
20+
run: |
21+
echo "changed_files<<EOF" >> $GITHUB_OUTPUT
22+
git diff --name-only -r HEAD^1 HEAD | while read line; do printf "%s\n" "$line"; done >> $GITHUB_OUTPUT
23+
echo "EOF" >> $GITHUB_OUTPUT
24+
925
standard-tests:
1026
runs-on: ubuntu-latest
27+
needs: get-changed-files
1128
strategy:
1229
matrix:
1330
package: [anthropic, cohere, google-genai, groq, mistralai]
31+
if: contains(needs.get-changed-files.outputs.changed_files, 'langchain-core/') || contains(needs.get-changed-files.outputs.changed_files, 'libs/langchain-${{ matrix.package }}/')
1432
steps:
1533
- uses: actions/checkout@v4
1634
- name: Use Node.js 18.x
@@ -34,6 +52,8 @@ jobs:
3452
# we need separate jobs for each test.
3553
standard-tests-openai:
3654
runs-on: ubuntu-latest
55+
needs: get-changed-files
56+
if: contains(needs.get-changed-files.outputs.changed_files, 'langchain-core/') || contains(needs.get-changed-files.outputs.changed_files, 'libs/langchain-openai/')
3757
steps:
3858
- uses: actions/checkout@v4
3959
- name: Use Node.js 18.x
@@ -52,6 +72,8 @@ jobs:
5272

5373
standard-tests-azure-openai:
5474
runs-on: ubuntu-latest
75+
needs: get-changed-files
76+
if: contains(needs.get-changed-files.outputs.changed_files, 'langchain-core/') || contains(needs.get-changed-files.outputs.changed_files, 'libs/langchain-openai/')
5577
steps:
5678
- uses: actions/checkout@v4
5779
- name: Use Node.js 18.x
@@ -73,6 +95,8 @@ jobs:
7395

7496
standard-tests-bedrock:
7597
runs-on: ubuntu-latest
98+
needs: get-changed-files
99+
if: contains(needs.get-changed-files.outputs.changed_files, 'langchain-core/') || contains(needs.get-changed-files.outputs.changed_files, 'libs/langchain-community/')
76100
steps:
77101
- uses: actions/checkout@v4
78102
- name: Use Node.js 18.x

.github/workflows/test-exports.yml

+9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
name: Environment tests
22

33
on:
4+
pull_request:
5+
# Only run workflow if files in these directories are changed
6+
paths:
7+
- 'langchain/**'
8+
- 'langchain-core/**'
9+
- 'libs/langchain-anthropic/**'
10+
- 'libs/langchain-community/**'
11+
- 'libs/langchain-openai/**'
12+
- 'examples/**'
413
workflow_dispatch: # Allows triggering the workflow manually in GitHub UI
514
workflow_call: # Allows triggering the workflow from another workflow
615

.github/workflows/unit-tests-langchain-integrations.yml renamed to .github/workflows/unit-tests-integrations.yml

+21-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ on:
1111
paths:
1212
- 'langchain-core/**'
1313
- 'libs/**/**'
14-
- '!libs/langchain-community/**'
1514
workflow_dispatch: # Allows triggering the workflow manually in GitHub UI
1615

1716

@@ -26,19 +25,38 @@ concurrency:
2625
cancel-in-progress: true
2726

2827
jobs:
28+
get-changed-files:
29+
runs-on: ubuntu-latest
30+
outputs:
31+
changed_files: ${{ steps.get_changes.outputs.changed_files }}
32+
steps:
33+
- name: Checkout
34+
uses: actions/checkout@v3
35+
with:
36+
fetch-depth: 2
37+
- name: Get changes
38+
id: get_changes
39+
run: |
40+
echo "changed_files<<EOF" >> $GITHUB_OUTPUT
41+
git diff --name-only -r HEAD^1 HEAD | while read line; do printf "%s\n" "$line"; done >> $GITHUB_OUTPUT
42+
echo "EOF" >> $GITHUB_OUTPUT
43+
2944
unit-tests:
3045
name: Unit Tests
46+
needs: get-changed-files
3147
strategy:
3248
matrix:
3349
os: [ubuntu-latest]
3450
node-version: [18.x, 20.x]
51+
package: [anthropic, azure-openai, cloudflare, cohere, community, exa, google-common, google-gauth, google-genai, google-vertexai, google-vertexai-web, google-webauth, groq, mistralai, mongo, nomic, openai, pinecone, qdrant, redis, textsplitters, weaviate, yandex]
3552
# See Node.js release schedule at https://nodejs.org/en/about/releases/
3653
# include:
3754
# - os: windows-latest
3855
# node-version: 20.x
3956
# - os: macos-latest
4057
# node-version: 20.x
4158
runs-on: ${{ matrix.os }}
59+
if: contains(needs.get-changed-files.outputs.changed_files, 'langchain-core/') || contains(needs.get-changed-files.outputs.changed_files, 'libs/langchain-${{ matrix.package }}/')
4260
env:
4361
PUPPETEER_SKIP_DOWNLOAD: "true"
4462
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD: "true"
@@ -51,5 +69,5 @@ jobs:
5169
cache: "yarn"
5270
- name: Install dependencies
5371
run: yarn install --immutable
54-
- name: Test
55-
run: yarn run test:unit:ci --filter=!@langchain/community --filter=!@langchain/core --filter=!langchain --filter=!api_refs --filter=!core_docs --filter=!create-langchain-integration --filter=!examples
72+
- name: Test '@langchain/${{ matrix.package }}' package
73+
run: yarn test:unit:ci --filter=@langchain/${{ matrix.package }}

.github/workflows/unit-tests-langchain-community.yml

-54
This file was deleted.

CONTRIBUTING.md

+12
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,18 @@ To make creating packages like this easier, we offer the [`create-langchain-inte
3737
$ npx create-langchain-integration
3838
```
3939

40+
After creating the new integration package, you should add it to the [`unit-tests-integrations.yml`](./.github/workflows/unit-tests-integrations.yml) GitHub action workflow so that it is tested in CI. To do this, simply add the integration name inside the `jobs.unit-tests.strategy.matrix.package` array:
41+
42+
```yaml
43+
jobs:
44+
unit-tests:
45+
name: Unit Tests
46+
strategy:
47+
matrix:
48+
package: [anthropic, azure-openai, cloudflare, <your package name>]
49+
...
50+
```
51+
4052
### Want to add a feature that's already in Python?
4153

4254
If you're interested in contributing a feature that's already in the [LangChain Python repo](https://github.com/langchain-ai/langchain) and you'd like some help getting started, you can try pasting code snippets and classes into the [LangChain Python to JS translator](https://langchain-translator.vercel.app/).

libs/langchain-openai/src/chat_models.ts

+3-4
Original file line numberDiff line numberDiff line change
@@ -274,14 +274,13 @@ export interface ChatOpenAICallOptions
274274
/**
275275
* Wrapper around OpenAI large language models that use the Chat endpoint.
276276
*
277-
* To use you should have the `openai` package installed, with the
278-
* `OPENAI_API_KEY` environment variable set.
277+
* To use you should have the `OPENAI_API_KEY` environment variable set.
279278
*
280-
* To use with Azure you should have the `openai` package installed, with the
279+
* To use with Azure you should have the:
281280
* `AZURE_OPENAI_API_KEY`,
282281
* `AZURE_OPENAI_API_INSTANCE_NAME`,
283282
* `AZURE_OPENAI_API_DEPLOYMENT_NAME`
284-
* and `AZURE_OPENAI_API_VERSION` environment variable set.
283+
* and `AZURE_OPENAI_API_VERSION` environment variables set.
285284
* `AZURE_OPENAI_BASE_PATH` is optional and will override `AZURE_OPENAI_API_INSTANCE_NAME` if you need to use a custom endpoint.
286285
*
287286
* @remarks

turbo.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
},
2525
"test:ci": {
2626
"outputs": [],
27-
"dependsOn": ["test"]
27+
"dependsOn": ["^test", "test"]
2828
},
2929
"test:single": {
3030
"dependsOn": ["^build", "build"]

0 commit comments

Comments
 (0)