use workflow dispatch api instead of deploy-trigger file
This commit is contained in:
+22
-17
@@ -4,6 +4,7 @@ set -euo pipefail
|
|||||||
GITEA_URL="https://git.timothykim.net"
|
GITEA_URL="https://git.timothykim.net"
|
||||||
GITEA_ORG="hantim"
|
GITEA_ORG="hantim"
|
||||||
TEMPLATE_REPO="static-site-template"
|
TEMPLATE_REPO="static-site-template"
|
||||||
|
SPINNER='⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏'
|
||||||
|
|
||||||
if [ -z "${1:-}" ]; then
|
if [ -z "${1:-}" ]; then
|
||||||
echo "Usage: ./scripts/new-app.sh <domain>"
|
echo "Usage: ./scripts/new-app.sh <domain>"
|
||||||
@@ -139,18 +140,23 @@ else
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
echo "==> Waiting for DNS to propagate..."
|
echo "==> Waiting for DNS to propagate..."
|
||||||
|
ELAPSED=0
|
||||||
for i in $(seq 1 30); do
|
for i in $(seq 1 30); do
|
||||||
RESOLVED=$(dig +short "$APP" @ns1.vultr.com 2>/dev/null)
|
RESOLVED=$(dig +short "$APP" @ns1.vultr.com 2>/dev/null)
|
||||||
if [ "$RESOLVED" = "$SERVER_IP" ]; then
|
if [ "$RESOLVED" = "$SERVER_IP" ]; then
|
||||||
echo " DNS is live."
|
printf "\r\033[K DNS is live.\n"
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
if [ "$i" = "30" ]; then
|
if [ "$i" = "30" ]; then
|
||||||
|
printf "\r\033[K"
|
||||||
echo "Error: DNS for $APP did not resolve to $SERVER_IP after 5 minutes."
|
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."
|
echo " If this is a new domain, make sure nameservers are set to Vultr on directnic.com."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
SC=${SPINNER:$(( (i - 1) % ${#SPINNER} )):1}
|
||||||
|
printf "\r %s Waiting for DNS... (%ds)" "$SC" "$ELAPSED"
|
||||||
sleep 10
|
sleep 10
|
||||||
|
ELAPSED=$((ELAPSED + 10))
|
||||||
done
|
done
|
||||||
|
|
||||||
# --- Create Gitea repo from template ---
|
# --- Create Gitea repo from template ---
|
||||||
@@ -287,29 +293,23 @@ git push
|
|||||||
# --- Trigger initial build ---
|
# --- Trigger initial build ---
|
||||||
|
|
||||||
echo "==> Triggering initial build for $APP..."
|
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
|
for i in $(seq 1 60); do
|
||||||
TRIGGER_CODE=$(curl -s -o /dev/null -w "%{http_code}" \
|
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 "Authorization: token $GITEA_TOKEN" \
|
||||||
-H "Content-Type: application/json" \
|
-H "Content-Type: application/json" \
|
||||||
-d "{\"content\": \"$(echo -n "initial deploy" | base64)\", \"message\": \"trigger initial build\"}")
|
-d '{"ref": "main"}')
|
||||||
[ "$TRIGGER_CODE" != "404" ] && break
|
[ "$TRIGGER_CODE" != "404" ] && printf "\r\033[K" && break
|
||||||
echo " Waiting for repo to be ready..."
|
SC=${SPINNER:$(( (i - 1) % ${#SPINNER} )):1}
|
||||||
|
printf "\r %s Waiting for repo to be ready... (%ds)" "$SC" "$ELAPSED"
|
||||||
sleep 2
|
sleep 2
|
||||||
|
ELAPSED=$((ELAPSED + 2))
|
||||||
done
|
done
|
||||||
|
|
||||||
if [ "$TRIGGER_CODE" = "201" ]; then
|
if [ "$TRIGGER_CODE" = "204" ]; then
|
||||||
echo " Build triggered."
|
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
|
else
|
||||||
echo " Warning: Could not trigger build (HTTP $TRIGGER_CODE). Check manually:"
|
echo " Warning: Could not trigger build (HTTP $TRIGGER_CODE). Check manually:"
|
||||||
echo " $GITEA_URL/$GITEA_ORG/$APP/actions"
|
echo " $GITEA_URL/$GITEA_ORG/$APP/actions"
|
||||||
@@ -318,13 +318,18 @@ fi
|
|||||||
# --- Verify ---
|
# --- Verify ---
|
||||||
|
|
||||||
echo "==> Waiting for deployment (up to 3 minutes)..."
|
echo "==> Waiting for deployment (up to 3 minutes)..."
|
||||||
|
ELAPSED=0
|
||||||
for i in $(seq 1 18); do
|
for i in $(seq 1 18); do
|
||||||
if curl -sf "https://www.$APP" > /dev/null 2>&1; then
|
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
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
SC=${SPINNER:$(( (i - 1) % ${#SPINNER} )):1}
|
||||||
|
printf "\r %s Waiting for site... (%ds)" "$SC" "$ELAPSED"
|
||||||
sleep 10
|
sleep 10
|
||||||
|
ELAPSED=$((ELAPSED + 10))
|
||||||
done
|
done
|
||||||
|
printf "\r\033[K"
|
||||||
|
|
||||||
echo "WARNING: https://www.$APP is not responding after 3 minutes."
|
echo "WARNING: https://www.$APP is not responding after 3 minutes."
|
||||||
echo " Check that:"
|
echo " Check that:"
|
||||||
|
|||||||
Reference in New Issue
Block a user