|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +# Copyright 2025 Google LLC. |
| 4 | +# |
| 5 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | +# you may not use this file except in compliance with the License. |
| 7 | +# You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, software |
| 12 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +# See the License for the specific language governing permissions and |
| 15 | +# limitations under the License. |
| 16 | + |
| 17 | +# Set SCRIPT_DIR to the current directory of this file. |
| 18 | +SCRIPT_DIR=$(cd -P "$(dirname "$0")" >/dev/null 2>&1 && pwd) |
| 19 | +SCRIPT_FILE="${SCRIPT_DIR}/$(basename "$0")" |
| 20 | + |
| 21 | +## |
| 22 | +## Local Development |
| 23 | +## |
| 24 | +## These functions should be used to run the local development process |
| 25 | +## |
| 26 | + |
| 27 | +## clean - Cleans the build output |
| 28 | +function clean() { |
| 29 | + mvn clean |
| 30 | +} |
| 31 | + |
| 32 | +## build - Builds the project without running tests. |
| 33 | +function test() { |
| 34 | + mvn install -DskipTests=true |
| 35 | +} |
| 36 | + |
| 37 | +## test - Runs local unit tests. |
| 38 | +function test() { |
| 39 | + mvn install |
| 40 | +} |
| 41 | + |
| 42 | +## e2e - Runs end-to-end integration tests. |
| 43 | +function e2e() { |
| 44 | + if [[ ! -f .envrc ]] ; then |
| 45 | + write_e2e_env .envrc |
| 46 | + fi |
| 47 | + source .envrc |
| 48 | + JOB_TYPE=integration .github/scripts/run_tests.sh |
| 49 | +} |
| 50 | + |
| 51 | + |
| 52 | +## e2e - Runs end-to-end integration tests. |
| 53 | +function e2e_graalvm() { |
| 54 | + if [[ ! -f .envrc ]] ; then |
| 55 | + write_e2e_env .envrc |
| 56 | + fi |
| 57 | + source .envrc |
| 58 | + .github/scripts/run_tests_graalvm_native.sh |
| 59 | +} |
| 60 | + |
| 61 | +## fix - Fixes java code format. |
| 62 | +function fix() { |
| 63 | + mvn com.coveo:fmt-maven-plugin:format |
| 64 | +} |
| 65 | + |
| 66 | +## lint - runs the java lint |
| 67 | +function lint() { |
| 68 | + mvn -P lint install -DskipTests=true |
| 69 | +} |
| 70 | + |
| 71 | + |
| 72 | +# write_e2e_env - Loads secrets from the gcloud project and writes |
| 73 | +# them to target/e2e.env to run e2e tests. |
| 74 | +# |
| 75 | +function write_e2e_env(){ |
| 76 | + secret_vars=(MYSQL_CONNECTION_NAME |
| 77 | + MYSQL_USER |
| 78 | + MYSQL_PASS |
| 79 | + MYSQL_DB |
| 80 | + MYSQL_IAM_CONNECTION_NAME |
| 81 | + MYSQL_USER_IAM_JAVA |
| 82 | + POSTGRES_CONNECTION_NAME |
| 83 | + POSTGRES_IAM_CONNECTION_NAME |
| 84 | + POSTGRES_USER |
| 85 | + POSTGRES_USER_IAM_JAVA |
| 86 | + POSTGRES_PASS |
| 87 | + POSTGRES_DB |
| 88 | + POSTGRES_CAS_CONNECTION_NAME |
| 89 | + POSTGRES_CAS_PASS |
| 90 | + POSTGRES_CUSTOMER_CAS_CONNECTION_NAME |
| 91 | + POSTGRES_CUSTOMER_CAS_PASS |
| 92 | + POSTGRES_CUSTOMER_CAS_PASS_VALID_DOMAIN_NAME |
| 93 | + POSTGRES_CUSTOMER_CAS_PASS_INVALID_DOMAIN_NAME |
| 94 | + SQLSERVER_CONNECTION_NAME |
| 95 | + SQLSERVER_USER |
| 96 | + SQLSERVER_PASS |
| 97 | + SQLSERVER_DB |
| 98 | + IMPERSONATED_USER |
| 99 | + QUOTA_PROJECT |
| 100 | + ) |
| 101 | + |
| 102 | + if [[ -z "${TEST_PROJECT:-}" ]] ; then |
| 103 | + echo "Set TEST_PROJECT environment variable to the project containing" |
| 104 | + echo "the e2e test suite secrets." |
| 105 | + exit 1 |
| 106 | + fi |
| 107 | + |
| 108 | + echo "Getting test secrets from $TEST_PROJECT into $1" |
| 109 | + { |
| 110 | + for name in "${secret_vars[@]}" ; do |
| 111 | + val=$(gcloud secrets versions access latest --project "$TEST_PROJECT" --secret="$name") |
| 112 | + echo "export $name=\'$val\'" |
| 113 | + done |
| 114 | + } > "$1" |
| 115 | + |
| 116 | +} |
| 117 | + |
| 118 | +## help - prints the help details |
| 119 | +## |
| 120 | +function help() { |
| 121 | + # Note: This will print the comments beginning with ## above each function |
| 122 | + # in this file. |
| 123 | + |
| 124 | + echo "build.sh <command> <arguments>" |
| 125 | + echo |
| 126 | + echo "Commands to assist with local development and CI builds." |
| 127 | + echo |
| 128 | + echo "Commands:" |
| 129 | + echo |
| 130 | + grep -e '^##' "$SCRIPT_FILE" | sed -e 's/##/ /' |
| 131 | +} |
| 132 | + |
| 133 | +set -euo pipefail |
| 134 | + |
| 135 | +# Check CLI Arguments |
| 136 | +if [[ "$#" -lt 1 ]] ; then |
| 137 | + help |
| 138 | + exit 1 |
| 139 | +fi |
| 140 | + |
| 141 | +cd "$SCRIPT_DIR" |
| 142 | + |
| 143 | +"$@" |
| 144 | + |
0 commit comments