-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: populate
.repo-metadata.json
from highest version (#2890)
In this PR: - populate `.repo-metadata.json` from highest stable version of proto paths. The `.repo-metadata.json` is only generated once per library and the first item in proto paths is used, so the proto paths with the highest stable version should be the first item after sorting the proto paths in the library. The method used to compare two proto paths, `a` and `b`: 1. if both of `a` and `b` don't have a version, the one with lower depth is smaller. 2. if either `a` or `b` has a version, the one with the version is smaller. 3. if either `a` or `b` has a stable version, but not both, the one with the stable version is smaller, e.g., `google/spanner/v2` is smaller than `google/spanner/v3beta`. 4. if both `a` and `b` have a non-stable version, the one with higher version is smaller, e.g., `google/spanner/v2beta1` is smaller than `google/spanner/v2alpha2`. 5. if both `a` and `b` have a stable version, the one with lower depth is smaller, e.g., `google/spanner/v1` is smaller than `google/spanner/admin/v1`, `google/spanner/v1` is smaller than `google/spanner/admin/v2` 6. if both `a` and `b` have a stable version and the depth is the same, the one with higher version is smaller, e.g., `google/spanner/v2` is smaller than `google/spanner/v1`. Test the change: 1. build the image locally: ``` docker build -f .cloudbuild/library_generation/library_generation.Dockerfile -t local:latest . ``` 2. build the generator locally: ``` mvn -V -B -ntp clean install -DskipTests ``` 3. run the image: ``` docker run --rm -u "$(id -u):$(id -g)" -v "$(pwd):/workspace" -v "$HOME/.m2:/home/.m2" local:latest ``` Result: 1. no change in common protos 2. `transport` changed to `both` in `java-iam/.repo-metadata.json`. This is expected since the `transport` in [`google/iam/v2/BUILD.bazel`](https://github.com/googleapis/googleapis/blob/master/google/iam/v2/BUILD.bazel#L94) is `grpc+rest`. Without this change, the `transport` is parsed from `google/iam/v2/BUILD.bazel`, which doesn't have a `java_gapic_library` target, thus the value is `grpc` by default.
- Loading branch information
1 parent
9829721
commit f587541
Showing
5 changed files
with
230 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
122 changes: 122 additions & 0 deletions
122
library_generation/test/model/gapic_config_unit_tests.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
# Copyright 2024 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# https://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
import unittest | ||
|
||
from library_generation.model.gapic_config import GapicConfig | ||
|
||
|
||
class GapicConfigTest(unittest.TestCase): | ||
def test_get_version_returns_none(self): | ||
self.assertIsNone(GapicConfig(proto_path="example/dir1/dir2").get_version()) | ||
|
||
def test_get_version_returns_non_stable_version(self): | ||
self.assertEqual( | ||
"v2p2beta1", | ||
GapicConfig(proto_path="example/dir1/dir2/v2p2beta1").get_version(), | ||
) | ||
self.assertEqual( | ||
"v2beta1", | ||
GapicConfig(proto_path="example/dir1/dir2/v2beta1").get_version(), | ||
) | ||
|
||
def test_get_version_returns_stable_version(self): | ||
self.assertEqual( | ||
"v20", | ||
GapicConfig(proto_path="example/dir1/dir2/v20").get_version(), | ||
) | ||
|
||
def test_is_stable_with_no_version_returns_false(self): | ||
self.assertFalse( | ||
GapicConfig(proto_path="example/dir1/dir2/non_version").is_stable(), | ||
) | ||
|
||
def test_is_stable_with_non_stable_version_returns_false(self): | ||
self.assertFalse( | ||
GapicConfig(proto_path="example/dir1/dir2/v20alpha").is_stable(), | ||
) | ||
self.assertFalse( | ||
GapicConfig(proto_path="example/dir1/dir2/v20beta2").is_stable(), | ||
) | ||
|
||
def test_is_stable_with_stable_version_returns_true(self): | ||
self.assertTrue( | ||
GapicConfig(proto_path="example/dir1/dir2/v30").is_stable(), | ||
) | ||
|
||
def test_compare_configs_without_a_version(self): | ||
config_len_3 = GapicConfig(proto_path="example/dir1/dir2") | ||
config_len_4 = GapicConfig(proto_path="example/dir1/dir2/dir3") | ||
self.assertLess( | ||
config_len_3, | ||
config_len_4, | ||
"config_len_3 should be smaller since it has a lower depth.", | ||
) | ||
|
||
def test_compare_configs_only_one_has_a_stable_version(self): | ||
versioned_config = GapicConfig(proto_path="example/dir1/dir2/dir3/dir4/v1") | ||
non_versioned_config = GapicConfig(proto_path="example/dir1/dir2/dir3") | ||
self.assertLess( | ||
versioned_config, | ||
non_versioned_config, | ||
"versioned_config should be smaller since it has a version.", | ||
) | ||
|
||
def test_compare_configs_only_one_has_a_non_stable_version(self): | ||
non_stable_versioned_config = GapicConfig( | ||
proto_path="example/dir1/dir2/dir3/dir4/v1beta" | ||
) | ||
non_versioned_config = GapicConfig(proto_path="example/dir1/dir2/dir3") | ||
self.assertLess( | ||
non_stable_versioned_config, | ||
non_versioned_config, | ||
"non_stable_versioned_config should be smaller since it has a version.", | ||
) | ||
|
||
def test_compare_configs_one_has_non_stable_and_one_has_stable_version(self): | ||
stable_versioned_config = GapicConfig( | ||
proto_path="example/dir1/dir2/dir3/dir4/v1" | ||
) | ||
non_stable_versioned_config = GapicConfig(proto_path="example/dir1/dir2/v2beta") | ||
self.assertLess( | ||
stable_versioned_config, | ||
non_stable_versioned_config, | ||
"stable_versioned_config should be smaller since it has a stable version.", | ||
) | ||
|
||
def test_compare_configs_two_have_non_stable_version(self): | ||
v3p2beta = GapicConfig(proto_path="example/dir1/dir2/dir3/dir4/v3p2beta") | ||
v2p4beta = GapicConfig(proto_path="example/dir1/dir2/v2p4beta") | ||
self.assertLess( | ||
v3p2beta, | ||
v2p4beta, | ||
"v3p2beta should be smaller since it has a higher version.", | ||
) | ||
|
||
def test_compare_configs_two_have_stable_version_different_depth(self): | ||
v3 = GapicConfig(proto_path="example/dir1/dir2/v3") | ||
v4 = GapicConfig(proto_path="example/dir1/dir2/dir3/dir4/v4") | ||
self.assertLess( | ||
v3, | ||
v4, | ||
"v3 should be smaller since it has lower depth", | ||
) | ||
|
||
def test_compare_configs_two_have_stable_version_same_depth(self): | ||
v4 = GapicConfig(proto_path="example/dir1/dir2/v4") | ||
v3 = GapicConfig(proto_path="example/dir1/dir2/v3") | ||
self.assertLess( | ||
v4, | ||
v3, | ||
"v4 should be smaller since it has a higher version", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters