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

Add codegen/build-clients.sh script, update codegen/apis submodule #49

Merged
merged 8 commits into from
Jul 23, 2024
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
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
PINECONE_API_KEY="<Project API Key>"
TEST_POD_INDEX_NAME="<Pod based Index name>"
TEST_PODS_INDEX_NAME="<Pod based Index name>"
TEST_SERVERLESS_INDEX_NAME="<Serverless based Index name>"
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ jobs:
- name: Run tests
run: go test ./pinecone
env:
TEST_POD_INDEX_NAME: ${{ secrets.TEST_POD_INDEX_NAME }}
TEST_PODS_INDEX_NAME: ${{ secrets.TEST_PODS_INDEX_NAME }}
TEST_SERVERLESS_INDEX_NAME: ${{ secrets.TEST_SERVERLESS_INDEX_NAME }}
PINECONE_API_KEY: ${{ secrets.API_KEY }}
6 changes: 3 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[submodule "apis"]
path = apis
url = [email protected]:pinecone-io/go-apis.git
[submodule "codegen/apis"]
path = codegen/apis
url = [email protected]:pinecone-io/apis.git
Comment on lines +1 to +3
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moving to new submodule location, and swapping the underlying repo.

1 change: 0 additions & 1 deletion apis
Submodule apis deleted from 3a31d3
1 change: 1 addition & 0 deletions codegen/apis
Submodule apis added at 062b11
81 changes: 81 additions & 0 deletions codegen/build-clients.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#!/bin/bash
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was modeling this after the work @jhamon had done in other repos, but this diverges a bit in that I'm not using a docker image, and we're doing both OAS and proto files in here.

Let me know if this doesn't make sense - or any other feedback. I didn't want to make too many changes to the dependencies we were using to generate code.


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"
version_file="internal/gen/api_version.go"

update_apis_repo() {
echo "Updating apis repo"
pushd codegen/apis
git fetch
git checkout main
git pull
just build
popd
}

verify_spec_version() {
local version=$1
echo "Verifying spec version has been provided: $version"
if [ -z "$version" ]; then
echo "Version is required"
exit 1
fi
Comment on lines +25 to +29
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I should maybe do some actual checking against the folder names under /apis/_build/ maybe. 🤔

}

generate_oas_client() {
oas_file="codegen/apis/_build/${version}/control_${version}.oas.yaml"

oapi-codegen --package=control \
--generate types,client \
"${oas_file}" > "${control_destination}/control_plane.oas.go"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

There's a version in the proto / data plane output, maybe should have that here too.

}

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

protoc --experimental_allow_proto3_optional \
--proto_path=codegen/apis/vendor/protos \
--proto_path=codegen/apis/_build/${version} \
--go_opt=module="github.com/pinecone-io/go-pinecone" \
--go-grpc_opt=module="github.com/pinecone-io/go-pinecone" \
--go_out=. \
--go-grpc_out=. \
"${proto_file}"
}

generate_version_file() {
echo "Generating version file"
cat > "${version_file}" <<EOL
// Code generated by build-clients.sh - DO NOT EDIT.
package gen

const PineconeApiVersion = "${version}"
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 data plane client code
rm -rf "${data_destination}"
mkdir -p "${data_destination}"

generate_proto_client

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

generate_version_file
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ module github.com/pinecone-io/go-pinecone
go 1.21

require (
github.com/golang/protobuf v1.5.4
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I ran go mod tidy locally and this was removed... I think the google.golang.org/protobuf v1.34.1 below covers it?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, we should prefer google.golang.org according to https://protobuf.dev/reference/go/faq/.

github.com/google/go-cmp v0.6.0
github.com/google/uuid v1.6.0
github.com/oapi-codegen/runtime v1.1.1
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ github.com/bmatcuk/doublestar v1.1.1/go.mod h1:UD6OnuiIn0yFxxA2le/rnRU1G4RaI4UvF
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
Expand Down
4 changes: 4 additions & 0 deletions internal/gen/api_version.go

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

Loading