Skip to content

Commit 7fbced3

Browse files
committed
revamping placeholder dyno restart job
1 parent 58e346e commit 7fbced3

File tree

1 file changed

+50
-5
lines changed

1 file changed

+50
-5
lines changed

.github/workflows/imports.yml

Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -316,13 +316,58 @@ jobs:
316316
runs-on: ubuntu-latest
317317
timeout-minutes: 10
318318
steps:
319-
- name: Restart Heroku dynos
319+
- name: Restart Heroku dynos and wait
320320
env:
321321
HEROKU_API_KEY: ${{ secrets.HEROKU_API_KEY }}
322322
HEROKU_APP_NAME: ${{ secrets.HEROKU_APP_NAME }}
323323
run: |
324324
echo "::add-mask::${HEROKU_API_KEY}"
325-
curl -sS -X DELETE \
326-
-H "Accept: application/vnd.heroku+json; version=3" \
327-
-H "Authorization: Bearer ${HEROKU_API_KEY}" \
328-
"https://api.heroku.com/apps/${HEROKU_APP_NAME}/dynos"
325+
set -euo pipefail
326+
base="https://api.heroku.com/apps/${HEROKU_APP_NAME}"
327+
authHeader="Authorization: Bearer ${HEROKU_API_KEY}"
328+
acceptHeader="Accept: application/vnd.heroku+json; version=3"
329+
330+
echo "Fetching current dyno state..."
331+
curl -sS -H "$acceptHeader" -H "$authHeader" "$base/dynos" | tee before.json >/dev/null
332+
333+
echo "Issuing restart (DELETE /dynos)..."
334+
http_code=$(curl -sS -o /dev/null -w "%{http_code}" -X DELETE -H "$acceptHeader" -H "$authHeader" "$base/dynos")
335+
echo "Heroku API status: ${http_code}"
336+
if [ "$http_code" != "202" ] && [ "$http_code" != "200" ]; then
337+
echo "Unexpected response from Heroku API when restarting dynos" >&2
338+
# Fetch response body for debugging
339+
curl -sS -X DELETE -H "$acceptHeader" -H "$authHeader" "$base/dynos" || true
340+
exit 1
341+
fi
342+
343+
echo "Waiting for dynos to cycle..."
344+
attempts=0
345+
max_attempts=30
346+
sleep_seconds=2
347+
changed=0
348+
while [ $attempts -lt $max_attempts ]; do
349+
sleep "$sleep_seconds"
350+
attempts=$((attempts+1))
351+
now=$(curl -sS -H "$acceptHeader" -H "$authHeader" "$base/dynos")
352+
echo "$now" > after.json
353+
# If jq is available, compare updated_at or created_at; else compare raw payloads
354+
if command -v jq >/dev/null 2>&1; then
355+
before_hash=$(jq -r 'map({name,updated_at})|tostring' before.json 2>/dev/null || echo "")
356+
after_hash=$(jq -r 'map({name,updated_at})|tostring' after.json 2>/dev/null || echo "")
357+
if [ "$before_hash" != "$after_hash" ]; then
358+
changed=1
359+
break
360+
fi
361+
else
362+
if ! diff -q before.json after.json >/dev/null 2>&1; then
363+
changed=1
364+
break
365+
fi
366+
fi
367+
done
368+
if [ $changed -eq 1 ]; then
369+
echo "Dynos changed state; restart confirmed."
370+
else
371+
echo "Dynos did not show a state change within timeout; restart may still have occurred. Showing current dynos:"
372+
cat after.json || true
373+
fi

0 commit comments

Comments
 (0)