use workflow dispatch api instead of deploy-trigger file

This commit is contained in:
2026-03-16 21:54:19 -04:00
parent 126061bbcb
commit 98aa8e7727
+22 -17
View File
@@ -4,6 +4,7 @@ set -euo pipefail
GITEA_URL="https://git.timothykim.net"
GITEA_ORG="hantim"
TEMPLATE_REPO="static-site-template"
SPINNER='⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏'
if [ -z "${1:-}" ]; then
echo "Usage: ./scripts/new-app.sh <domain>"
@@ -139,18 +140,23 @@ else
fi
echo "==> Waiting for DNS to propagate..."
ELAPSED=0
for i in $(seq 1 30); do
RESOLVED=$(dig +short "$APP" @ns1.vultr.com 2>/dev/null)
if [ "$RESOLVED" = "$SERVER_IP" ]; then
echo " DNS is live."
printf "\r\033[K DNS is live.\n"
break
fi
if [ "$i" = "30" ]; then
printf "\r\033[K"
echo "Error: DNS for $APP did not resolve to $SERVER_IP after 5 minutes."
echo " If this is a new domain, make sure nameservers are set to Vultr on directnic.com."
exit 1
fi
SC=${SPINNER:$(( (i - 1) % ${#SPINNER} )):1}
printf "\r %s Waiting for DNS... (%ds)" "$SC" "$ELAPSED"
sleep 10
ELAPSED=$((ELAPSED + 10))
done
# --- Create Gitea repo from template ---
@@ -287,29 +293,23 @@ git push
# --- Trigger initial build ---
echo "==> Triggering initial build for $APP..."
# Wait for template repo to be ready (Gitea generates content asynchronously)
# Wait for template repo to be ready, then dispatch the build workflow
ELAPSED=0
for i in $(seq 1 60); do
TRIGGER_CODE=$(curl -s -o /dev/null -w "%{http_code}" \
-X POST "$GITEA_URL/api/v1/repos/$GITEA_ORG/$APP/contents/.deploy-trigger" \
-X POST "$GITEA_URL/api/v1/repos/$GITEA_ORG/$APP/actions/workflows/build.yml/dispatches" \
-H "Authorization: token $GITEA_TOKEN" \
-H "Content-Type: application/json" \
-d "{\"content\": \"$(echo -n "initial deploy" | base64)\", \"message\": \"trigger initial build\"}")
[ "$TRIGGER_CODE" != "404" ] && break
echo " Waiting for repo to be ready..."
-d '{"ref": "main"}')
[ "$TRIGGER_CODE" != "404" ] && printf "\r\033[K" && break
SC=${SPINNER:$(( (i - 1) % ${#SPINNER} )):1}
printf "\r %s Waiting for repo to be ready... (%ds)" "$SC" "$ELAPSED"
sleep 2
ELAPSED=$((ELAPSED + 2))
done
if [ "$TRIGGER_CODE" = "201" ]; then
if [ "$TRIGGER_CODE" = "204" ]; then
echo " Build triggered."
elif [ "$TRIGGER_CODE" = "422" ]; then
# File already exists — update it to trigger a new build
EXISTING_SHA=$(curl -s "$GITEA_URL/api/v1/repos/$GITEA_ORG/$APP/contents/.deploy-trigger" \
-H "Authorization: token $GITEA_TOKEN" | jq -r '.sha')
curl -s -o /dev/null -X PUT "$GITEA_URL/api/v1/repos/$GITEA_ORG/$APP/contents/.deploy-trigger" \
-H "Authorization: token $GITEA_TOKEN" \
-H "Content-Type: application/json" \
-d "{\"content\": \"$(echo -n "redeploy $(date +%s)" | base64)\", \"sha\": \"$EXISTING_SHA\", \"message\": \"trigger rebuild\"}"
echo " Build re-triggered (file already existed)."
else
echo " Warning: Could not trigger build (HTTP $TRIGGER_CODE). Check manually:"
echo " $GITEA_URL/$GITEA_ORG/$APP/actions"
@@ -318,13 +318,18 @@ fi
# --- Verify ---
echo "==> Waiting for deployment (up to 3 minutes)..."
ELAPSED=0
for i in $(seq 1 18); do
if curl -sf "https://www.$APP" > /dev/null 2>&1; then
echo "Site is live at https://www.$APP"
printf "\r\033[K Site is live at https://www.$APP\n"
exit 0
fi
SC=${SPINNER:$(( (i - 1) % ${#SPINNER} )):1}
printf "\r %s Waiting for site... (%ds)" "$SC" "$ELAPSED"
sleep 10
ELAPSED=$((ELAPSED + 10))
done
printf "\r\033[K"
echo "WARNING: https://www.$APP is not responding after 3 minutes."
echo " Check that:"