-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpublish-event.sh
More file actions
executable file
·47 lines (40 loc) · 1.42 KB
/
publish-event.sh
File metadata and controls
executable file
·47 lines (40 loc) · 1.42 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
#!/bin/bash
# shellcheck disable=SC2155
readonly event_name=$1
readonly url="$SPRINTERS_RUNNER_WEBHOOK"
if [ -z "$url" ]; then
echo "Skipping event publishing for event: $event_name"
exit 0
fi
get_env_value_string() {
local var_name="$1"
if [[ -n "${!var_name+x}" ]]; then
echo "\"${!var_name}\""
else
echo "null"
fi
}
get_env_value_number() {
local var_name="$1"
if [[ -n "${!var_name+x}" ]]; then
echo "${!var_name}"
else
echo "null"
fi
}
readonly event="\"event\":\"$event_name\""
readonly hostname="\"hostname\":\"$(hostname)\""
readonly timestamp="\"timestamp\":\"$(date -u -Ins | tr ',' '.' | cut -c1-23)Z\""
readonly runner_name="\"runner_name\":$(get_env_value_string RUNNER_NAME)"
readonly repository_id="\"repository_id\":$(get_env_value_number GITHUB_REPOSITORY_ID)"
readonly workflow_run_id="\"workflow_run_id\":$(get_env_value_number GITHUB_RUN_ID)"
readonly workflow_run_attempt="\"workflow_run_attempt\":$(get_env_value_number GITHUB_RUN_ATTEMPT)"
uuid=$(cat /proc/sys/kernel/random/uuid)
payload="{$event,$hostname,$timestamp,$runner_name,$repository_id,$workflow_run_id,$workflow_run_attempt}"
sha256=$(printf "%s" "$payload" | sha256sum | awk '{print $1}')
curl -s -k "$url" --connect-timeout 3 \
-H "Content-Type: application/json" \
-H "X-Runner-Delivery: $uuid" \
-H "X-Runner-Action: event" \
-H "X-Runner-Sha256: $sha256" \
-d "$payload" || echo "$event event publishing failed"