-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathentrypoint
More file actions
executable file
·63 lines (47 loc) · 1.71 KB
/
entrypoint
File metadata and controls
executable file
·63 lines (47 loc) · 1.71 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
#!/bin/bash
CLEAN_CONTEXT=$(echo "$NP_ACTION_CONTEXT" | sed "s/^'//;s/'$//")
export NP_ACTION_CONTEXT="$CLEAN_CONTEXT"
CURRENT_DIR=$(dirname "${BASH_SOURCE[0]}")
cd "$CURRENT_DIR" && cd ..
TOKEN=$(np token create --body "{\"api_key\": \"$NP_API_KEY\"}" --format json | jq -r .access_token)
CALLBACK_URL=$(echo "$NP_ACTION_CONTEXT" | jq -r .notification.callback_url)
logs=$(np service workflow exec --workflow workflows/create_app.yaml)
EXIT_CODE=$?
# Determine status based on exit code
if [ $EXIT_CODE -eq 0 ]; then
STATUS="success"
else
STATUS="failed"
fi
timestamp=$(($(date +%s) * 1000))
messages=$(echo "$logs" | while IFS= read -r line; do
[[ -z "$line" ]] && continue
if [[ "$line" =~ "failed" ]] || [[ "$line" =~ "ERROR" ]] || [[ "$line" =~ "error" ]]; then
level="ERROR"
elif [[ "$line" =~ "warning" ]] || [[ "$line" =~ "WARNING" ]] || [[ "$line" =~ "warn" ]]; then
level="WARNING"
else
level="INFO"
fi
jq -n \
--arg level "$level" \
--arg message "$line" \
--arg ts "$timestamp" \
'{level: $level, message: $message, timestamp: ($ts | tonumber)}'
done | jq -s '.')
payload=$(jq -n \
--arg status "$STATUS" \
--argjson messages "$messages" \
'{status: $status, messages: $messages}')
echo "$payload" | jq .
echo "Updating hook with status: $STATUS. URL: $CALLBACK_URL"
# Call the callback URL with the status
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" -X PATCH "$CALLBACK_URL" \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d "$payload")
if [ "$HTTP_CODE" -ge 200 ] && [ "$HTTP_CODE" -lt 300 ]; then
echo "✓ Successfully updated hook (HTTP $HTTP_CODE)"
else
echo "✗ Failed to update hook (HTTP $HTTP_CODE)"
fi