-
Notifications
You must be signed in to change notification settings - Fork 1.1k
ci(showcase): replace hermetic build golden tests with Librarian #13569
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
Merged
+81
−108
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
26319ca
update generate_showcase.sh to use librarian
zhumin8 0379c8e
update workflow and readme
zhumin8 accd371
simplify scripts by removing flag
zhumin8 a77c2eb
fix verify.sh
zhumin8 70a8f93
Merge branch 'main' into ci-showcase-librarian
zhumin8 f497c9e
use java 17 for code generation
zhumin8 81b12c6
restrict pip config to active virtual environment
zhumin8 a4e488e
check all java-showcase in test and clarify need clean git tree in RE…
zhumin8 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,96 +1,19 @@ | ||
| #!/bin/bash | ||
| # Generates the showcase library using the docker image, which is built | ||
| # from the current state of the repo in order to test local changes. | ||
| # Generates the showcase library using librarian. | ||
| set -ex | ||
|
|
||
| echo "******** Generating Showcase ********" | ||
|
|
||
| trap cleanup ERR | ||
|
|
||
| readonly ROOT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )/../.." | ||
| pushd "${ROOT_DIR}" | ||
| source "${ROOT_DIR}/java-showcase/scripts/showcase_utilities.sh" | ||
|
|
||
| cleanup() { | ||
| if [[ -z "${api_def_dir}" ]]; then | ||
| rm -rf "${api_def_dir}" | ||
| fi | ||
| if [[ -z "${showcase_def_dir}" ]]; then | ||
| rm -rf "${showcase_def_dir}" | ||
| fi | ||
| } | ||
|
|
||
| while [[ $# -gt 0 ]]; do | ||
| key="$1" | ||
| case "${key}" in | ||
| --replace) | ||
| replace="$2" | ||
| shift | ||
| ;; | ||
| *) | ||
| echo "Invalid option: [$1]" | ||
| exit 1 | ||
| ;; | ||
| esac | ||
| shift | ||
| done | ||
|
|
||
| if [ -z "${replace}" ]; then | ||
| replace="false" | ||
| fi | ||
|
|
||
|
|
||
| # download api definitions from googleapis repository | ||
| googleapis_commitish=$(grep googleapis_commitish generation_config.yaml | cut -d ":" -f 2 | xargs) | ||
| api_def_dir=$(mktemp -d) | ||
| git clone https://github.com/googleapis/googleapis.git "${api_def_dir}" | ||
|
|
||
| pushd "${api_def_dir}" | ||
| git checkout "${googleapis_commitish}" | ||
| # for local setups, we avoid permission issues when the docker image | ||
| # performs version-dependent operations. | ||
| rm -rf ".git/" | ||
| popd | ||
|
|
||
| append_showcase_to_api_defs "${api_def_dir}" | ||
|
|
||
| if [[ -f "image-id" ]]; then | ||
| echo "image already exists:" | ||
| cat image-id | ||
| else | ||
| echo "building docker image" | ||
| DOCKER_BUILDKIT=1 docker build --file sdk-platform-java/.cloudbuild/library_generation/library_generation.Dockerfile --iidfile image-id . | ||
| fi | ||
|
|
||
| if [[ "${replace}" == "true" ]]; then | ||
| generated_files_dir="${ROOT_DIR}" | ||
| else | ||
| export generated_files_dir=$(mktemp -d) | ||
| # here we store the generated library location for upstream scripts to use | ||
| # it. | ||
| echo "${generated_files_dir}/java-showcase" > "${ROOT_DIR}/generated-showcase-location" | ||
| # we prepare the temp folder with the minimal setup to perform an incremental | ||
| # generation. | ||
| pushd "${ROOT_DIR}" | ||
| cp -r generation_config.yaml java-showcase/ versions.txt "${generated_files_dir}" | ||
| popd #ROOT_DIR | ||
| fi | ||
| # Export PYTHONPATH so that owlbot.py scripts run by Librarian | ||
| # can resolve local synthtool under the hermetic build directory. | ||
| export PYTHONPATH="${ROOT_DIR}/sdk-platform-java/hermetic_build/library_generation/owlbot" | ||
| cd "${ROOT_DIR}" | ||
|
|
||
| pushd sdk-platform-java | ||
| GENERATOR_VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout -pl gapic-generator-java) | ||
| popd | ||
| readonly LIBRARIAN_VER=$(go run github.com/googleapis/librarian/cmd/librarian@latest config get version) | ||
| readonly LIBRARIAN_CMD="go run github.com/googleapis/librarian/cmd/librarian@${LIBRARIAN_VER}" | ||
|
zhumin8 marked this conversation as resolved.
|
||
|
|
||
| echo "generating showcase" | ||
| workspace_name="/workspace" | ||
| docker run \ | ||
| --rm \ | ||
| -u "$(id -u):$(id -g)" \ | ||
| -v "${generated_files_dir}:${workspace_name}" \ | ||
| -v "${api_def_dir}:${workspace_name}/googleapis" \ | ||
| -e GENERATOR_VERSION="${GENERATOR_VERSION}" \ | ||
| "$(cat image-id)" \ | ||
| --generation-config-path="${workspace_name}/generation_config.yaml" \ | ||
| --library-names="showcase" \ | ||
| --api-definitions-path="${workspace_name}/googleapis" | ||
| echo "generating showcase in place" | ||
| $LIBRARIAN_CMD generate showcase | ||
|
|
||
| echo "generated showcase library in ${generated_files_dir}" | ||
| echo "generated showcase library" | ||
This file contains hidden or 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 |
|---|---|---|
| @@ -1,21 +1,18 @@ | ||
| #!/bin/sh | ||
| # This script generates showcase in a temporary/untracked folder and compares | ||
| # its contents with the actual showcase libraries. | ||
| #!/bin/bash | ||
| # This script generates showcase in place and checks for git diffs to verify. | ||
|
|
||
| echo "******** Verifying Showcase ********" | ||
|
|
||
| set -oxe | ||
| set -ex | ||
| readonly SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) | ||
| readonly ROOT_DIR="${SCRIPT_DIR}/../.." | ||
| source "${SCRIPT_DIR}/showcase_utilities.sh" | ||
| readonly SHOWCASE_DIR="${SCRIPT_DIR}/.." | ||
| # generate sources in place | ||
| bash "${SCRIPT_DIR}/generate_showcase.sh" | ||
|
|
||
| # generate sources | ||
| bash "${SCRIPT_DIR}/generate_showcase.sh" --replace "false" | ||
|
|
||
| generated_library_location=$(cat "${ROOT_DIR}/generated-showcase-location") | ||
|
|
||
| # compare library | ||
| diff -ru "${SHOWCASE_DIR}/" "${generated_library_location}" | ||
|
|
||
| cleanup $SCRIPT_DIR | ||
| # check if there are changes in java-showcase directory | ||
| if [ -n "$(git status --porcelain ${SHOWCASE_DIR})" ]; then | ||
| git diff ${SHOWCASE_DIR} | ||
| echo "Error: Showcase generated files are out of sync. Please run 'mvn compile -P update' inside java-showcase to update them." | ||
| exit 1 | ||
| fi |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.