Skip to content

Commit

Permalink
feat(ci): test against multiple versions (#45)
Browse files Browse the repository at this point in the history
* feat(ci): test against multiple versions

* Update DEVELOPER.md

* extend timeout

* set timeout

* fix table name
  • Loading branch information
averikitsch committed Mar 20, 2024
1 parent d3de139 commit 1e9c1a1
Show file tree
Hide file tree
Showing 6 changed files with 116 additions and 19 deletions.
6 changes: 5 additions & 1 deletion .github/sync-repo-settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 27,11 @@ branchProtectionRules:
requiredStatusCheckContexts:
- "cla/google"
- "lint"
- "integration-test-pr (langchain-spanner-testing)"
- "integration-test-pr-py38 (langchain-spanner-testing)"
- "integration-test-pr-py39 (langchain-spanner-testing)"
- "integration-test-pr-py310 (langchain-spanner-testing)"
- "integration-test-pr-py311 (langchain-spanner-testing)"
- "integration-test-pr-py312 (langchain-spanner-testing)"
- "conventionalcommits.org"
- "header-check"
# - Add required status checks like presubmit tests
Expand Down
81 changes: 81 additions & 0 deletions DEVELOPER.md
Original file line number Diff line number Diff line change
@@ -0,0 1,81 @@
# DEVELOPER.md

## Versioning

This library follows [Semantic Versioning](http://semver.org/).

## Processes

### Conventional Commit messages

This repository uses tool [Release Please](https://github.com/googleapis/release-please) to create GitHub and PyPi releases. It does so by parsing your
git history, looking for [Conventional Commit messages](https://www.conventionalcommits.org/),
and creating release PRs.

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)

## Testing

### Run tests locally

1. Set environment variables for `INSTANCE_ID`, `GOOGLE_DATABASE`, `PG_DATABASE`, `TABLE_NAME`

1. Run pytest to automatically run all tests:

```bash
pytest
```

### CI Platform Setup

Cloud Build is used to run tests against Google Cloud resources in test project: langchain-spanner-testing.
Each test has a corresponding Cloud Build trigger, see [all triggers][triggers].
These tests are registered as required tests in `.github/sync-repo-settings.yaml`.

#### Trigger Setup

Cloud Build triggers (for Python versions 3.8 to 3.11) were created with the following specs:

```YAML
name: integration-test-pr-py38
description: Run integration tests on PR for Python 3.8
filename: integration.cloudbuild.yaml
github:
name: langchain-google-spanner-python
owner: googleapis
pullRequest:
branch: .*
commentControl: COMMENTS_ENABLED_FOR_EXTERNAL_CONTRIBUTORS_ONLY
ignoredFiles:
- docs/**
- .kokoro/**
- .github/**
- "*.md"
substitutions:
_INSTANCE_ID: <ADD_VALUE>
_PG_DATABASE: <ADD_VALUE>
_GOOGLE_DATABASE: <ADD_VALUE>
_VERSION: "3.8"
```

Use `gcloud builds triggers import --source=trigger.yaml` create triggers via the command line

#### Project Setup

1. Create an spanner instance and database
1. Setup Cloud Build triggers (above)

#### Run tests with Cloud Build

* Run integration test:

```bash
gcloud builds submit --config integration.cloudbuild.yaml --region us-central1 --substitutions=_INSTANCE_ID=$INSTANCE_ID
```

#### Trigger

To run Cloud Build tests on GitHub from external contributors, ie RenovateBot, comment: `/gcbrun`.


[triggers]: https://console.cloud.google.com/cloud-build/triggers?e=13802955&project=langchain-spanner-testing
20 changes: 12 additions & 8 deletions integration.cloudbuild.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 14,31 @@

steps:
- id: Install dependencies
name: python:3.11
name: python:${_VERSION}
entrypoint: pip
args: ["install", "--user", "-r", "requirements.txt"]

- id: Install module (and test requirements)
name: python:3.11
name: python:${_VERSION}
entrypoint: pip
args: ["install", ".[test]", "--user"]

- id: Run integration tests
name: python:3.11
name: python:${_VERSION}
entrypoint: python
args: ["-m", "pytest"]
env:
- 'PROJECT_ID=$PROJECT_ID'
- 'INSTANCE_ID=${_INSTANCE_ID}'
- 'GOOGLE_DATABASE=${_GOOGLE_DATABASE}'
- 'PG_DATABASE=${_PG_DATABASE}'
- 'TABLE_NAME=test_$BUILD_ID'
- "PROJECT_ID=$PROJECT_ID"
- "INSTANCE_ID=${_INSTANCE_ID}"
- "GOOGLE_DATABASE=${_GOOGLE_DATABASE}"
- "PG_DATABASE=${_PG_DATABASE}"

timeout: "4800s"
substitutions:
_INSTANCE_ID: test-instance
_GOOGLE_DATABASE: test-google-db
_PG_DATABASE: test-pg-db
_VERSION: "3.8"

options:
dynamicSubstitutions: true
3 changes: 2 additions & 1 deletion tests/integration/test_spanner_chat_message_history.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 14,7 @@


import os
import uuid

import pytest # noqa
from google.cloud.spanner import Client # type: ignore
Expand All @@ -24,7 25,7 @@

project_id = os.environ["PROJECT_ID"]
instance_id = os.environ["INSTANCE_ID"]
table_name = os.environ["TABLE_NAME"].replace("-", "_")
table_name = "test_table" str(uuid.uuid4()).replace("-", "_")

OPERATION_TIMEOUT_SECONDS = 240

Expand Down
17 changes: 14 additions & 3 deletions tests/integration/test_spanner_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 13,7 @@
# limitations under the License.

import os
import uuid

import pytest
from google.cloud.spanner import Client, KeySet # type: ignore
Expand All @@ -24,7 25,7 @@
instance_id = os.environ["INSTANCE_ID"]
google_database = os.environ["GOOGLE_DATABASE"]
pg_database = os.environ["PG_DATABASE"]
table_name = os.environ["TABLE_NAME"].replace("-", "_")
table_name = "test_table" str(uuid.uuid4()).replace("-", "_")

OPERATION_TIMEOUT_SECONDS = 240

Expand Down Expand Up @@ -59,7 60,12 @@ def setup_database(self, client):
table_name,
client=client,
content_column="product_id",
metadata_columns=["product_name", "description", "price", "dummy_col"],
metadata_columns=[
"product_name",
"description",
"price",
"dummy_col",
],
)
test_documents = [
Document(
Expand Down Expand Up @@ -472,7 478,12 @@ def setup_database(self, client):
table_name,
client=client,
content_column="product_id",
metadata_columns=["product_name", "description", "price", "dummy_col"],
metadata_columns=[
"product_name",
"description",
"price",
"dummy_col",
],
)
test_documents = [
Document(
Expand Down
8 changes: 2 additions & 6 deletions tests/integration/test_spanner_vector_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 14,16 @@

import datetime
import os
import random
import uuid

import pytest
from google.cloud.spanner import Client, KeySet # type: ignore
from google.cloud.spanner import Client # type: ignore
from langchain_community.document_loaders import HNLoader
from langchain_community.embeddings import FakeEmbeddings

from langchain_google_spanner.vector_store import ( # type: ignore
DistanceStrategy,
QueryParameters,
SecondaryIndex,
SpannerVectorStore,
TableColumn,
)
Expand All @@ -34,9 32,7 @@
instance_id = os.environ["INSTANCE_ID"]
google_database = os.environ["GOOGLE_DATABASE"]
pg_database = os.environ["PG_DATABASE"]
table_name = os.environ["TABLE_NAME"].replace("-", "_") str(
random.randint(10000, 99999)
)
table_name = "test_table" str(uuid.uuid4()).replace("-", "_")


OPERATION_TIMEOUT_SECONDS = 240
Expand Down

0 comments on commit 1e9c1a1

Please sign in to comment.