-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathci_firebase_apptesting_execute.sh
More file actions
executable file
·146 lines (130 loc) · 4.29 KB
/
Copy pathci_firebase_apptesting_execute.sh
File metadata and controls
executable file
·146 lines (130 loc) · 4.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/usr/bin/env bash
# Run Firebase App Testing agent against an APK or the latest App Distribution release.
# Requires: firebase-tools (npm), GOOGLE_APPLICATION_CREDENTIALS or FIREBASE_SERVICE_ACCOUNT_JSON,
# FIREBASE_ANDROID_APP_ID (1:project:android:hex form).
# Docs: https://firebase.google.com/docs/app-distribution/android/app-testing-agent
set -euo pipefail
REPO_ROOT="$(cd "$(dirname "$0")/.." && pwd)"
TEST_DIR_DEFAULT="$REPO_ROOT/firebase-apptesting/tests"
APK_PATH=""
TEST_DIR="$TEST_DIR_DEFAULT"
TEST_DEVICES="${FIREBASE_APP_TESTING_DEVICES:-model=panther,version=33,locale=en,orientation=portrait}"
NON_BLOCKING=0
DEBUG_CLI=0
usage() {
cat <<'USAGE'
Usage: ci_firebase_apptesting_execute.sh [--apk PATH] [--test-dir DIR] [--test-devices SPEC] [--non-blocking] [--debug]
--apk Path to release/debug APK (omit to use latest App Distribution release for --app)
--test-dir Directory where agent YAML suites live (default: firebase-apptesting/tests)
--test-devices Semicolon-separated Test Lab device specs (default: env FIREBASE_APP_TESTING_DEVICES or preset)
--non-blocking Pass --test-non-blocking to firebase CLI (exit before agent finishes)
--debug Pass --debug to firebase CLI (verbose; may log sensitive URLs — use only when diagnosing failures)
Environment:
FIREBASE_ANDROID_APP_ID Required Firebase Android app id
FIREBASE_SERVICE_ACCOUNT_JSON Service account JSON body (written to temp file for ADC)
GOOGLE_APPLICATION_CREDENTIALS Optional; if set, FIREBASE_SERVICE_ACCOUNT_JSON is ignored
FIREBASE_APPTESTING_DEBUG If set to "true", same as --debug (for CI wiring without argv changes)
USAGE
}
while [[ $# -gt 0 ]]; do
case "$1" in
--apk)
APK_PATH="${2:?}"
shift 2
;;
--test-dir)
TEST_DIR="${2:?}"
shift 2
;;
--test-devices)
TEST_DEVICES="${2:?}"
shift 2
;;
--non-blocking)
NON_BLOCKING=1
shift
;;
--debug)
DEBUG_CLI=1
shift
;;
-h|--help)
usage
exit 0
;;
*)
echo "Unknown option: $1" >&2
usage >&2
exit 2
;;
esac
done
if [[ "${FIREBASE_APPTESTING_DEBUG:-}" == "true" ]]; then
DEBUG_CLI=1
fi
if [[ -z "${FIREBASE_ANDROID_APP_ID:-}" ]]; then
echo "❌ FIREBASE_ANDROID_APP_ID is not set" >&2
exit 1
fi
if [[ ! -d "$TEST_DIR" ]]; then
echo "❌ Test directory not found: $TEST_DIR" >&2
exit 1
fi
CREDS_FILE=""
if [[ -n "${GOOGLE_APPLICATION_CREDENTIALS:-}" ]]; then
if [[ ! -f "$GOOGLE_APPLICATION_CREDENTIALS" ]]; then
echo "❌ GOOGLE_APPLICATION_CREDENTIALS is not a file: $GOOGLE_APPLICATION_CREDENTIALS" >&2
exit 1
fi
else
if [[ -z "${FIREBASE_SERVICE_ACCOUNT_JSON:-}" ]]; then
echo "❌ Set GOOGLE_APPLICATION_CREDENTIALS or FIREBASE_SERVICE_ACCOUNT_JSON" >&2
exit 1
fi
CREDS_FILE="$(mktemp)"
trap 'rm -f "$CREDS_FILE"' EXIT
printf '%s\n' "$FIREBASE_SERVICE_ACCOUNT_JSON" >"$CREDS_FILE"
export GOOGLE_APPLICATION_CREDENTIALS="$CREDS_FILE"
fi
if ! command -v firebase >/dev/null 2>&1; then
echo "❌ firebase CLI not found. Install: npm install -g firebase-tools" >&2
exit 1
fi
# Bind CLI + ADC to the same GCP project as the service account (fixes "Requesting test execution"
# failures when the default Firebase project is unset or mismatched vs App Distribution).
FIREBASE_CLI_PROJECT=""
if [[ -n "${GOOGLE_APPLICATION_CREDENTIALS:-}" ]]; then
FIREBASE_CLI_PROJECT="$(
python3 -c 'import json,sys; print(json.load(open(sys.argv[1],encoding="utf-8"))["project_id"])' \
"$GOOGLE_APPLICATION_CREDENTIALS"
)"
fi
if [[ -z "$FIREBASE_CLI_PROJECT" ]]; then
echo "❌ Could not read project_id from service account JSON" >&2
exit 1
fi
export GOOGLE_CLOUD_PROJECT="$FIREBASE_CLI_PROJECT"
export GCLOUD_PROJECT="$FIREBASE_CLI_PROJECT"
ARGS=(
apptesting:execute
"--app=$FIREBASE_ANDROID_APP_ID"
"--test-dir=$TEST_DIR"
"--test-devices=$TEST_DEVICES"
)
if [[ "$NON_BLOCKING" -eq 1 ]]; then
ARGS+=(--test-non-blocking)
fi
if [[ -n "$APK_PATH" ]]; then
if [[ ! -f "$APK_PATH" ]]; then
echo "❌ APK not found: $APK_PATH" >&2
exit 1
fi
ARGS+=("$APK_PATH")
fi
FB=(firebase --non-interactive -P "$FIREBASE_CLI_PROJECT")
if [[ "$DEBUG_CLI" -eq 1 ]]; then
FB+=(--debug)
fi
FB+=("${ARGS[@]}")
echo "Running: ${FB[*]}"
"${FB[@]}"