Skip to content

chore: initial migration of spring generator code #1686

Merged
emmileaf merged 37 commits intomainfrom
generator-migration-test
May 3, 2023
Merged

chore: initial migration of spring generator code #1686
emmileaf merged 37 commits intomainfrom
generator-migration-test

Conversation

@emmileaf
Copy link
Copy Markdown
Contributor

@emmileaf emmileaf commented Mar 30, 2023

This PR contains an initial migration of generator code from gapic-generator-java (see googleapis/sdk-platform-java#1580 for source) to the spring-cloud-gcp repo (alongside scripts and generated code).

End-to-end workflow can be verified from this PR by creating a branch with libraries-bom version change and running:

gh workflow run .github/workflows/generateAutoConfigs.yaml --ref generator-migration-test
-f branch_name=<test-branch-name> -f forked_repo=none

For reviewers:
Please see #1686 (comment) for an outline of file roles (migrated content vs. original changes introduced by the migration), to help with navigating the PR diff.


High-level migration approach:

  1. Set up spring-cloud-generator as a Bazel module (name: spring_cloud_generator, with BUILD.bazel and WORKSPACE)
  2. Set up spring-cloud-generator as a Maven submodule in spring-cloud-gcp (artifact name: com.google.api.spring-cloud-generator, with pom.xml)
    • Version is aligned with spring-cloud-gcp, and has dependency on published gapic-generator-java jar
    • Not intended for release; updated script to install a local SNAPSHOT version of this module for use in generation
  3. Adjustments to (and restructuring of) scripts and github workflow to make local googleapis workspace modifications, trigger Bazel targets using the migrated generator, and process generated code into spring-cloud-previews

Other smaller changes:

  • Updated perl script replacement logic in scripts with buildozer for better readability
  • Removed outdated library_list.txt, and added step in gh action to log contents after generating this file
  • Updated license headers formatting (// => /*) to align with spring-cloud-gcp checks

Planned enhancements (not included in this PR):

From autoconfig-gen-draft2 branch, commit dcd082333eca7938e627855b294db995da06ee11
* Temporary assessment of scope of test-related code duplication
* Has mvn test -DupdateUnitGoldens working in maven module setup
@emmileaf emmileaf changed the title [do not merge] testing spring generator migration setup chore: initial migration of spring generator code Apr 13, 2023
Comment thread .github/workflows/testGenerateAutoConfigs.yaml Outdated
Comment thread spring-cloud-generator/scripts/generate-all.sh
Comment thread spring-cloud-generator/scripts/setup-googleapis-rules.sh
Comment thread spring-cloud-generator/pom.xml Outdated
@emmileaf emmileaf marked this pull request as ready for review April 13, 2023 14:38
@emmileaf emmileaf requested review from blakeli0 and meltsufin April 20, 2023 14:22
Comment thread spring-cloud-generator/WORKSPACE Outdated


# Spring generator
_spring_cloud_generator_version = "4.1.4-SNAPSHOT" # {x-version-update:spring-cloud-gcp:current}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think this version needs to be in sync with the latest spring-cloud-gcp version? I'm actually not sure how it worked with the wrong version.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

You're right - thanks for catching this! I'm also confused to how this slipped past and kept working without the version being in sync - will take a look.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ah, this may have worked with the incorrect version because the setup here is redundant/unused in the generation process. I've trimmed away most of this file in 87df937, with a quick explanation below:

When initially following the gapic-generator-java approach, I was under the impression that the generator WORKSPACE needed a maven_install() for the end-to-end generation, and followed most of this setup.

On a second look at gapic-generator-java/WORKSPACE, I realize that it's fetching a snapshot jar, so probably just to allow for bazel invocations from within the repo (for integration tests?), while googleapis/WORKSPACE fetches a published version. In the spring codegen process, because we are not publishing the generator, the local copy of googleapis/WORKSPACE is already being modified with a maven_install() block to fetch the locally built generator as part of scripts. The version was correct there, which is why the generation workflow had worked.

This setup may be needed again when adding integration tests for the spring generator, but I will remove it for now given the additional version management.

@@ -0,0 +1,146 @@
# Copyright 2022 Google LLC
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

New files in this repo need to be have 2023 in the copyright header

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Also the copyright format is different from other files in this repo

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Per discussion - updated license header year to 2023 (eefaeb6) for migrated files that previously lived on branch, but not published to gapic-generator-java main.

* Not needed in generation workflow since it already modifies googleapis WORKSPACE with maven install of snapshot jar
* gapic-generator-java setup uses this for running integration tests within the repo
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented May 2, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 86 Code Smells

88.8% 88.8% Coverage
0.0% 0.0% Duplication

@emmileaf emmileaf requested a review from blakeli0 May 2, 2023 23:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants