Skip to content

Merge pull request #255 from Salt-House/Tokiya-feature #271

Merge pull request #255 from Salt-House/Tokiya-feature

Merge pull request #255 from Salt-House/Tokiya-feature #271

Workflow file for this run

name: Deploy on Push to dev
on:
push:
branches:
- dev
workflow_dispatch:
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Print the ref value (for debugging)
run: |
echo "The ref is: $GITHUB_REF"
- name: Trigger Deployment and Poll Status
run: |
# 1. 触发部署请求
# 添加 --http1.1 强制使用 HTTP/1.1 协议,避免 HTTP/2 流错误
echo "Triggering deployment..."
RESPONSE=$(curl -s --http1.1 -X POST "https://maimaimoe.cn/cd/v1/github/nextjs" \
-H "Content-Type: application/json" \
-d '{
"commit": "${{ github.sha }}",
"actor": "${{ github.actor }}",
"message": "Update from GitHub Action"
}')
echo "Trigger Response: $RESPONSE"
# 2. 提取 Job ID
JOB_ID=$(echo "$RESPONSE" | jq -r '.data.jobId')
if [ "$JOB_ID" == "null" ] || [ -z "$JOB_ID" ]; then
echo "❌ Failed to retrieve Job ID. Deployment trigger failed."
exit 1
fi
echo "✅ Deployment triggered. Job ID: $JOB_ID"
echo "Waiting for deployment to complete..."
# 3. 轮询状态
MAX_RETRIES=60
COUNT=0
while [ $COUNT -lt $MAX_RETRIES ]; do
sleep 10
# 这里也建议加上 --http1.1
STATUS_RES=$(curl -s --http1.1 "https://maimaimoe.cn/cd/v1/github/status?id=$JOB_ID")
RESULT=$(echo "$STATUS_RES" | jq -r '.data.result')
echo "[$COUNT/$MAX_RETRIES] Current Status: $RESULT"
if [[ "$RESULT" == *"Success"* ]]; then
echo "🎉 Deployment Successful!"
echo "Logs:"
echo "$RESULT"
exit 0
elif [[ "$RESULT" == *"Failed"* ]]; then
echo "❌ Deployment Failed!"
echo "Logs:"
echo "$RESULT"
exit 1
elif [[ "$RESULT" == "Pending" ]]; then
:
else
echo "Unknown status: $RESULT"
fi
COUNT=$((COUNT+1))
done
echo "❌ Deployment timed out after 10 minutes."
exit 1