diff --git a/.github/scripts/run_tests.sh b/.github/scripts/run_tests.sh index a8c40c7ed..88a8b0342 100755 --- a/.github/scripts/run_tests.sh +++ b/.github/scripts/run_tests.sh @@ -17,10 +17,14 @@ set -e if [[ $OSTYPE == 'darwin'* ]]; then - # Add alias for 127.0.0.2 to be used as a loopback address + # Add alias for 127.0.0.2 and 127.0.0.3 to be used as a loopback address # https://superuser.com/questions/458875/how-do-you-get-loopback-addresses-other-than-127-0-0-1-to-work-on-os-x - sudo ifconfig lo0 alias 127.0.0.2 up - sudo ifconfig lo0 alias 127.0.0.3 up + if ! ( ifconfig lo0 | grep -q 127.0.0.2 ) ; then + sudo ifconfig lo0 alias 127.0.0.2 up + fi + if ! ( ifconfig lo0 | grep -q 127.0.0.3 ) ; then + sudo ifconfig lo0 alias 127.0.0.3 up + fi fi echo -e "******************** Running tests... ********************\n" diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 330df6a0b..901b62f4f 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -131,11 +131,11 @@ jobs: MYSQL_PASS:${{ vars.GOOGLE_CLOUD_PROJECT }}/MYSQL_PASS MYSQL_DB:${{ vars.GOOGLE_CLOUD_PROJECT }}/MYSQL_DB MYSQL_IAM_CONNECTION_NAME:${{ vars.GOOGLE_CLOUD_PROJECT }}/MYSQL_JAVA_IAM_CONNECTION_NAME - MYSQL_IAM_USER_JAVA:${{ vars.GOOGLE_CLOUD_PROJECT }}/MYSQL_USER_IAM_JAVA + MYSQL_USER_IAM_JAVA:${{ vars.GOOGLE_CLOUD_PROJECT }}/MYSQL_USER_IAM_JAVA POSTGRES_CONNECTION_NAME:${{ vars.GOOGLE_CLOUD_PROJECT }}/POSTGRES_CONNECTION_NAME POSTGRES_IAM_CONNECTION_NAME:${{ vars.GOOGLE_CLOUD_PROJECT }}/POSTGRES_IAM_CONNECTION_NAME POSTGRES_USER:${{ vars.GOOGLE_CLOUD_PROJECT }}/POSTGRES_USER - POSTGRES_IAM_USER:${{ vars.GOOGLE_CLOUD_PROJECT }}/POSTGRES_USER_IAM_JAVA + POSTGRES_USER_IAM_JAVA:${{ vars.GOOGLE_CLOUD_PROJECT }}/POSTGRES_USER_IAM_JAVA POSTGRES_PASS:${{ vars.GOOGLE_CLOUD_PROJECT }}/POSTGRES_PASS POSTGRES_DB:${{ vars.GOOGLE_CLOUD_PROJECT }}/POSTGRES_DB POSTGRES_CAS_CONNECTION_NAME:${{ vars.GOOGLE_CLOUD_PROJECT }}/POSTGRES_CAS_CONNECTION_NAME @@ -157,11 +157,11 @@ jobs: MYSQL_PASS: "${{ steps.secrets.outputs.MYSQL_PASS }}" MYSQL_DB: "${{ steps.secrets.outputs.MYSQL_DB }}" MYSQL_IAM_CONNECTION_NAME: "${{ steps.secrets.outputs.MYSQL_IAM_CONNECTION_NAME }}" - MYSQL_IAM_USER: "${{ steps.secrets.outputs.MYSQL_IAM_USER_JAVA }}" + MYSQL_USER_IAM_JAVA: "${{ steps.secrets.outputs.MYSQL_USER_IAM_JAVA }}" POSTGRES_CONNECTION_NAME: "${{ steps.secrets.outputs.POSTGRES_CONNECTION_NAME }}" POSTGRES_IAM_CONNECTION_NAME: "${{ steps.secrets.outputs.POSTGRES_IAM_CONNECTION_NAME }}" POSTGRES_USER: "${{ steps.secrets.outputs.POSTGRES_USER }}" - POSTGRES_IAM_USER: "${{ steps.secrets.outputs.POSTGRES_IAM_USER }}" + POSTGRES_USER_IAM_JAVA: "${{ steps.secrets.outputs.POSTGRES_USER_IAM_JAVA }}" POSTGRES_PASS: "${{ steps.secrets.outputs.POSTGRES_PASS }}" POSTGRES_DB: "${{ steps.secrets.outputs.POSTGRES_DB }}" POSTGRES_CAS_CONNECTION_NAME: "${{ steps.secrets.outputs.POSTGRES_CAS_CONNECTION_NAME }}" @@ -204,7 +204,10 @@ jobs: ./flakybot --repo ${{github.repository}} --commit_hash ${{github.sha}} --build_url https://github.com/${{github.repository}}/actions/runs/${{github.run_id}} graalvm: # run job on periodic (schedule) event - if: "${{ github.event_name == 'schedule' }}" + if: | + github.event_name == 'schedule' || + github.event_name != 'pull_request' || + (github.event.pull_request.head.repo.full_name == github.repository && github.actor != 'dependabot[bot]') name: graalvm native / linux runs-on: ubuntu-latest permissions: @@ -242,11 +245,11 @@ jobs: MYSQL_PASS:${{ vars.GOOGLE_CLOUD_PROJECT }}/MYSQL_PASS MYSQL_DB:${{ vars.GOOGLE_CLOUD_PROJECT }}/MYSQL_DB MYSQL_IAM_CONNECTION_NAME:${{ vars.GOOGLE_CLOUD_PROJECT }}/MYSQL_JAVA_IAM_CONNECTION_NAME - MYSQL_IAM_USER_JAVA:${{ vars.GOOGLE_CLOUD_PROJECT }}/MYSQL_USER_IAM_JAVA + MYSQL_USER_IAM_JAVA:${{ vars.GOOGLE_CLOUD_PROJECT }}/MYSQL_USER_IAM_JAVA POSTGRES_CONNECTION_NAME:${{ vars.GOOGLE_CLOUD_PROJECT }}/POSTGRES_CONNECTION_NAME POSTGRES_IAM_CONNECTION_NAME:${{ vars.GOOGLE_CLOUD_PROJECT }}/POSTGRES_IAM_CONNECTION_NAME POSTGRES_USER:${{ vars.GOOGLE_CLOUD_PROJECT }}/POSTGRES_USER - POSTGRES_IAM_USER:${{ vars.GOOGLE_CLOUD_PROJECT }}/POSTGRES_USER_IAM_JAVA + POSTGRES_USER_IAM_JAVA:${{ vars.GOOGLE_CLOUD_PROJECT }}/POSTGRES_USER_IAM_JAVA POSTGRES_PASS:${{ vars.GOOGLE_CLOUD_PROJECT }}/POSTGRES_PASS POSTGRES_DB:${{ vars.GOOGLE_CLOUD_PROJECT }}/POSTGRES_DB POSTGRES_CAS_CONNECTION_NAME:${{ vars.GOOGLE_CLOUD_PROJECT }}/POSTGRES_CAS_CONNECTION_NAME @@ -269,11 +272,11 @@ jobs: MYSQL_PASS: "${{ steps.secrets.outputs.MYSQL_PASS }}" MYSQL_DB: "${{ steps.secrets.outputs.MYSQL_DB }}" MYSQL_IAM_CONNECTION_NAME: "${{ steps.secrets.outputs.MYSQL_IAM_CONNECTION_NAME }}" - MYSQL_IAM_USER: "${{ steps.secrets.outputs.MYSQL_IAM_USER_JAVA }}" + MYSQL_USER_IAM_JAVA: "${{ steps.secrets.outputs.MYSQL_USER_IAM_JAVA }}" POSTGRES_CONNECTION_NAME: "${{ steps.secrets.outputs.POSTGRES_CONNECTION_NAME }}" POSTGRES_IAM_CONNECTION_NAME: "${{ steps.secrets.outputs.POSTGRES_IAM_CONNECTION_NAME }}" POSTGRES_USER: "${{ steps.secrets.outputs.POSTGRES_USER }}" - POSTGRES_IAM_USER: "${{ steps.secrets.outputs.POSTGRES_IAM_USER }}" + POSTGRES_USER_IAM_JAVA: "${{ steps.secrets.outputs.POSTGRES_USER_IAM_JAVA }}" POSTGRES_PASS: "${{ steps.secrets.outputs.POSTGRES_PASS }}" POSTGRES_DB: "${{ steps.secrets.outputs.POSTGRES_DB }}" POSTGRES_CAS_CONNECTION_NAME: "${{ steps.secrets.outputs.POSTGRES_CAS_CONNECTION_NAME }}" diff --git a/build.sh b/build.sh new file mode 100755 index 000000000..2ec4efa1f --- /dev/null +++ b/build.sh @@ -0,0 +1,144 @@ +#!/usr/bin/env bash + +# Copyright 2025 Google LLC. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Set SCRIPT_DIR to the current directory of this file. +SCRIPT_DIR=$(cd -P "$(dirname "$0")" >/dev/null 2>&1 && pwd) +SCRIPT_FILE="${SCRIPT_DIR}/$(basename "$0")" + +## +## Local Development +## +## These functions should be used to run the local development process +## + +## clean - Cleans the build output +function clean() { + mvn clean +} + +## build - Builds the project without running tests. +function test() { + mvn install -DskipTests=true +} + +## test - Runs local unit tests. +function test() { + mvn install +} + +## e2e - Runs end-to-end integration tests. +function e2e() { + if [[ ! -f .envrc ]] ; then + write_e2e_env .envrc + fi + source .envrc + JOB_TYPE=integration .github/scripts/run_tests.sh +} + + +## e2e - Runs end-to-end integration tests. +function e2e_graalvm() { + if [[ ! -f .envrc ]] ; then + write_e2e_env .envrc + fi + source .envrc + .github/scripts/run_tests_graalvm_native.sh +} + +## fix - Fixes java code format. +function fix() { + mvn com.coveo:fmt-maven-plugin:format +} + +## lint - runs the java lint +function lint() { + mvn -P lint install -DskipTests=true +} + + +# write_e2e_env - Loads secrets from the gcloud project and writes +# them to target/e2e.env to run e2e tests. +# +function write_e2e_env(){ + secret_vars=(MYSQL_CONNECTION_NAME + MYSQL_USER + MYSQL_PASS + MYSQL_DB + MYSQL_IAM_CONNECTION_NAME + MYSQL_USER_IAM_JAVA + POSTGRES_CONNECTION_NAME + POSTGRES_IAM_CONNECTION_NAME + POSTGRES_USER + POSTGRES_USER_IAM_JAVA + POSTGRES_PASS + POSTGRES_DB + POSTGRES_CAS_CONNECTION_NAME + POSTGRES_CAS_PASS + POSTGRES_CUSTOMER_CAS_CONNECTION_NAME + POSTGRES_CUSTOMER_CAS_PASS + POSTGRES_CUSTOMER_CAS_PASS_VALID_DOMAIN_NAME + POSTGRES_CUSTOMER_CAS_PASS_INVALID_DOMAIN_NAME + SQLSERVER_CONNECTION_NAME + SQLSERVER_USER + SQLSERVER_PASS + SQLSERVER_DB + IMPERSONATED_USER + QUOTA_PROJECT + ) + + if [[ -z "${TEST_PROJECT:-}" ]] ; then + echo "Set TEST_PROJECT environment variable to the project containing" + echo "the e2e test suite secrets." + exit 1 + fi + + echo "Getting test secrets from $TEST_PROJECT into $1" + { + for name in "${secret_vars[@]}" ; do + val=$(gcloud secrets versions access latest --project "$TEST_PROJECT" --secret="$name") + echo "export $name=\'$val\'" + done + } > "$1" + +} + +## help - prints the help details +## +function help() { + # Note: This will print the comments beginning with ## above each function + # in this file. + + echo "build.sh " + echo + echo "Commands to assist with local development and CI builds." + echo + echo "Commands:" + echo + grep -e '^##' "$SCRIPT_FILE" | sed -e 's/##/ /' +} + +set -euo pipefail + +# Check CLI Arguments +if [[ "$#" -lt 1 ]] ; then + help + exit 1 +fi + +cd "$SCRIPT_DIR" + +"$@" + diff --git a/jdbc/mariadb/src/test/java/com/google/cloud/sql/mariadb/JdbcMariaDBIamAuthIntegrationTests.java b/jdbc/mariadb/src/test/java/com/google/cloud/sql/mariadb/JdbcMariaDBIamAuthIntegrationTests.java index 0b2b35f36..06ae22c5a 100644 --- a/jdbc/mariadb/src/test/java/com/google/cloud/sql/mariadb/JdbcMariaDBIamAuthIntegrationTests.java +++ b/jdbc/mariadb/src/test/java/com/google/cloud/sql/mariadb/JdbcMariaDBIamAuthIntegrationTests.java @@ -40,9 +40,9 @@ public class JdbcMariaDBIamAuthIntegrationTests { private static final String CONNECTION_NAME = System.getenv("MYSQL_IAM_CONNECTION_NAME"); private static final String DB_NAME = System.getenv("MYSQL_DB"); - private static final String DB_USER = System.getenv("MYSQL_IAM_USER"); + private static final String DB_USER = System.getenv("MYSQL_USER_IAM_JAVA"); private static final ImmutableList requiredEnvVars = - ImmutableList.of("MYSQL_IAM_CONNECTION_NAME", "MYSQL_DB", "MYSQL_IAM_USER"); + ImmutableList.of("MYSQL_IAM_CONNECTION_NAME", "MYSQL_DB", "MYSQL_USER_IAM_JAVA"); @Rule public Timeout globalTimeout = new Timeout(80, TimeUnit.SECONDS); private HikariDataSource connectionPool; diff --git a/jdbc/mysql-j-8/src/test/java/com/google/cloud/sql/mysql/JdbcMysqlJ8IamAuthIntegrationTests.java b/jdbc/mysql-j-8/src/test/java/com/google/cloud/sql/mysql/JdbcMysqlJ8IamAuthIntegrationTests.java index 8606eb224..23d98d629 100644 --- a/jdbc/mysql-j-8/src/test/java/com/google/cloud/sql/mysql/JdbcMysqlJ8IamAuthIntegrationTests.java +++ b/jdbc/mysql-j-8/src/test/java/com/google/cloud/sql/mysql/JdbcMysqlJ8IamAuthIntegrationTests.java @@ -40,10 +40,10 @@ public class JdbcMysqlJ8IamAuthIntegrationTests { private static final String CONNECTION_NAME = System.getenv("MYSQL_IAM_CONNECTION_NAME"); private static final String DB_NAME = System.getenv("MYSQL_DB"); - private static final String DB_USER = System.getenv("MYSQL_IAM_USER"); + private static final String DB_USER = System.getenv("MYSQL_USER_IAM_JAVA"); private static final ImmutableList requiredEnvVars = - ImmutableList.of("MYSQL_IAM_USER", "MYSQL_DB", "MYSQL_IAM_CONNECTION_NAME"); + ImmutableList.of("MYSQL_USER_IAM_JAVA", "MYSQL_DB", "MYSQL_IAM_CONNECTION_NAME"); @Rule public Timeout globalTimeout = new Timeout(80, TimeUnit.SECONDS); private HikariDataSource connectionPool; diff --git a/jdbc/postgres/src/test/java/com/google/cloud/sql/postgres/JdbcPostgresIamAuthIntegrationTests.java b/jdbc/postgres/src/test/java/com/google/cloud/sql/postgres/JdbcPostgresIamAuthIntegrationTests.java index a64cbba0f..67b754374 100644 --- a/jdbc/postgres/src/test/java/com/google/cloud/sql/postgres/JdbcPostgresIamAuthIntegrationTests.java +++ b/jdbc/postgres/src/test/java/com/google/cloud/sql/postgres/JdbcPostgresIamAuthIntegrationTests.java @@ -49,10 +49,10 @@ public class JdbcPostgresIamAuthIntegrationTests { // [START cloud_sql_connector_postgres_jdbc_iam_auth] private static final String CONNECTION_NAME = System.getenv("POSTGRES_IAM_CONNECTION_NAME"); private static final String DB_NAME = System.getenv("POSTGRES_DB"); - private static final String DB_USER = System.getenv("POSTGRES_IAM_USER"); + private static final String DB_USER = System.getenv("POSTGRES_USER_IAM_JAVA"); // [END cloud_sql_connector_postgres_jdbc_iam_auth] private static final ImmutableList requiredEnvVars = - ImmutableList.of("POSTGRES_IAM_USER", "POSTGRES_DB", "POSTGRES_IAM_CONNECTION_NAME"); + ImmutableList.of("POSTGRES_USER_IAM_JAVA", "POSTGRES_DB", "POSTGRES_IAM_CONNECTION_NAME"); @Rule public Timeout globalTimeout = new Timeout(80, TimeUnit.SECONDS); private HikariDataSource connectionPool; diff --git a/jdbc/postgres/src/test/java/com/google/cloud/sql/postgres/JdbcPostgresNamedConnectorIntegrationTests.java b/jdbc/postgres/src/test/java/com/google/cloud/sql/postgres/JdbcPostgresNamedConnectorIntegrationTests.java index c48baa805..e90ea3cef 100644 --- a/jdbc/postgres/src/test/java/com/google/cloud/sql/postgres/JdbcPostgresNamedConnectorIntegrationTests.java +++ b/jdbc/postgres/src/test/java/com/google/cloud/sql/postgres/JdbcPostgresNamedConnectorIntegrationTests.java @@ -46,9 +46,9 @@ public class JdbcPostgresNamedConnectorIntegrationTests { private static final String CONNECTION_NAME = System.getenv("POSTGRES_IAM_CONNECTION_NAME"); private static final String DB_NAME = System.getenv("POSTGRES_DB"); - private static final String DB_USER = System.getenv("POSTGRES_IAM_USER"); + private static final String DB_USER = System.getenv("POSTGRES_USER_IAM_JAVA"); private static final ImmutableList requiredEnvVars = - ImmutableList.of("POSTGRES_IAM_USER", "POSTGRES_DB", "POSTGRES_IAM_CONNECTION_NAME"); + ImmutableList.of("POSTGRES_USER_IAM_JAVA", "POSTGRES_DB", "POSTGRES_IAM_CONNECTION_NAME"); @Rule public Timeout globalTimeout = new Timeout(80, TimeUnit.SECONDS); private HikariDataSource connectionPool; diff --git a/jdbc/postgres/src/test/java/com/google/cloud/sql/postgres/JdbcPostgresQuotaProjectIAMAuthIntegrationTests.java b/jdbc/postgres/src/test/java/com/google/cloud/sql/postgres/JdbcPostgresQuotaProjectIAMAuthIntegrationTests.java index d27dad233..7525dc5a9 100644 --- a/jdbc/postgres/src/test/java/com/google/cloud/sql/postgres/JdbcPostgresQuotaProjectIAMAuthIntegrationTests.java +++ b/jdbc/postgres/src/test/java/com/google/cloud/sql/postgres/JdbcPostgresQuotaProjectIAMAuthIntegrationTests.java @@ -40,12 +40,12 @@ public class JdbcPostgresQuotaProjectIAMAuthIntegrationTests { private static final String CONNECTION_NAME = System.getenv("POSTGRES_IAM_CONNECTION_NAME"); private static final String DB_NAME = System.getenv("POSTGRES_DB"); - private static final String DB_USER = System.getenv("POSTGRES_IAM_USER"); + private static final String DB_USER = System.getenv("POSTGRES_USER_IAM_JAVA"); private static final String QUOTA_PROJECT = System.getenv("QUOTA_PROJECT"); private static final ImmutableList requiredEnvVars = ImmutableList.of( - "POSTGRES_IAM_USER", "POSTGRES_DB", "POSTGRES_IAM_CONNECTION_NAME", "QUOTA_PROJECT"); + "POSTGRES_USER_IAM_JAVA", "POSTGRES_DB", "POSTGRES_IAM_CONNECTION_NAME", "QUOTA_PROJECT"); @Rule public Timeout globalTimeout = new Timeout(80, TimeUnit.SECONDS); private HikariDataSource connectionPool; diff --git a/r2dbc/mariadb/src/test/java/com/google/cloud/sql/core/R2dbcMariadbIamAuthIntegrationTests.java b/r2dbc/mariadb/src/test/java/com/google/cloud/sql/core/R2dbcMariadbIamAuthIntegrationTests.java index 28696d570..4069327e1 100644 --- a/r2dbc/mariadb/src/test/java/com/google/cloud/sql/core/R2dbcMariadbIamAuthIntegrationTests.java +++ b/r2dbc/mariadb/src/test/java/com/google/cloud/sql/core/R2dbcMariadbIamAuthIntegrationTests.java @@ -46,11 +46,11 @@ public class R2dbcMariadbIamAuthIntegrationTests { private static final ImmutableList requiredEnvVars = - ImmutableList.of("MYSQL_IAM_USER", "MYSQL_DB", "MYSQL_IAM_CONNECTION_NAME"); + ImmutableList.of("MYSQL_USER_IAM_JAVA", "MYSQL_DB", "MYSQL_IAM_CONNECTION_NAME"); private static final String CONNECTION_NAME = System.getenv("MYSQL_IAM_CONNECTION_NAME"); private static final String DB_NAME = System.getenv("MYSQL_DB"); - private static final String DB_USER = System.getenv("MYSQL_IAM_USER"); + private static final String DB_USER = System.getenv("MYSQL_USER_IAM_JAVA"); @Rule public Timeout globalTimeout = new Timeout(80, TimeUnit.SECONDS); diff --git a/r2dbc/mysql/src/test/java/com/google/cloud/sql/core/R2dbcMysqlIamAuthIntegrationTests.java b/r2dbc/mysql/src/test/java/com/google/cloud/sql/core/R2dbcMysqlIamAuthIntegrationTests.java index f451ba0bd..c517e668b 100644 --- a/r2dbc/mysql/src/test/java/com/google/cloud/sql/core/R2dbcMysqlIamAuthIntegrationTests.java +++ b/r2dbc/mysql/src/test/java/com/google/cloud/sql/core/R2dbcMysqlIamAuthIntegrationTests.java @@ -46,11 +46,11 @@ public class R2dbcMysqlIamAuthIntegrationTests { private static final ImmutableList requiredEnvVars = - ImmutableList.of("MYSQL_IAM_USER", "MYSQL_DB", "MYSQL_IAM_CONNECTION_NAME"); + ImmutableList.of("MYSQL_USER_IAM_JAVA", "MYSQL_DB", "MYSQL_IAM_CONNECTION_NAME"); private static final String CONNECTION_NAME = System.getenv("MYSQL_IAM_CONNECTION_NAME"); private static final String DB_NAME = System.getenv("MYSQL_DB"); - private static final String DB_USER = System.getenv("MYSQL_IAM_USER"); + private static final String DB_USER = System.getenv("MYSQL_USER_IAM_JAVA"); @Rule public Timeout globalTimeout = new Timeout(80, TimeUnit.SECONDS); diff --git a/r2dbc/postgres/src/test/java/com/google/cloud/sql/core/R2dbcPostgresIamAuthIntegrationTests.java b/r2dbc/postgres/src/test/java/com/google/cloud/sql/core/R2dbcPostgresIamAuthIntegrationTests.java index 72caf7bec..fde6acc67 100644 --- a/r2dbc/postgres/src/test/java/com/google/cloud/sql/core/R2dbcPostgresIamAuthIntegrationTests.java +++ b/r2dbc/postgres/src/test/java/com/google/cloud/sql/core/R2dbcPostgresIamAuthIntegrationTests.java @@ -49,7 +49,7 @@ public class R2dbcPostgresIamAuthIntegrationTests { // [START cloud_sql_connector_postgres_r2dbc_iam_auth] private static final String CONNECTION_NAME = System.getenv("POSTGRES_IAM_CONNECTION_NAME"); private static final String DB_NAME = System.getenv("POSTGRES_DB"); - private static final String DB_USER = System.getenv("POSTGRES_IAM_USER"); + private static final String DB_USER = System.getenv("POSTGRES_USER_IAM_JAVA"); // [END cloud_sql_connector_postgres_r2dbc_iam_auth] private static final ImmutableList requiredEnvVars = ImmutableList.of(