Skip to content
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
33 changes: 33 additions & 0 deletions .github/workflows/showcase.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,46 @@ jobs:
env:
BUILD_SUBDIR: sdk-platform-java
JOB_TYPE: install
- uses: actions/setup-go@v5
with:
go-version: 'stable'
- name: Install protoc
run: |
set -e
VERSION="33.2"
Comment thread
zhumin8 marked this conversation as resolved.
curl -fsSL --retry 5 --retry-delay 15 -o /tmp/protoc.zip "https://github.com/protocolbuffers/protobuf/releases/download/v$VERSION/protoc-$VERSION-linux-x86_64.zip"
cd /usr/local
sudo unzip -o /tmp/protoc.zip
protoc --version
- uses: actions/setup-python@v5
with:
python-version: "3.12"
cache: 'pip'
- name: Install Librarian and tools
env:
PYTHONPATH: ${{ github.workspace }}/sdk-platform-java/hermetic_build/library_generation/owlbot
run: |
V=$(go run github.com/googleapis/librarian/cmd/librarian@latest config get version)
echo "Installing librarian version $V"
go install github.com/googleapis/librarian/cmd/librarian@$V
librarian install
- name: Setup Java 17 for Golden Tests
uses: actions/setup-java@v4
with:
java-version: 17
distribution: temurin
- name: Showcase golden tests
working-directory: java-showcase
run: |
mvn test \
-P enable-golden-tests \
--batch-mode \
--no-transfer-progress
- name: Restore Matrix Java
Comment thread
zhumin8 marked this conversation as resolved.
uses: actions/setup-java@v4
with:
java-version: ${{ matrix.java }}
distribution: temurin
- name: Parse showcase version
working-directory: java-showcase/gapic-showcase
run: echo "SHOWCASE_VERSION=$(mvn help:evaluate -Dexpression=gapic-showcase.version -q -DforceStdout)" >> "$GITHUB_ENV"
Expand Down
32 changes: 27 additions & 5 deletions java-showcase/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ the Showcase API which can communicate with a local Showcase server to perform i

## Requirements

* Install [Go](https://go.dev) in your `PATH`.
* Install [Go](https://go.dev) in your `PATH` (version 1.20 or later).
* Install the [protoc](https://github.com/protocolbuffers/protobuf/releases) compiler in your `PATH`.

## Installing the Server

Expand Down Expand Up @@ -73,19 +74,40 @@ mvn verify -P enable-integration-tests

## Running the Golden tests

**NOTE** This requires Docker to be installed in your machine.
Open a new terminal window in the root project directory.
This verify check compares the current checked-in files in `java-showcase` against a newly generated client.

### Prerequisites (One-time Setup)
Make sure you have **Go** and **protoc** installed and available in your `PATH` (see the [Requirements](#requirements) section), then run the following setup steps from the repository root:

```shell
# Setup and activate Python virtual environment
python -m venv .venv
Comment thread
zhumin8 marked this conversation as resolved.
source .venv/bin/activate

# Configure pip for external sources
pip config --venv set global.extra-index-url https://pypi.org/simple

# Install and configure Java tools (takes around 5 mins)
V=$(go run github.com/googleapis/librarian/cmd/librarian@latest config get version)
go run github.com/googleapis/librarian/cmd/librarian@${V} install
```

### Running the tests
Once the prerequisites are installed and the virtual environment is activated, run:

```shell
cd java-showcase
mvn verify -P enable-golden-tests
```

> [!IMPORTANT]
> The golden tests run the generator and compare the entire `java-showcase` directory against the newly generated state using `git diff`. For these tests to pass, you must have a completely clean git tree within the `java-showcase` directory before running them. Any uncommitted changes or untracked files will cause the tests to fail.

## Update the Golden Showcase Files

**NOTE** This requires Docker to be installed in your machine.
Open a new terminal window in the root project directory.
To regenerate the showcase library files and update them in place:

Make sure the Python virtual environment is activated, then run:

```shell
# In repository's root directory
Expand Down
2 changes: 0 additions & 2 deletions java-showcase/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,6 @@
<executable>bash</executable>
<arguments>
<argument>scripts/generate_showcase.sh</argument>
<argument>--replace</argument>
<argument>true</argument>
</arguments>
</configuration>
</execution>
Expand Down
97 changes: 10 additions & 87 deletions java-showcase/scripts/generate_showcase.sh
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}"
Comment thread
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"
25 changes: 11 additions & 14 deletions java-showcase/scripts/verify.sh
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
Loading