Skip to content

Commit aa445b0

Browse files
fix: use github token correctly
Fixes the -H parameter recognition by curl Signed-off-by: Tiago Castro <[email protected]>
1 parent d24ff3a commit aa445b0

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

wait-for-workflow.sh

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,17 @@ counter=0
2121

2222
# Get the current time in ISO 8601 format
2323
current_time=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
24-
start_time=${START_TIME:-$current_time}
24+
yesterday=$(date -u -d "yesterday" +"%Y-%m-%dT%H:%M:%SZ")
25+
start_time=${START_TIME:-$yesterday}
2526

2627
# Check if REF has the prefix "refs/heads/" and append it if not
2728
if [[ ! "$REF" =~ ^refs/heads/ ]]; then
2829
REF="refs/heads/$REF"
2930
fi
3031

31-
GITHUB_AUTH=
32+
HEADERS=(-H "Accept: application/vnd.github+json")
3233
if [ -n "${GITHUB_TOKEN:-}" ]; then
33-
GITHUB_AUTH="-H \"Authorization: token $GITHUB_TOKEN\""
34+
HEADERS+=(-H "Authorization: token $GITHUB_TOKEN")
3435
fi
3536

3637
echo "ℹ️ Organization: ${ORG_NAME}"
@@ -40,6 +41,9 @@ echo "ℹ️ Timeout to find the workflow: ${max_find_minutes} minutes"
4041
echo "ℹ️ Timeout for the workflow to complete: ${timeout} minutes"
4142
echo "ℹ️ Interval between checks: ${interval} seconds"
4243

44+
echo "ℹ️ Worflow Start Time: $start_time"
45+
echo "ℹ️ Current Time: $current_time"
46+
4347
# If RUN_ID is not empty, use it directly
4448
if [ -n "${RUN_ID:-}" ]; then
4549
run_id="${RUN_ID}"
@@ -51,7 +55,7 @@ else
5155
# Wait for the workflow to be triggered
5256
while true; do
5357
echo "⏳ Waiting for the workflow to be found..."
54-
response=$(curl -s -H "Accept: application/vnd.github+json" $GITHUB_AUTH \
58+
response=$(curl -s "${HEADERS[@]}" \
5559
"https://api.github.com/repos/${ORG_NAME}/${REPO_NAME}/actions/workflows/${workflow_id}/runs")
5660
if echo "$response" | grep -q "API rate limit exceeded"; then
5761
echo "❌ API rate limit exceeded. Please try again later."
@@ -95,7 +99,7 @@ fi
9599
timeout_counter=0
96100
while true; do
97101
echo "⌛ Waiting for the workflow to complete..."
98-
run_data=$(curl -s -H "Accept: application/vnd.github+json" $GITHUB_AUTH \
102+
run_data=$(curl -s "${HEADERS[@]}" \
99103
"https://api.github.com/repos/${ORG_NAME}/${REPO_NAME}/actions/runs/$run_id")
100104
status=$(echo "$run_data" | jq -r '.status')
101105

0 commit comments

Comments
 (0)