-
Notifications
You must be signed in to change notification settings - Fork 195
Expand file tree
/
Copy pathscript.prepare
More file actions
158 lines (139 loc) · 4.52 KB
/
Copy pathscript.prepare
File metadata and controls
158 lines (139 loc) · 4.52 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
147
148
149
150
151
152
153
154
155
156
157
158
# Force plaintext token storage so acceptance tests exercise the file-backed
# cache rather than the OS keyring, which is not reliably reachable in CI.
# Tests that want to exercise the secure path or the resolver default unset
# or override this in their own script.prepare or script.
export DATABRICKS_AUTH_STORAGE=plaintext
errcode() {
# Temporarily disable 'set -e' to prevent the script from exiting on error
set +e
# Execute the provided command with all arguments
"$@"
local exit_code=$?
# Re-enable 'set -e' if it was previously set
set -e
if [ $exit_code -ne 0 ]; then
>&2 printf "\nExit code: $exit_code\n"
fi
}
musterr() {
# Temporarily disable 'set -e' to prevent the script from exiting on error
set +e
# Execute the provided command with all arguments
"$@"
local exit_code=$?
# Re-enable 'set -e'
set -e
if [ $exit_code -eq 0 ]; then
>&2 printf "\nUnexpected success\n"
exit 1
fi
}
trace() {
>&2 printf "\n>>> %s\n" "$*"
if [[ "$1" == *"="* ]]; then
# If the first argument contains '=', collect all env vars
local env_vars=()
while [[ "$1" == *"="* ]]; do
env_vars+=("$1")
shift
done
# Export environment variables in a subshell and execute the command
(
export "${env_vars[@]}"
"$@"
)
else
# Execute the command normally
"$@"
fi
return $?
}
git-repo-init() {
git init -qb main
git config core.autocrlf false
git config user.name "Tester"
git config user.email "tester@databricks.com"
git config core.hooksPath no-hooks
git add databricks.yml
git commit -qm 'Add databricks.yml'
}
title() {
local label="$1"
printf "\n=== %b" "$label"
}
withdir() {
local dir="$1"
shift
local orig_dir="$(pwd)"
cd "$dir" || return $?
"$@"
local exit_code=$?
cd "$orig_dir" || return $?
return $exit_code
}
uuid() {
python3 -c 'import uuid; print(uuid.uuid4())'
}
venv_activate() {
if [[ "$OSTYPE" == "msys" || "$OSTYPE" == "cygwin" || "$OSTYPE" == "win32" ]]; then
source .venv/Scripts/activate
else
source .venv/bin/activate
fi
}
envsubst() {
# We need to disable MSYS_NO_PATHCONV when running the python script.
# This is because the python interpreter is otherwise unable to find the python script
# when MSYS_NO_PATHCONV is enabled.
env -u MSYS_NO_PATHCONV envsubst.py
}
print_telemetry_bool_values() {
jq -r 'select(.path? == "/telemetry-ext") | (.body.protoLogs // [])[] | fromjson | ( (.entry // .) | (.databricks_cli_log.bundle_deploy_event.experimental.bool_values // []) ) | map("\(.key) \(.value)") | .[]' out.requests.txt | sort
}
sethome() {
local home="$1"
mkdir -p "$home"
# Resolve to an absolute path so HOME (and USERPROFILE) keep pointing at
# the same directory after the test cd's elsewhere. The SDK expands
# `~/.databrickscfg` against $HOME at lookup time; with a relative path
# the cfg silently disappears once the cwd changes, and helpers like
# databrickscfg.GetConfiguredDefaultProfile return "" instead of
# erroring.
#
# On Git Bash (MSYS), plain `pwd` returns Unix-style /c/... paths that
# the native Windows Go binary can't open; `pwd -W` returns the mixed
# C:/... form instead. Use the same form for both HOME and USERPROFILE
# so tests that compare a `$HOME`-based placeholder against the CLI's
# `os.UserHomeDir()` output (which reads USERPROFILE on Windows) find
# a match.
if [[ "$OSTYPE" == "msys" || "$OSTYPE" == "cygwin" || "$OSTYPE" == "win32" ]]; then
home="$(cd "$home" && pwd -W)"
else
home="$(cd "$home" && pwd)"
fi
# For macOS and Linux, use HOME.
export HOME="$home"
# For Windows, use USERPROFILE.
export USERPROFILE="$home"
}
as-test-sp() {
if [[ -z "$TEST_SP_TOKEN" ]]; then
echo "Error: TEST_SP_TOKEN is not set." >&2
return 1
fi
DATABRICKS_TOKEN="$TEST_SP_TOKEN" \
DATABRICKS_CLIENT_SECRET="" \
DATABRICKS_CLIENT_ID="" \
DATABRICKS_AUTH_TYPE="" \
"$@"
}
readplanarg() {
# Expands into "--plan <filename>" based on READPLAN env var
# Use it with "bundle deploy" to configure two runs: once with saved plan and one without.
# Note: READPLAN is specially handled in test runner so that engine=terraform/readplan is set combination is skipped.
if [[ -n "$READPLAN" ]]; then
printf -- "--plan %s" "$1"
else
printf ""
fi
}