-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathro
More file actions
executable file
·183 lines (149 loc) · 6.17 KB
/
ro
File metadata and controls
executable file
·183 lines (149 loc) · 6.17 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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#!/bin/bash
# ======================================================================================
# Synopsis: Shorthand for robot run command that outputs logs to a standard location
# for viewing at localhost:3000
# ======================================================================================
function show_help() {
cat << EOF
ro - RunWhen Robot Framework Execution Utility
SYNOPSIS:
ro [OPTIONS] [TARGET]
DESCRIPTION:
A wrapper around the robot command that sets up isolated execution environments
with proper configuration copying for cloud CLIs (Azure, GCP, Kubernetes).
ARGUMENTS:
TARGET Robot file or directory to execute (default: current directory)
Examples: runbook.robot, sli.robot, .
OPTIONS:
--test NAME Execute specific test case by name
--help, -h Show this help message
ENVIRONMENT SETUP:
The utility automatically creates an isolated working directory and copies:
- Azure CLI configuration (~/.azure → AZURE_CONFIG_DIR)
- Azure DevOps CLI configuration (~/.azure-devops → AZURE_DEVOPS_CONFIG_DIR)
- Google Cloud SDK configuration (~/.gcloud → CLOUDSDK_CONFIG)
- Kubernetes configuration (~/.kube → KUBECONFIG)
EXAMPLES:
ro # Run all .robot files in current directory
ro runbook.robot # Run specific robot file
ro --test "Check Health" # Run specific test case
ro ../other-codebundle/ # Run tests in different directory
OUTPUT:
Logs are written to \$ROBOT_LOG_DIR with HTML reports for viewing at localhost:3000
EOF
}
# Check for help flags
if [[ "$1" == "--help" || "$1" == "-h" ]]; then
show_help
exit 0
fi
TMPDIR="${TMPDIR:-/tmp/runwhen}"
export RW_MODE="${RW_MODE:-dev}"
function ro () {
# If no arguments given, pretend the user typed '.'
if [ $# -eq 0 ]; then
set -- "."
fi
# We'll parse --test arguments first, but we really only need the final target later
TASKS=()
POSITIONAL=()
while [[ $# -gt 0 ]]; do
case "$1" in
--test)
if [ -n "$2" ]; then
TASKS+=("--test" "$2")
shift 2
else
echo "Error: --test requires an argument."
exit 1
fi
;;
*)
POSITIONAL+=("$1")
shift
;;
esac
done
set -- "${POSITIONAL[@]}" # restore positional parameters
# The last positional argument is our "execution target"
ROBOT_FILE_EXECUTING=${!#}
# --------------------------------------------------------------------
# 1) Expand that target to a full path, then see if it's a file/dir
# --------------------------------------------------------------------
real_target="$(realpath "$ROBOT_FILE_EXECUTING")"
if [ -d "$real_target" ]; then
# It's a directory
RW_SLX="$(basename "$real_target")"
RW_RFNS="all"
else
# It's presumably a file (like 'runbook.robot')
dir_of_target="$(dirname "$real_target")"
RW_SLX="$(basename "$dir_of_target")"
RW_RFNS="$(basename "$real_target")"
fi
export RW_SLX RW_RFNS
echo "[DEBUG] RW_SLX='${RW_SLX}', RW_RFNS='${RW_RFNS}'"
# --------------------------------------------------------------------
# 2) Construct a working directory based on RW_SLX / RW_RFNS
# --------------------------------------------------------------------
runwhen_workdir="${TMPDIR}/${RW_SLX}/${RW_RFNS}"
mkdir -p "${runwhen_workdir}"
echo "RUNWHEN_WORKDIR set to: ${runwhen_workdir}"
# Create subdirectories for each CLI/tool
azure_config_dir="${runwhen_workdir}/.azure"
mkdir -p "${azure_config_dir}"
azure_devops_config_dir="${runwhen_workdir}/.azure-devops"
mkdir -p "${azure_devops_config_dir}"
gcloud_config_dir="${runwhen_workdir}/.gcloud"
mkdir -p "${gcloud_config_dir}"
codebundle_temp_dir="${runwhen_workdir}/cb-temp"
mkdir -p "${codebundle_temp_dir}"
kube_config_dir="${runwhen_workdir}/.kube"
mkdir -p "${kube_config_dir}"
kubeconfig_path="${kube_config_dir}/config"
# Copy existing configurations if they exist
if [ -d "$HOME/.azure" ]; then
cp -r "$HOME/.azure"/* "${azure_config_dir}/" 2>/dev/null || true
echo "Copied Azure CLI config to: ${azure_config_dir}"
fi
if [ -d "$HOME/.azure-devops" ]; then
cp -r "$HOME/.azure-devops"/* "${azure_devops_config_dir}/" 2>/dev/null || true
echo "Copied Azure DevOps CLI config to: ${azure_devops_config_dir}"
fi
# Export environment variables
export AZURE_CONFIG_DIR="${azure_config_dir}"
echo "AZURE_CONFIG_DIR set to: ${AZURE_CONFIG_DIR}"
export AZURE_DEVOPS_CONFIG_DIR="${azure_devops_config_dir}"
echo "AZURE_DEVOPS_CONFIG_DIR set to: ${AZURE_DEVOPS_CONFIG_DIR}"
export CLOUDSDK_CONFIG="${gcloud_config_dir}"
echo "CLOUDSDK_CONFIG set to: ${CLOUDSDK_CONFIG}"
export CODEBUNDLE_TEMP_DIR="${codebundle_temp_dir}"
echo "CODEBUNDLE_TEMP_DIR set to: ${CODEBUNDLE_TEMP_DIR}"
export KUBECONFIG="${kubeconfig_path}"
echo "KUBECONFIG set to: ${KUBECONFIG}"
# --------------------------------------------------------------------
# 3) Figure out Robot output directory (depends on $ROBOT_LOG_DIR, etc.)
# --------------------------------------------------------------------
# Use your existing logic. For example:
if [ -d "$real_target" ]; then
# All .robot in directory
OUTPUT_DIR="$ROBOT_LOG_DIR/$RW_SLX"
TYPE="codebundle"
else
# Single .robot file
OUTPUT_DIR="$ROBOT_LOG_DIR/$RW_SLX"
TYPE="$(basename "$real_target" .robot)"
fi
echo "[DEBUG] Robot logs => $OUTPUT_DIR (TYPE='${TYPE}')"
# --------------------------------------------------------------------
# 4) Finally run Robot
# --------------------------------------------------------------------
robot --loglevel trace \
--outputdir "$OUTPUT_DIR" \
--log "${TYPE}-log.html" \
--output "${TYPE}-output.xml" \
--report "${TYPE}-report.html" \
"${TASKS[@]}" \
"${POSITIONAL[@]}"
}
ro "$@"