-
Notifications
You must be signed in to change notification settings - Fork 0
72 lines (64 loc) · 2.35 KB
/
deploy.yml
File metadata and controls
72 lines (64 loc) · 2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
name: Deploy to OnePlus
on:
workflow_call:
inputs:
project_name:
description: "PM2 project name on the OnePlus server"
required: true
type: string
deploy_host:
description: "Deploy webhook hostname"
required: false
type: string
default: "deploy.bitroot.in"
secrets:
DEPLOY_SECRET:
description: "Shared secret for deploy-webhook authentication (HMAC-SHA256)"
required: true
jobs:
deploy:
name: Deploy ${{ inputs.project_name }}
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Trigger deploy webhook
id: deploy
run: |
PROJECT="${{ inputs.project_name }}"
HOST="${{ inputs.deploy_host }}"
SECRET="${{ secrets.DEPLOY_SECRET }}"
BODY="{\"project\":\"${PROJECT}\"}"
echo "deploying ${PROJECT} via https://${HOST}/hook ..."
RESPONSE=$(curl -sf \
--max-time 300 \
-X POST "https://${HOST}/hook" \
-H "Content-Type: application/json" \
-H "X-Deploy-Secret: ${SECRET}" \
-d "$BODY" 2>&1) || {
echo "::error::webhook request failed"
exit 1
}
echo "=== deploy output ==="
echo "$RESPONSE" | python3 -c "import sys,json; d=json.load(sys.stdin); print(d.get('output','(no output)'))" 2>/dev/null || echo "$RESPONSE"
STATUS=$(echo "$RESPONSE" | python3 -c "import sys,json; print(json.load(sys.stdin).get('status','error'))" 2>/dev/null || echo "error")
if [ "$STATUS" != "ok" ]; then
echo "::error::deploy returned status: $STATUS"
exit 1
fi
echo "deploy succeeded"
- name: Verify health check
run: |
PROJECT="${{ inputs.project_name }}"
URL="https://${PROJECT}.bitroot.in/health"
echo "checking $URL ..."
for i in $(seq 1 6); do
STATUS=$(curl -s -o /dev/null -w "%{http_code}" --max-time 10 "$URL" || echo "000")
if [ "$STATUS" = "200" ]; then
echo "health check passed (HTTP $STATUS)"
exit 0
fi
echo "attempt $i: HTTP $STATUS — retrying in 5s..."
sleep 5
done
echo "::warning::health check at $URL not responding — app may still be starting"
exit 0