Skip to content

Commit fc26331

Browse files
authored
Merge pull request #9 from cloudbeds/fix/missing-workflow-id
Fix/missing workflow
2 parents a30eae0 + c403d7f commit fc26331

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

entrypoint.sh

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ api() {
102102
echo >&2 "path: $path"
103103
echo >&2 "response: $response"
104104
if [[ "$response" == *'"Server Error"'* ]]; then
105-
echo "Server error - trying again"
105+
echo >&2 "Server error - trying again"
106106
else
107107
exit 1
108108
fi
@@ -123,8 +123,18 @@ get_workflow_runs() {
123123

124124
echo "Getting workflow runs using query: ${query}" >&2
125125

126-
api "workflows/${INPUT_WORKFLOW_FILE_NAME}/runs?${query}" |
127-
jq -r '.workflow_runs[].id' |
126+
response=$(api "workflows/${INPUT_WORKFLOW_FILE_NAME}/runs?${query}")
127+
128+
# Validate response is valid JSON with workflow_runs array
129+
if ! echo "$response" | jq -e '.workflow_runs' > /dev/null 2>&1; then
130+
echo "Error: Invalid API response or missing workflow_runs" >&2
131+
echo "Response: $response" >&2
132+
return 1
133+
fi
134+
135+
echo "$response" |
136+
jq -r '.workflow_runs[].id | select(. != null) | tostring' |
137+
grep -E '^[0-9]+$' |
128138
sort # Sort to ensure repeatable order, and lexicographically for compatibility with join
129139
}
130140

@@ -139,7 +149,7 @@ trigger_workflow() {
139149
echo >&2 " {\"ref\":\"${ref}\",\"inputs\":${client_payload}}"
140150

141151
api "workflows/${INPUT_WORKFLOW_FILE_NAME}/dispatches" \
142-
--data "{\"ref\":\"${ref}\",\"inputs\":${client_payload}}"
152+
--data "{\"ref\":\"${ref}\",\"inputs\":${client_payload}}" > /dev/null
143153

144154
NEW_RUNS=$OLD_RUNS
145155
while [ "$NEW_RUNS" = "$OLD_RUNS" ]

0 commit comments

Comments
 (0)