Skip to content

Commit 9321ed8

Browse files
committed
refactor(ci): improve reliability with trap EXIT and explicit error handling
1 parent 8181c1d commit 9321ed8

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

.kokoro/system.sh

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ run_package_test() {
6464
local gcloud_config_dir=$(mktemp -d -t "gcloud-config-${package_name}-XXXXXX")
6565
local CLOUDSDK_CONFIG="${gcloud_config_dir}"
6666

67+
# 🪤 TRAP: Ensure cleanup of THIS specific temp dir on exit of this subshell
68+
trap 'rm -rf "$gcloud_config_dir"' EXIT
69+
70+
6771
echo "------------------------------------------------------------"
6872
echo "Configuring environment for: ${package_name}"
6973
echo "------------------------------------------------------------"
@@ -101,8 +105,10 @@ run_package_test() {
101105
export PROJECT_ID GOOGLE_APPLICATION_CREDENTIALS NOX_FILE NOX_SESSION CLOUDSDK_CONFIG
102106
export GOOGLE_CLOUD_PROJECT="${PROJECT_ID}"
103107

104-
gcloud auth activate-service-account --key-file="$GOOGLE_APPLICATION_CREDENTIALS"
105-
gcloud config set project "$PROJECT_ID"
108+
# 🛡️ Explicit check: Fail early if auth fails
109+
gcloud auth activate-service-account --key-file="$GOOGLE_APPLICATION_CREDENTIALS" || return 1
110+
export CLOUDSDK_CORE_PROJECT="${PROJECT_ID}"
111+
106112

107113
# Run the actual test
108114
pushd "${package_path}" > /dev/null
@@ -112,7 +118,6 @@ run_package_test() {
112118
set -e
113119
popd > /dev/null
114120

115-
rm -rf "${gcloud_config_dir}"
116121
return $res
117122
}
118123

0 commit comments

Comments
 (0)