diff --git a/.github/workflows/dataconnect.yml b/.github/workflows/dataconnect.yml index 578690c9d4e..1e71d202ee5 100644 --- a/.github/workflows/dataconnect.yml +++ b/.github/workflows/dataconnect.yml @@ -271,6 +271,17 @@ jobs: with: args: -color /github/workspace/.github/workflows/dataconnect.yml + shellcheck: + continue-on-error: false + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + with: + show-progress: false + sparse-checkout: 'firebase-dataconnect/' + - name: shellcheck + run: find . -name '*.sh' -print0 | xargs --verbose -0 shellcheck --norc --enable=all --shell=bash + python-ci-unit-tests: continue-on-error: false runs-on: ubuntu-latest diff --git a/firebase-dataconnect/emulator/emulator.sh b/firebase-dataconnect/emulator/emulator.sh index 39a45ec6a4e..67f6fe180d1 100755 --- a/firebase-dataconnect/emulator/emulator.sh +++ b/firebase-dataconnect/emulator/emulator.sh @@ -16,7 +16,8 @@ set -euo pipefail -readonly SCRIPT_DIR="$(dirname "$0")" +SCRIPT_DIR="$(dirname "$0")" +readonly SCRIPT_DIR readonly SELF_EXECUTABLE="$0" readonly LOG_PREFIX="[$0] " readonly DEFAULT_POSTGRESQL_STRING='postgresql://postgres:postgres@localhost:5432?sslmode=disable' @@ -38,7 +39,7 @@ function parse_args { local OPTIND=1 local OPTERR=0 while getopts ":c:p:v:hwg" arg ; do - case "$arg" in + case "${arg}" in c) emulator_binary="${OPTARG}" ;; g) emulator_binary="gradle" ;; p) postgresql_string="${OPTARG}" ;; @@ -59,12 +60,12 @@ function parse_args { exit 2 ;; *) - log_error_and_exit "INTERNAL ERROR: unknown argument: $arg" + log_error_and_exit "INTERNAL ERROR: unknown argument: ${arg}" ;; esac done - if [[ $emulator_binary != "gradle" ]] ; then + if [[ ${emulator_binary} != "gradle" ]] ; then export DATACONNECT_EMULATOR_BINARY_PATH="${emulator_binary}" else run_command "${SCRIPT_DIR}/../../gradlew" -p "${SCRIPT_DIR}/../.." --configure-on-demand :firebase-dataconnect:connectors:downloadDebugDataConnectExecutable @@ -72,8 +73,8 @@ function parse_args { if [[ ${#gradle_emulator_binaries[@]} -ne 1 ]]; then log_error_and_exit "expected exactly 1 emulator binary from gradle, but got ${#gradle_emulator_binaries[@]}: ${gradle_emulator_binaries[*]}" fi - local gradle_emulator_binary="${gradle_emulator_binaries[@]}" - if [[ ! -e $gradle_emulator_binary ]] ; then + local gradle_emulator_binary="${gradle_emulator_binaries[0]}" + if [[ ! -e ${gradle_emulator_binary} ]] ; then log_error_and_exit "emulator binary from gradle does not exist: ${gradle_emulator_binary}" fi export DATACONNECT_EMULATOR_BINARY_PATH="${gradle_emulator_binary}" @@ -82,7 +83,7 @@ function parse_args { export FIREBASE_DATACONNECT_POSTGRESQL_STRING="${postgresql_string}" export DATA_CONNECT_PREVIEW="${preview_flags}" - if [[ $wipe_and_restart_postgres_pod == "1" ]] ; then + if [[ ${wipe_and_restart_postgres_pod} == "1" ]] ; then run_command "${SCRIPT_DIR}/wipe_postgres_db.sh" run_command "${SCRIPT_DIR}/start_postgres_pod.sh" fi diff --git a/firebase-dataconnect/emulator/start_postgres_pod.sh b/firebase-dataconnect/emulator/start_postgres_pod.sh index a42fc2bde82..7fe1194834e 100755 --- a/firebase-dataconnect/emulator/start_postgres_pod.sh +++ b/firebase-dataconnect/emulator/start_postgres_pod.sh @@ -25,8 +25,9 @@ function run_command { "$@" } -# Determine the absolute path of the directory containing this file. -readonly SCRIPT_DIR="$(readlink -f $(dirname "$0"))" +# Determine the path of the directory containing this file. +SCRIPT_DIR="$(dirname "$0")" +readonly SCRIPT_DIR # Create the podman "pod" if it is not already created. # Bind the PostgreSQL server to port 5432 on the host, so that the host can connect to it. diff --git a/firebase-dataconnect/scripts/compile_kotlin.sh b/firebase-dataconnect/scripts/compile_kotlin.sh index 64b68bfac67..f9e9527c72f 100755 --- a/firebase-dataconnect/scripts/compile_kotlin.sh +++ b/firebase-dataconnect/scripts/compile_kotlin.sh @@ -16,7 +16,8 @@ set -euo pipefail -readonly PROJECT_ROOT_DIR="$(dirname "$0")/../.." +PROJECT_ROOT_DIR="$(dirname "$0")/../.." +readonly PROJECT_ROOT_DIR readonly TARGETS=( ":firebase-dataconnect:compileDebugKotlin" diff --git a/firebase-dataconnect/scripts/emulator_run.sh b/firebase-dataconnect/scripts/emulator_run.sh index 352584af85d..0c21f1aad14 100755 --- a/firebase-dataconnect/scripts/emulator_run.sh +++ b/firebase-dataconnect/scripts/emulator_run.sh @@ -16,7 +16,8 @@ set -euo pipefail -readonly PROJECT_ROOT_DIR="$(dirname "$0")/../.." +PROJECT_ROOT_DIR="$(dirname "$0")/../.." +readonly PROJECT_ROOT_DIR ( set -xv diff --git a/firebase-dataconnect/scripts/generateApiTxtFile.sh b/firebase-dataconnect/scripts/generateApiTxtFile.sh index cb572c07140..7ed6070c95b 100755 --- a/firebase-dataconnect/scripts/generateApiTxtFile.sh +++ b/firebase-dataconnect/scripts/generateApiTxtFile.sh @@ -16,7 +16,8 @@ set -euo pipefail -readonly PROJECT_ROOT_DIR="$(dirname "$0")/../.." +PROJECT_ROOT_DIR="$(dirname "$0")/../.." +readonly PROJECT_ROOT_DIR readonly args=( "${PROJECT_ROOT_DIR}/gradlew" diff --git a/firebase-dataconnect/scripts/generate_data_connect_sources.sh b/firebase-dataconnect/scripts/generate_data_connect_sources.sh index d685d990253..b1a3b35d8cc 100755 --- a/firebase-dataconnect/scripts/generate_data_connect_sources.sh +++ b/firebase-dataconnect/scripts/generate_data_connect_sources.sh @@ -16,7 +16,8 @@ set -euo pipefail -readonly PROJECT_ROOT_DIR="$(dirname "$0")/../.." +PROJECT_ROOT_DIR="$(dirname "$0")/../.." +readonly PROJECT_ROOT_DIR readonly TARGETS=( ":firebase-dataconnect:connectors:generateDebugDataConnectSources" diff --git a/firebase-dataconnect/scripts/run_all_tests.sh b/firebase-dataconnect/scripts/run_all_tests.sh index e7c38e6c3a2..dc7b8c11cb9 100755 --- a/firebase-dataconnect/scripts/run_all_tests.sh +++ b/firebase-dataconnect/scripts/run_all_tests.sh @@ -16,7 +16,8 @@ set -euo pipefail -readonly PROJECT_ROOT_DIR="$(dirname "$0")/../.." +PROJECT_ROOT_DIR="$(dirname "$0")/../.." +readonly PROJECT_ROOT_DIR readonly TARGETS=( ":firebase-dataconnect:androidTestutil:connectedDebugAndroidTest" diff --git a/firebase-dataconnect/scripts/run_integration_tests.sh b/firebase-dataconnect/scripts/run_integration_tests.sh index 914839c3141..d81ae3b1e64 100755 --- a/firebase-dataconnect/scripts/run_integration_tests.sh +++ b/firebase-dataconnect/scripts/run_integration_tests.sh @@ -16,7 +16,8 @@ set -euo pipefail -readonly PROJECT_ROOT_DIR="$(dirname "$0")/../.." +PROJECT_ROOT_DIR="$(dirname "$0")/../.." +readonly PROJECT_ROOT_DIR readonly TARGETS=( ":firebase-dataconnect:connectedDebugAndroidTest" diff --git a/firebase-dataconnect/scripts/run_unit_tests.sh b/firebase-dataconnect/scripts/run_unit_tests.sh index 4bd53b738b3..a54e1e8c6ae 100755 --- a/firebase-dataconnect/scripts/run_unit_tests.sh +++ b/firebase-dataconnect/scripts/run_unit_tests.sh @@ -16,7 +16,8 @@ set -euo pipefail -readonly PROJECT_ROOT_DIR="$(dirname "$0")/../.." +PROJECT_ROOT_DIR="$(dirname "$0")/../.." +readonly PROJECT_ROOT_DIR readonly TARGETS=( ":firebase-dataconnect:testDebugUnitTest" diff --git a/firebase-dataconnect/scripts/shellcheck.sh b/firebase-dataconnect/scripts/shellcheck.sh new file mode 100755 index 00000000000..eab124ad645 --- /dev/null +++ b/firebase-dataconnect/scripts/shellcheck.sh @@ -0,0 +1,36 @@ +#!/bin/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 -euo pipefail + +DATACONNECT_ROOT_DIR="$(dirname "$0")/.." +readonly DATACONNECT_ROOT_DIR + +sh_files=( + "${DATACONNECT_ROOT_DIR}"/emulator/*.sh + "${DATACONNECT_ROOT_DIR}"/scripts/*.sh +) + +readonly args=( + shellcheck + --norc + --enable=all + --shell=bash + "${sh_files[@]}" +) + +echo "${args[*]}" +exec "${args[@]}" diff --git a/firebase-dataconnect/scripts/spotlessApply.sh b/firebase-dataconnect/scripts/spotlessApply.sh index 8944c83c03f..4a5ee5f23af 100755 --- a/firebase-dataconnect/scripts/spotlessApply.sh +++ b/firebase-dataconnect/scripts/spotlessApply.sh @@ -16,7 +16,8 @@ set -euo pipefail -readonly PROJECT_ROOT_DIR="$(dirname "$0")/../.." +PROJECT_ROOT_DIR="$(dirname "$0")/../.." +readonly PROJECT_ROOT_DIR readonly TARGETS=( ":firebase-dataconnect:spotlessApply"