Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor /codegen/build-clients.sh to support new apis structure, regenerate for 2024-10 #76

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
name: ci
on:
pull_request:
branches:
- main
pull_request: {}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ci workflow wasn't running because we only run against main and I'm working againrelease-candidate/2024-10 here.


jobs:
build:
Expand Down
2 changes: 1 addition & 1 deletion codegen/apis
Submodule apis updated from 062b11 to 3b7369
71 changes: 51 additions & 20 deletions codegen/build-clients.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
#!/bin/bash

set -eux -o pipefail

version=$1 # e.g. 2024-07

# data_destination must align with the option go_package:
# https://github.com/pinecone-io/apis/blob/e9b47c76f649656002f4911946ca6c4c4a6f04fc/src/release/data/data.proto#L3
data_destination="internal/gen/data"
control_destination="internal/gen/control"
# modules
db_control_module="db_control"
db_data_module="db_data"
inference_module="inference"

# generated output destination paths
# db_data_destination must align with the option go_package in the proto file:
# https://github.com/pinecone-io/apis/blob/d1d005e75cc9fe9a5c486ef9218fe87b57765961/src/release/db/data/data.proto#L3
db_data_destination="internal/gen/data"
db_control_destination="internal/gen/${db_control_module}"
inference_destination="internal/gen/${inference_module}"

# version file
version_file="internal/gen/api_version.go"
# generated oas files
db_control_oas_file="${db_control_destination}/${db_control_module}_${version}.oas.go"
inference_oas_file="${inference_destination}/${inference_module}_${version}.oas.go"

set -eux -o pipefail

update_apis_repo() {
echo "Updating apis repo"
Expand All @@ -27,18 +39,35 @@ verify_spec_version() {
echo "Version is required"
exit 1
fi

verify_directory_exists "codegen/apis/_build/${version}"
}

verify_directory_exists() {
local directory=$1
if [ ! -d "$directory" ]; then
echo "Directory does not exist at $directory"
exit 1
fi
}

generate_oas_client() {
oas_file="codegen/apis/_build/${version}/control_${version}.oas.yaml"
local module=$1
local destination=$2

# source oas file for module and version
oas_file="codegen/apis/_build/${version}/${module}_${version}.oas.yaml"

oapi-codegen --package=control \
oapi-codegen --package=${module} \
--generate types,client \
"${oas_file}" > "${control_destination}/control_plane.oas.go"
"${oas_file}" > "${destination}"
}

generate_proto_client() {
proto_file="codegen/apis/_build/${version}/data_${version}.proto"
local module=$1

# source proto file for module and version
proto_file="codegen/apis/_build/${version}/${module}_${version}.proto"

protoc --experimental_allow_proto3_optional \
--proto_path=codegen/apis/vendor/protos \
Expand All @@ -63,19 +92,21 @@ EOL
update_apis_repo
verify_spec_version $version

# Generate control plane client code
rm -rf "${control_destination}"
mkdir -p "${control_destination}"

generate_oas_client
# Generate db_control oas client
rm -rf "${db_control_destination}"
mkdir -p "${db_control_destination}"
generate_oas_client $db_control_module $db_control_oas_file

# Generate data plane client code
rm -rf "${data_destination}"
mkdir -p "${data_destination}"
# Generate inference oas client
rm -rf "${inference_destination}"
mkdir -p "${inference_destination}"
generate_oas_client $inference_module $inference_oas_file

generate_proto_client
# Generate db_data proto client
rm -rf "${db_data_destination}"
mkdir -p "${db_data_destination}"
generate_proto_client $db_data_module

# Generate version file
rm -rf "${version_file}"

generate_version_file
2 changes: 1 addition & 1 deletion internal/gen/api_version.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

204 changes: 2 additions & 202 deletions internal/gen/control/control_plane.oas.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading