Skip to content

Commit

Permalink
content: update
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisgrieser committed Nov 23, 2024
1 parent 8f3ce86 commit 4b73de1
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 27 deletions.
39 changes: 39 additions & 0 deletions .report-deployment-status.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env zsh
# INFO
# checks the deployment status of the latest GitHub Action run and exits either
# after a timeout or with a non-zero exit code if the deployment failed.
# Requires the `$GITHUB_TOKEN`.
#───────────────────────────────────────────────────────────────────────────────
# CONFIG
spinner="⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏"
timeout_secs=300 # = 5 minutes

#───────────────────────────────────────────────────────────────────────────────

repo=$(git remote --verbose | head -n1 | cut -d: -f2 | cut -d" " -f1)
for ((i = 1; i <= timeout_secs; i++)); do
sleep 1
last_run=$(
curl --silent -L \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $GITHUB_TOKEN" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"https://api.github.com/repos/$repo/actions/runs?per_page=1"
)
run_status=$(echo "$last_run" | grep '"status":' | cut -d'"' -f4)
[[ "$run_status" == "completed" ]] && break
pos=$((i % ${#spinner}))
printf "\r%s %s" "${spinner:$pos:1}" "$run_status"
done
printf "\r" # progress message / spinner

conclusion=$(echo "$last_run" | grep '"conclusion":' | cut -d'"' -f4)
if [[ "$run_status" != "completed" ]]; then
echo "⚠️ Timeout waiting for GitHub page deployment."
return 1
elif [[ "$conclusion" != "success" ]]; then
echo "❌ GitHub page deployment failed: $conclusion"
return 1
fi
echo "✅ GitHub page deployment successful."
return 0
32 changes: 5 additions & 27 deletions Justfile
Original file line number Diff line number Diff line change
@@ -1,38 +1,16 @@
set quiet := true

deploy-update: && notify-on-deployment-status
# streaming
deploy-update: && report-deployment-status
#!/usr/bin/env zsh
git add --all &&
git commit --message="content: update" &&
git push --no-progress
[[ $? -ne 0 ]] && return 1
notify-on-deployment-status:
#!/usr/bin/env zsh
spinner="⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏"
for i in {1..150}; do
sleep 2 # timeout: 150 x 2 = 300 seconds = 5 minutes
last_run=$(curl --silent -L \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $GITHUB_TOKEN" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"https://api.github.com/repos/chrisgrieser/chrisgrieser.github.io/actions/runs?per_page=1"
)
run_status=$(echo "$last_run" | grep '"status":' | cut -d'"' -f4)
[[ "$run_status" == "completed" ]] && break
pos=$((i % ${#spinner}))
printf "\r%s %s" "${spinner:$pos:1}" "$run_status"
done
printf "\r" # remove spinner
conclusion=$(echo "$last_run" | grep '"conclusion":' | cut -d'"' -f4)
if [[ "$run_status" != "completed" ]]; then
echo "Timeout waiting for GitHub page deployment."
return 1
elif [[ "$conclusion" != "success" ]]; then
echo "GitHub page deployment failed: $conclusion"
return 1
fi
echo "GitHub page deployment successful."
# streaming
report-deployment-status:
./.report-deployment-status.sh

#───────────────────────────────────────────────────────────────────────────────

Expand Down

0 comments on commit 4b73de1

Please sign in to comment.