Skip to content

Commit a3f410d

Browse files
authored
feat(ci): test against multiple versions (#86)
* feat(ci): test against mulitple versions * Update sync-repo-settings.yaml * Update sync-repo-settings.yaml * Update test_cloudsql_vectorstore_index.py
1 parent e143e14 commit a3f410d

File tree

7 files changed

+113
-8
lines changed

7 files changed

+113
-8
lines changed

.github/header-checker-lint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ ignoreFiles:
1818
- ".github/sync-repo-settings.yaml"
1919
- ".kokoro/**"
2020
- "**/requirements.txt"
21-
- "**/requirements-test.txt"
21+
- "**/requirements*.txt"

.github/sync-repo-settings.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@ branchProtectionRules:
2727
requiredStatusCheckContexts:
2828
- "cla/google"
2929
- "lint"
30-
- "pg-integration-test-pr (langchain-cloud-sql-testing)"
30+
- "pg-integration-test-pr-py38 (langchain-cloud-sql-testing)"
31+
- "pg-integration-test-pr-py39 (langchain-cloud-sql-testing)"
32+
- "pg-integration-test-pr-py310 (langchain-cloud-sql-testing)"
33+
- "pg-integration-test-pr-py311 (langchain-cloud-sql-testing)"
34+
- "pg-integration-test-pr-py312 (langchain-cloud-sql-testing)"
3135
- "conventionalcommits.org"
3236
- "header-check"
3337
# - Add required status checks like presubmit tests

DEVELOPER.md

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# DEVELOPER.md
2+
3+
## Versioning
4+
5+
This library follows [Semantic Versioning](http://semver.org/).
6+
7+
## Processes
8+
9+
### Conventional Commit messages
10+
11+
This repository uses tool [Release Please](https://github.com/googleapis/release-please) to create GitHub and PyPi releases. It does so by parsing your
12+
git history, looking for [Conventional Commit messages](https://www.conventionalcommits.org/),
13+
and creating release PRs.
14+
15+
Learn more by reading [How should I write my commits?](https://github.com/googleapis/release-please?tab=readme-ov-file#how-should-i-write-my-commits)
16+
17+
## Testing
18+
19+
### Run tests locally
20+
21+
1. Set environment variables for `INSTANCE_ID`, `DATABASE_ID`, `REGION`, `DB_USER`, `DB_PASSWORD`
22+
23+
1. Run pytest to automatically run all tests:
24+
25+
```bash
26+
pytest
27+
```
28+
29+
### CI Platform Setup
30+
31+
Cloud Build is used to run tests against Google Cloud resources in test project: langchain-alloydb-testing.
32+
Each test has a corresponding Cloud Build trigger, see [all triggers][triggers].
33+
These tests are registered as required tests in `.github/sync-repo-settings.yaml`.
34+
35+
#### Trigger Setup
36+
37+
Cloud Build triggers (for Python versions 3.8 to 3.11) were created with the following specs:
38+
39+
```YAML
40+
name: pg-integration-test-pr-py38
41+
description: Run integration tests on PR for Python 3.8
42+
filename: integration.cloudbuild.yaml
43+
github:
44+
name: langchain-google-alloydb-pg-python
45+
owner: googleapis
46+
pullRequest:
47+
branch: .*
48+
commentControl: COMMENTS_ENABLED_FOR_EXTERNAL_CONTRIBUTORS_ONLY
49+
ignoredFiles:
50+
- docs/**
51+
- .kokoro/**
52+
- .github/**
53+
- "*.md"
54+
substitutions:
55+
_CLUSTER_ID: <ADD_VALUE>
56+
_DATABASE_ID: <ADD_VALUE>
57+
_INSTANCE_ID: <ADD_VALUE>
58+
_REGION: us-central1
59+
_VERSION: "3.8"
60+
```
61+
62+
Use `gcloud builds triggers import --source=trigger.yaml` create triggers via the command line
63+
64+
#### Project Setup
65+
66+
1. Create an Cloud SQL for PostgreSQL instance and database
67+
1. Setup Cloud Build triggers (above)
68+
69+
#### Run tests with Cloud Build
70+
71+
* Run integration test:
72+
73+
```bash
74+
gcloud builds submit --config integration.cloudbuild.yaml --region us-central1 --substitutions=_INSTANCE_ID=$INSTANCE_ID,_DATABASE_ID=$DATABASE_ID,_REGION=$REGION
75+
```
76+
77+
#### Trigger
78+
79+
To run Cloud Build tests on GitHub from external contributors, ie RenovateBot, comment: `/gcbrun`.
80+
81+
82+
[triggers]: https://console.cloud.google.com/cloud-build/triggers?e=13802955&project=langchain-cloud-sql-testing

integration.cloudbuild.yaml

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,21 @@
1414

1515
steps:
1616
- id: Install dependencies
17-
name: python:3.11
18-
entrypoint: pip
19-
args: ["install", "--user", "-r", "requirements.txt"]
17+
name: python:${_VERSION}
18+
entrypoint: /bin/bash
19+
args:
20+
- -c
21+
- |
22+
if [[ $_VERSION == "3.8" ]]; then version="-3.8"; fi
23+
pip install --user -r requirements${version}.txt
2024
2125
- id: Install module (and test requirements)
22-
name: python:3.11
26+
name: python:${_VERSION}
2327
entrypoint: pip
2428
args: ["install", ".[test]", "--user"]
2529

2630
- id: Run integration tests
27-
name: python:3.11
31+
name: python:${_VERSION}
2832
entrypoint: python
2933
args: ["-m", "pytest"]
3034
env:
@@ -44,3 +48,7 @@ availableSecrets:
4448
substitutions:
4549
_DATABASE_ID: test-database
4650
_REGION: us-central1
51+
_VERSION: "3.8"
52+
53+
options:
54+
dynamicSubstitutions: true

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ dependencies = [
1212
"cloud-sql-python-connector[asyncpg] >= 1.7.0, <2.0.0",
1313
"langchain-core>=0.1.1, <2.0.0 ",
1414
"langchain-community>=0.0.18, <0.1.0",
15-
"numpy>=1.26.4, <2.0.0",
15+
"numpy>=1.24.4, <2.0.0",
1616
"pgvector>=0.2.5, <1.0.0",
1717
"SQLAlchemy>=2.0.25, <3.0.0"
1818
]

requirements-3.8.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
google-cloud-alloydb-connector[asyncpg]==0.4.0
2+
langchain-core==0.1.25
3+
langchain-community==0.0.21
4+
numpy==1.24.4
5+
pgvector==0.2.5
6+
SQLAlchemy==2.0.25

tests/test_cloudsql_vectorstore_index.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515

1616
import os
17+
import sys
1718
import uuid
1819

1920
import pytest
@@ -53,6 +54,10 @@ def get_env_var(key: str, desc: str) -> str:
5354

5455

5556
@pytest.mark.asyncio(scope="class")
57+
@pytest.mark.skipif(
58+
sys.version_info != (3, 11),
59+
reason="To prevent index clashes only run on python3.11 or higher",
60+
)
5661
class TestIndex:
5762
@pytest.fixture(scope="module")
5863
def db_project(self) -> str:

0 commit comments

Comments
 (0)