-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathrun-task.sh
More file actions
executable file
·65 lines (56 loc) · 2.64 KB
/
Copy pathrun-task.sh
File metadata and controls
executable file
·65 lines (56 loc) · 2.64 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
#!/usr/bin/env bash
# Execute one trusted task bundle through the harness workflow runner.
set -euo pipefail
umask 077
cd "$(dirname "$0")/.."
workflow_file="${1:?usage: run-task.sh WORKFLOW OUTPUT_DIR RESULT_FILE}"
output_dir="${2:?usage: run-task.sh WORKFLOW OUTPUT_DIR RESULT_FILE}"
result_file="${3:?usage: run-task.sh WORKFLOW OUTPUT_DIR RESULT_FILE}"
[[ "$output_dir" == /* && "$result_file" == /* ]] || {
echo "task output and result paths must be absolute" >&2
exit 1
}
[[ "$workflow_file" != /* && "$workflow_file" != *..* ]] || {
echo "task workflow must be a trusted repository-relative path" >&2
exit 1
}
gateway="${OPENSHELL_GATEWAY:-openshell}"
workspace="${OPENSHELL_WORKSPACE:-}"
task_timeout="${TASK_TIMEOUT:-8m}"
kill_after="${TASK_KILL_AFTER:-35s}"
[[ "$task_timeout" =~ ^[0-9]+[smh]$ && "$kill_after" =~ ^[0-9]+[smh]$ ]] || {
echo "TASK_TIMEOUT and TASK_KILL_AFTER must be durations such as 8m or 35s" >&2
exit 1
}
check_required_providers() {
local required="${TASK_PROVIDERS:-[]}"
mkdir -p "$output_dir"
if ! jq -e 'type == "array" and all(.[]; type == "string" and test("^[A-Za-z0-9][A-Za-z0-9_.-]{0,62}$"))' <<< "$required" >/dev/null; then
echo "TASK_PROVIDERS must be a JSON array of provider names" >&2
exit 1
fi
local report="$output_dir/provider-check.json"
local provider
local provider_args=(--gateway "$gateway")
[[ -n "$workspace" ]] && provider_args+=(--workspace "$workspace")
if jq -e 'length == 0' <<< "$required" >/dev/null; then
jq -n --arg gateway "$gateway" --arg workspace "$workspace" \
'{status:"skipped", gateway:$gateway, workspace:$workspace, providers:[]}' > "$report"
return
fi
while IFS= read -r provider; do
if ! timeout 60s openshell provider get "${provider_args[@]}" "$provider" >/dev/null 2>&1; then
jq -n --arg gateway "$gateway" --arg workspace "$workspace" --arg provider "$provider" \
'{status:"failed", gateway:$gateway, workspace:$workspace, missing:[$provider]}' > "$report"
echo "required OpenShell provider is unavailable: $provider (gateway=$gateway workspace=${workspace:-default})" >&2
exit 1
fi
done < <(jq -r '.[]' <<< "$required")
jq -n --arg gateway "$gateway" --arg workspace "$workspace" --argjson providers "$required" \
'{status:"available", gateway:$gateway, workspace:$workspace, providers:$providers}' > "$report"
}
check_required_providers
args=(workflow apply "$workflow_file" --output-dir "$output_dir" --result-file "$result_file")
[[ -n "$gateway" ]] && args+=(--gateway "$gateway")
[[ -n "$workspace" ]] && args+=(--workspace "$workspace")
exec timeout -s TERM -k "$kill_after" "$task_timeout" ./harness "${args[@]}"