Skip to content

Commit de76cec

Browse files
authored
dataconnect(chore): convert helper bash scripts to zsh (#8084)
1 parent 490a8f5 commit de76cec

15 files changed

Lines changed: 524 additions & 318 deletions

.github/workflows/dataconnect.yml

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -305,16 +305,26 @@ jobs:
305305
with:
306306
args: -color /github/workspace/.github/workflows/dataconnect.yml
307307

308-
shellcheck:
308+
zshellcheck:
309309
continue-on-error: false
310310
runs-on: ubuntu-latest
311311
steps:
312312
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
313313
with:
314314
show-progress: false
315315
sparse-checkout: 'firebase-dataconnect/'
316-
- name: shellcheck
317-
run: find . -name '*.sh' -print0 | xargs --verbose -0 shellcheck --norc --enable=all --shell=bash
316+
- name: zshellcheck setup
317+
run: |
318+
set -xveuo pipefail
319+
cd '${{ runner.temp }}'
320+
mkdir zshellcheck
321+
cd zshellcheck
322+
curl -fsSL -o zshellcheck.tar.gz https://github.com/afadesigns/zshellcheck/releases/download/v1.0.17/zshellcheck_Linux_x86_64.tar.gz
323+
tar xvf zshellcheck.tar.gz
324+
- name: zshellcheck
325+
run: |
326+
set -xveuo pipefail
327+
find . -name '*.zsh' -exec '${{ runner.temp }}/zshellcheck/zshellcheck' -severity style -no-color -no-banner -diff '{}' +
318328
319329
python-ci-unit-tests:
320330
continue-on-error: false

firebase-dataconnect/emulator/emulator.sh

Lines changed: 0 additions & 169 deletions
This file was deleted.
Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
#!/usr/bin/env zsh
2+
3+
# Copyright 2026 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+
setopt errexit nounset pipefail
18+
19+
source "${0:A:h:h}/scripts/util/say.zsh"
20+
21+
typeset -r self_executable="$0"
22+
typeset -r log_prefix="[$0]"
23+
typeset -r default_postgresql_string='postgresql://postgres:postgres@localhost:5432?sslmode=disable'
24+
25+
main() {
26+
cd "${0:A:h}"
27+
parse_args "$@"
28+
log "FIREBASE_DATACONNECT_POSTGRESQL_STRING=${FIREBASE_DATACONNECT_POSTGRESQL_STRING}"
29+
log "DATACONNECT_EMULATOR_BINARY_PATH=${DATACONNECT_EMULATOR_BINARY_PATH}"
30+
log "DATA_CONNECT_PREVIEW=${DATA_CONNECT_PREVIEW}"
31+
run_command firebase --debug emulators:start --only auth,dataconnect
32+
}
33+
34+
parse_args() {
35+
zmodload zsh/zutil
36+
local -A opts
37+
zparseopts -D -E -A opts c: g p: v: w h || {
38+
sayp "Run with %F{cyan}-h%f for help" >&2
39+
exit 2
40+
}
41+
42+
if (( ${+opts[-h]} )); then
43+
print_help
44+
exit 0
45+
fi
46+
47+
if (( # > 0 )); then
48+
say_error "unrecognized option or argument: $1" >&2
49+
sayp "Run with %F{cyan}-h%f for help" >&2
50+
exit 2
51+
fi
52+
53+
typeset emulator_binary="${opts[-c]:-${opts[-g]+gradle}}"
54+
typeset postgresql_string="${opts[-p]:-$default_postgresql_string}"
55+
typeset preview_flags="${opts[-v]:-}"
56+
typeset wipe_and_restart_postgres_pod=${+opts[-w]}
57+
58+
if [[ ${emulator_binary} != "gradle" ]] ; then
59+
export DATACONNECT_EMULATOR_BINARY_PATH="${emulator_binary}"
60+
else
61+
run_command "../../gradlew" -p ../.. --configure-on-demand :firebase-dataconnect:connectors:downloadDebugDataConnectExecutable
62+
typeset gradle_emulator_binaries=(../connectors/build/intermediates/dataconnect/debug/executable/*(N))
63+
if (( ${#gradle_emulator_binaries} != 1 )); then
64+
log_error_and_exit "expected exactly 1 emulator binary from gradle, but got ${#gradle_emulator_binaries}: ${gradle_emulator_binaries[*]}"
65+
fi
66+
typeset gradle_emulator_binary="${gradle_emulator_binaries[1]}"
67+
if [[ ! -e ${gradle_emulator_binary} ]] ; then
68+
log_error_and_exit "emulator binary from gradle does not exist: ${gradle_emulator_binary}"
69+
fi
70+
export DATACONNECT_EMULATOR_BINARY_PATH="${gradle_emulator_binary}"
71+
fi
72+
73+
export FIREBASE_DATACONNECT_POSTGRESQL_STRING="${postgresql_string}"
74+
export DATA_CONNECT_PREVIEW="${preview_flags}"
75+
76+
if [[ ${wipe_and_restart_postgres_pod} == "1" ]] ; then
77+
run_command podman compose down -v
78+
run_command podman compose up -d
79+
80+
say "Waiting for Postgres service to appear to be healthy..."
81+
typeset postgres_health_check_number=0
82+
while : ; do
83+
(( postgres_health_check_number++ )) || true
84+
typeset postgres_service_status="$(print_postgres_status)"
85+
say "Postgres service health check ${postgres_health_check_number}: ${postgres_service_status}"
86+
87+
if [[ ${postgres_service_status} == *"(healthy)"* ]] ; then
88+
say "Postgres service appears to be healthy after ${postgres_health_check_number} seconds"
89+
break
90+
elif (( ${postgres_health_check_number} == 30 )) ; then
91+
print_podman_compose_status
92+
say "ERROR: Postgres service does not appear to be healthy after ${postgres_health_check_number} seconds" >&2
93+
exit 1
94+
fi
95+
96+
sleep 1s
97+
done
98+
fi
99+
}
100+
101+
run_command() {
102+
logn "Running command: "
103+
say_args "$@"
104+
}
105+
106+
print_podman_compose_status() {
107+
podman compose ps --format=json
108+
}
109+
110+
print_postgres_status() {
111+
print_podman_compose_status | jq -re '.[] | select(.Labels["com.docker.compose.service"] == "postgres") | .Status'
112+
}
113+
114+
print_help() {
115+
sayp "%BFirebase Data Connect Emulator Launcher Helper%b"
116+
say
117+
saypn "%BSyntax: "
118+
sayn "${self_executable}"
119+
sayp " [options]%b"
120+
say
121+
say "This script provides a convenient way to launch the Firebase Data Connect"
122+
say "and Firebase Authentication emulators in a way that is amenable for running"
123+
say "the integration tests."
124+
say
125+
sayp "%UOptions:%u"
126+
say
127+
sayp "%F{cyan} -c <data_connect_emulator_binary_path>%f"
128+
say " Uses the Data Connect Emulator binary at the given path. A value of \"gradle\" "
129+
say " will use the same binary as the Gradle build. If not specified, or if specified "
130+
say " as the empty string, then the emulator binary is downloaded."
131+
say
132+
sayp "%F{cyan} -g%f"
133+
say " Shorthand for: -c gradle"
134+
say
135+
sayp "%F{cyan} -p <postgresql_connection_string>%f"
136+
say " Uses the given string to connect to the PostgreSQL server. If not specified "
137+
say " the the default value of \"${default_postgresql_string}\" is used."
138+
say " If specified as the empty string then an ephemeral PGLite server is used."
139+
say
140+
sayp "%F{cyan} -v <data_connect_preview_flags>%f"
141+
say " Uses the given Data Connect preview flags when launching the emulator."
142+
say " If not specified then an empty string is used, meaning that no preview flags"
143+
say " are in effect."
144+
say
145+
sayp "%F{cyan} -w%f"
146+
say " If specified, then a local PostgreSQL container is wiped and restarted"
147+
say " before launching the emulators. This is accomplished by running:"
148+
say " podman compose down -v && podman compose up -d"
149+
say
150+
sayp "%F{cyan} -h%f"
151+
say " Print this help screen and exit, as if successful."
152+
}
153+
154+
log() {
155+
logn "$@"
156+
say
157+
}
158+
159+
logn() {
160+
saypn "%F{magenta}"
161+
sayn "${log_prefix} "
162+
saypn "%f"
163+
sayn "$@"
164+
}
165+
166+
log_error_and_exit() {
167+
say_error "$@" >&2
168+
return 1
169+
}
170+
171+
main "$@"

0 commit comments

Comments
 (0)