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

fix(hermetic-build): obtain gapic-generator-java locally on release branch #2023

Merged
merged 9 commits into from Sep 21, 2023
3 changes: 2 additions & 1 deletion library_generation/README.md
Expand Up @@ -73,7 +73,8 @@ You can find the released version of gapic-generator-java in [maven central](htt
Use `--gapic_generator_version` to specify the value.

Note that you can specify a `SNAPSHOT` version as long as you have build the SNAPSHOT of gapic-generator-java in your maven
local repository.
local repository. If this is a release branch (i.e.
`release-please--branches--main`) it will also be obtained locally.

### protobuf_version (optional)
You can find the released version of protobuf in [GitHub](https://github.com/protocolbuffers/protobuf/releases/).
Expand Down
17 changes: 15 additions & 2 deletions library_generation/utilities.sh
Expand Up @@ -76,7 +76,9 @@ remove_grpc_version() {
download_gapic_generator_pom_parent() {
local gapic_generator_version=$1
if [ ! -f "gapic-generator-java-pom-parent-${gapic_generator_version}.pom" ]; then
if [[ "${gapic_generator_version}" == *"-SNAPSHOT" ]]; then
# release please branches will point to a non-snapshot that hasn't been
# published. We want to get the generator pom locally in this case
if [[ "${gapic_generator_version}" == *"-SNAPSHOT" ]] || [[ "$(is_release_branch)" == "true" ]]; then
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we always try to download from local maven repo first regardless of the name, and fall back to maven central if not exist? We are going to have multiple release branches in the future and this would become hard to maintain.
Similarly, we would have the same problem in the main generation script, can we try to fix it there as well @JoeWang1127 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thanks for the quick review!
I modified the generator download (pom & jar) to default to a local fetch before trying the external source

# copy a SNAPSHOT version from maven local repository.
copy_from "$HOME/.m2/repository/com/google/api/gapic-generator-java-pom-parent/${gapic_generator_version}/gapic-generator-java-pom-parent-${gapic_generator_version}.pom" \
"gapic-generator-java-pom-parent-${gapic_generator_version}.pom"
Expand Down Expand Up @@ -123,7 +125,9 @@ download_tools() {
download_generator() {
local gapic_generator_version=$1
if [ ! -f "gapic-generator-java-${gapic_generator_version}.jar" ]; then
if [[ "${gapic_generator_version}" == *"-SNAPSHOT" ]]; then
# release please branches will point to a non-snapshot that hasn't been
# published. We want to get the generator locally in this case
if [[ "${gapic_generator_version}" == *"-SNAPSHOT" ]] || [[ "$(is_release_branch)" == "true" ]]; then
# copy a SNAPSHOT version from maven local repository.
copy_from "$HOME/.m2/repository/com/google/api/gapic-generator-java/${gapic_generator_version}/gapic-generator-java-${gapic_generator_version}.jar" \
"gapic-generator-java-${gapic_generator_version}.jar"
Expand Down Expand Up @@ -212,3 +216,12 @@ detect_os_architecture() {
esac
echo "${os_architecture}"
}

# returns true if we are on a release branch
is_release_branch() {
if [ $(git rev-parse --abbrev-ref HEAD) == "release-please--branches--main" ]; then
echo "true"
return
fi
echo "false"
}