Skip to content

Commit

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

* Update sync-repo-settings.yaml

* Update sync-repo-settings.yaml

* Update test_cloudsql_vectorstore_index.py
  • Loading branch information
averikitsch committed Mar 15, 2024
1 parent e143e14 commit a3f410d
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/header-checker-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ ignoreFiles:
- ".github/sync-repo-settings.yaml"
- ".kokoro/**"
- "**/requirements.txt"
- "**/requirements-test.txt"
- "**/requirements*.txt"
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"
- "pg-integration-test-pr (langchain-cloud-sql-testing)"
- "pg-integration-test-pr-py38 (langchain-cloud-sql-testing)"
- "pg-integration-test-pr-py39 (langchain-cloud-sql-testing)"
- "pg-integration-test-pr-py310 (langchain-cloud-sql-testing)"
- "pg-integration-test-pr-py311 (langchain-cloud-sql-testing)"
- "pg-integration-test-pr-py312 (langchain-cloud-sql-testing)"
- "conventionalcommits.org"
- "header-check"
# - Add required status checks like presubmit tests
Expand Down
82 changes: 82 additions & 0 deletions DEVELOPER.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# 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`, `DATABASE_ID`, `REGION`, `DB_USER`, `DB_PASSWORD`

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-alloydb-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: pg-integration-test-pr-py38
description: Run integration tests on PR for Python 3.8
filename: integration.cloudbuild.yaml
github:
name: langchain-google-alloydb-pg-python
owner: googleapis
pullRequest:
branch: .*
commentControl: COMMENTS_ENABLED_FOR_EXTERNAL_CONTRIBUTORS_ONLY
ignoredFiles:
- docs/**
- .kokoro/**
- .github/**
- "*.md"
substitutions:
_CLUSTER_ID: <ADD_VALUE>
_DATABASE_ID: <ADD_VALUE>
_INSTANCE_ID: <ADD_VALUE>
_REGION: us-central1
_VERSION: "3.8"
```

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

#### Project Setup

1. Create an Cloud SQL for PostgreSQL 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,_DATABASE_ID=$DATABASE_ID,_REGION=$REGION
```

#### 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-cloud-sql-testing
18 changes: 13 additions & 5 deletions integration.cloudbuild.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,21 @@

steps:
- id: Install dependencies
name: python:3.11
entrypoint: pip
args: ["install", "--user", "-r", "requirements.txt"]
name: python:${_VERSION}
entrypoint: /bin/bash
args:
- -c
- |
if [[ $_VERSION == "3.8" ]]; then version="-3.8"; fi
pip install --user -r requirements${version}.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:
Expand All @@ -44,3 +48,7 @@ availableSecrets:
substitutions:
_DATABASE_ID: test-database
_REGION: us-central1
_VERSION: "3.8"

options:
dynamicSubstitutions: true
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ dependencies = [
"cloud-sql-python-connector[asyncpg] >= 1.7.0, <2.0.0",
"langchain-core>=0.1.1, <2.0.0 ",
"langchain-community>=0.0.18, <0.1.0",
"numpy>=1.26.4, <2.0.0",
"numpy>=1.24.4, <2.0.0",
"pgvector>=0.2.5, <1.0.0",
"SQLAlchemy>=2.0.25, <3.0.0"
]
Expand Down
6 changes: 6 additions & 0 deletions requirements-3.8.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
google-cloud-alloydb-connector[asyncpg]==0.4.0
langchain-core==0.1.25
langchain-community==0.0.21
numpy==1.24.4
pgvector==0.2.5
SQLAlchemy==2.0.25
5 changes: 5 additions & 0 deletions tests/test_cloudsql_vectorstore_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@


import os
import sys
import uuid

import pytest
Expand Down Expand Up @@ -53,6 +54,10 @@ def get_env_var(key: str, desc: str) -> str:


@pytest.mark.asyncio(scope="class")
@pytest.mark.skipif(
sys.version_info != (3, 11),
reason="To prevent index clashes only run on python3.11 or higher",
)
class TestIndex:
@pytest.fixture(scope="module")
def db_project(self) -> str:
Expand Down

0 comments on commit a3f410d

Please sign in to comment.