Skip to content

Commit

Permalink
Add lint, build, and test commands to justfile, add fmt and clippy …
Browse files Browse the repository at this point in the history
…to CI workflow (#59)

## Problem
@haruska had some good feedback around adding explicit `build`, `test`,
and `lint` commands to the `justfile` in the repo. Currently there are
only commands for dealing with code generation which is a little
confusing.

Additionally, we haven't run `cargo fmt` and `cargo clippy` on the
codebase yet, and have nothing enforcing its use.

## Solution

- Refactor`justfile`: move all code generation under `gen-*` commands,
add `build`, `test`, `lint`, and `update` commands to the file.
- Update `ci.yaml` workflow to support both fmt and clippy. Reject if
running either leads to issues.
- Code changes for fmt and clippy.

**Note:** At the moment I've added
`#![allow(clippy::enum_variant_names)]` and
`#![allow(clippy::empty_docs)]` to the `src/openapi/mod.rs` file. There
were some clippy issues in the generated code, and since we still need
to refactor the entire generation flow in this repo, I just stuck the
allow tags on top for now.

## Type of Change
- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- [ ] This change requires a documentation update
- [X] Infrastructure change (CI configs, etc)
- [ ] Non-code change (docs, etc)
- [ ] None of the above: (explain here)

## Test Plan
Make sure CI passes.
  • Loading branch information
austin-denoble authored Oct 1, 2024
1 parent 2415031 commit 2ccc8c1
Show file tree
Hide file tree
Showing 39 changed files with 466 additions and 409 deletions.
79 changes: 50 additions & 29 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -1,34 +1,55 @@
name: CI

on:
pull_request: {}
push:
branches:
- main
workflow_dispatch: {}
pull_request: {}
push:
branches:
- main
workflow_dispatch: {}

jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest]
rust: [stable]
steps:
- uses: actions/checkout@v4
- uses: hecrj/setup-rust-action@v2
with:
rust-version: ${{ matrix.rust }}
- name: Install protoc
uses: arduino/setup-protoc@v3
- name: Build SDK
run: cargo build
- name: Build documentation
run: cargo doc --no-deps
- name: Run tests
env:
PINECONE_API_KEY: ${{ secrets.PINECONE_API_KEY }}
SERVERLESS_INDEX_NAME: ${{ secrets.SERVERLESS_INDEX_NAME }}
POD_INDEX_NAME: ${{ secrets.POD_INDEX_NAME }}
COLLECTION_NAME: ${{ secrets.COLLECTION_NAME }}
run: cargo test --verbose
test:
name: Test
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest]
rust: [stable]
steps:
- uses: actions/checkout@v4
- uses: hecrj/setup-rust-action@v2
with:
rust-version: ${{ matrix.rust }}
- name: Install protoc
uses: arduino/setup-protoc@v3
- name: Build SDK
run: cargo build
- name: Build documentation
run: cargo doc --no-deps
- name: Run tests
env:
PINECONE_API_KEY: ${{ secrets.PINECONE_API_KEY }}
SERVERLESS_INDEX_NAME: ${{ secrets.SERVERLESS_INDEX_NAME }}
POD_INDEX_NAME: ${{ secrets.POD_INDEX_NAME }}
COLLECTION_NAME: ${{ secrets.COLLECTION_NAME }}
run: cargo test --verbose
fmt:
name: Rustfmt
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt
- name: Enforce formatting
run: cargo fmt --check
clippy:
name: Clippy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
components: clippy
- name: Run clippy
run: cargo clippy -- -D warnings
33 changes: 25 additions & 8 deletions justfile
Original file line number Diff line number Diff line change
@@ -1,22 +1,39 @@
api_version := "2024-07"

# Generate version file
generate-version:
echo "/// Pinecone API version\npub const API_VERSION: &str = \"{{api_version}}\";" > src/version.rs
# Lint files and run tests with optional specific test cases
test *tests: lint
# Runs the specified tests, or all tests if none specified
cargo test {{tests}} --verbose

# Update git submodules recursively
update:
git submodule update --init --recursive

# Run linting tools (cargo fmt and clippy)
lint:
cargo fmt && cargo clippy

# Build the OpenAPI and Protobuf definitions in `codegen/apis`
build-apis:
# Run cargo build
build:
cargo build

# Build the OpenAPI and Protobuf definitions in the `codegen/apis` submodule
gen-build-submodule-apis:
cd codegen/apis && just build

# Generate the control plane OpenAPI code based on the yaml files in `codegen/apis/_build`
build-openapi: build-apis generate-version
gen-openapi: gen-build-submodule-apis gen-version_file
./codegen/build-oas.sh {{api_version}}

# Generate the data plane protobuf code based on the yaml files in `codegen/apis/_build`
build-proto: build-apis generate-version
gen-proto: gen-build-submodule-apis gen-version_file
./codegen/build-proto.sh {{api_version}}

# Generate all OpenAPI and protobuf code
build-client: build-apis generate-version
gen-client: gen-build-submodule-apis gen-version_file
./codegen/build-oas.sh {{api_version}}
./codegen/build-proto.sh {{api_version}}

# Generate version file
gen-version_file:
echo "/// Pinecone API version\npub const API_VERSION: &str = \"{{api_version}}\";" > src/version.rs
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//! # Pinecone Rust SDK
//!
//! > ⚠️ **Warning:** This SDK is still in an alpha state. While it is mostly built out and functional,
//! it may undergo changes as we continue to improve the UX. Please try it out and give us your feedback,
//! but be aware that updates may introduce breaking changes.
//! > it may undergo changes as we continue to improve the UX. Please try it out and give us your feedback,
//! > but be aware that updates may introduce breaking changes.
//!
//! `pinecone-sdk` provides an interface for working with Pinecone services such as the Database and Inference APIs.
//! See [docs.pinecone.io](https://docs.pinecone.io/) for more information.
Expand Down
4 changes: 0 additions & 4 deletions src/openapi/apis/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
* Generated by: https://openapi-generator.tech
*/



#[derive(Debug, Clone)]
pub struct Configuration {
pub base_path: String,
Expand All @@ -30,7 +28,6 @@ pub struct ApiKey {
pub key: String,
}


impl Configuration {
pub fn new() -> Configuration {
Configuration::default()
Expand All @@ -47,7 +44,6 @@ impl Default for Configuration {
oauth_access_token: None,
bearer_access_token: None,
api_key: None,

}
}
}
25 changes: 15 additions & 10 deletions src/openapi/apis/inference_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,10 @@
* Generated by: https://openapi-generator.tech
*/


use super::{configuration, Error};
use crate::openapi::{apis::ResponseContent, models};
use reqwest;
use serde::{Deserialize, Serialize};
use crate::openapi::{apis::ResponseContent, models};
use super::{Error, configuration};


/// struct for typed errors of method [`embed`]
#[derive(Debug, Clone, Serialize, Deserialize)]
Expand All @@ -25,18 +23,22 @@ pub enum EmbedError {
UnknownValue(serde_json::Value),
}


/// Generate embeddings for input data
pub async fn embed(configuration: &configuration::Configuration, embed_request: Option<models::EmbedRequest>) -> Result<models::EmbeddingsList, Error<EmbedError>> {
pub async fn embed(
configuration: &configuration::Configuration,
embed_request: Option<models::EmbedRequest>,
) -> Result<models::EmbeddingsList, Error<EmbedError>> {
let local_var_configuration = configuration;

let local_var_client = &local_var_configuration.client;

let local_var_uri_str = format!("{}/embed", local_var_configuration.base_path);
let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
let mut local_var_req_builder =
local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());

if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
local_var_req_builder =
local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
}
if let Some(ref local_var_apikey) = local_var_configuration.api_key {
let local_var_key = local_var_apikey.key.clone();
Expand All @@ -58,8 +60,11 @@ pub async fn embed(configuration: &configuration::Configuration, embed_request:
serde_json::from_str(&local_var_content).map_err(Error::from)
} else {
let local_var_entity: Option<EmbedError> = serde_json::from_str(&local_var_content).ok();
let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
let local_var_error = ResponseContent {
status: local_var_status,
content: local_var_content,
entity: local_var_entity,
};
Err(Error::ResponseError(local_var_error))
}
}

Loading

0 comments on commit 2ccc8c1

Please sign in to comment.