Kokoro to gcb spanner#8707
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces utility scripts and templates to automate setting up Google Cloud Build (GCB) triggers for running system tests on client libraries, including a generated configuration for the Spanner library. The feedback focuses on improving the robustness and flexibility of these scripts: allowing the generation script to overwrite existing files for easier template updates, making the trigger creation script idempotent by checking for existing triggers, adding and forwarding a project ID parameter in the orchestrator script, and using npx instead of a hardcoded path for the nyc coverage tool in the Cloud Build template.
I am having trouble creating individual review comments. Click here to see my feedback.
bin/move-to-gcb/generate-cloudbuild.sh (33-36)
Exiting early when the output file already exists prevents updates to the template from being propagated to existing libraries when regenerating. To ensure maintainability and allow easy updates across all libraries when the template changes, the script should overwrite the existing file (or support a force flag) instead of exiting early.
if [ -f "${OUTPUT_FILE}" ]; then
echo "Overwriting existing file ${OUTPUT_FILE}."
fi
bin/move-to-gcb/create_trigger.sh (35-46)
If the build trigger already exists, the gcloud builds triggers create command will fail and cause the script to exit with an error. Checking if the trigger already exists before attempting to create it makes the script idempotent and improves the developer experience.
# Check if the trigger already exists
if gcloud builds triggers describe "${LIBRARY_NAME}-system-tests" --project="${PROJECT_ID}" --region="global" >/dev/null 2>&1; then
echo "Trigger '${LIBRARY_NAME}-system-tests' already exists in project '${PROJECT_ID}'."
else
# Execute the gcloud command with variable substitutions
gcloud builds triggers create github \
--project="${PROJECT_ID}" \
--name="${LIBRARY_NAME}-system-tests" \
--region="global" \
--description="CI build trigger for ${LIBRARY_NAME} system tests" \
--repo-owner="googleapis" \
--repo-name="google-cloud-node" \
--pull-request-pattern="^main$" \
--comment-control="COMMENTS_ENABLED_FOR_EXTERNAL_CONTRIBUTORS_ONLY" \
--included-files="handwritten/${LIBRARY_NAME}/**" \
--build-config="handwritten/${LIBRARY_NAME}/cloudbuild.yaml"
fi
bin/move-to-gcb/generate_yaml_and_create_trigger.sh (5-17)
The orchestrator script should accept the -p option to allow specifying a custom Google Cloud project ID, and forward it to create_trigger.sh. This ensures consistency and usability when running the script for different environments.
usage() {
echo "Usage: $0 -l <library_name> [-p <project_id>]"
echo " -l The name of the library (e.g., bigtable, spanner) [Required]"
echo " -p The Google Cloud project ID"
exit 1
}
while getopts "l:p:h" opt; do
case "${opt}" in
l) LIBRARY_NAME="${OPTARG}" ;;
p) PROJECT_ID="${OPTARG}" ;;
h) usage ;;
*) usage ;;
esac
done
bin/move-to-gcb/generate_yaml_and_create_trigger.sh (29-30)
Forward the custom project ID (if provided) to the create_trigger.sh script.
# Create the build trigger
"${SCRIPT_DIR}/create_trigger.sh" -l "${LIBRARY_NAME}" ${PROJECT_ID:+-p "${PROJECT_ID}"}
bin/move-to-gcb/cloudbuild.yaml.template (46-51)
Hardcoding the internal path to nyc (./node_modules/nyc/bin/nyc.js) is fragile as the package structure could change across major versions. Using npx --no-install nyc is more robust and idiomatic for Node.js projects.
# Check if nyc is installed and run report
if npx --no-install nyc --version >/dev/null 2>&1; then
npx --no-install nyc report || true # || true prevents build failure if nyc report itself exits non-zero
else
echo "nyc not found, skipping coverage report."
fi
Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly:
Fixes #<issue_number_goes_here> 🦕