-
Notifications
You must be signed in to change notification settings - Fork 0
129 lines (112 loc) · 4.35 KB
/
deploy.yml
File metadata and controls
129 lines (112 loc) · 4.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
name: CD Pipeline
on:
workflow_run:
workflows: ["CI Pipeline"]
branches: [main]
types: [completed]
workflow_dispatch:
inputs:
deploy_backend:
description: 'Deploy backend to Render?'
required: true
default: true
type: boolean
deploy_frontend:
description: 'Deploy frontend to Vercel?'
required: true
default: true
type: boolean
permissions:
contents: read
jobs:
deploy-backend:
name: 🚀 Deploy Backend → Render
runs-on: ubuntu-latest
timeout-minutes: 20
if: >
(github.event_name == 'workflow_dispatch') ||
(github.event_name == 'workflow_run' && github.event.workflow_run.conclusion == 'success')
steps:
- uses: actions/checkout@v4
- name: Check required secrets
run: |
if [ -z "${{ secrets.RENDER_DEPLOY_HOOK_URL }}" ]; then
echo "❌ Secret RENDER_DEPLOY_HOOK_URL is not set."
echo " Add it at: Settings → Secrets → Actions → New repository secret"
exit 1
fi
echo "✅ RENDER_DEPLOY_HOOK_URL is configured"
- name: Trigger Render deploy webhook
run: |
curl -X POST "${{ secrets.RENDER_DEPLOY_HOOK_URL }}" \
-H "Content-Type: application/json" \
--fail-with-body
- name: Confirm deploy trigger
run: |
echo "Deploy triggered successfully on Render"
echo "Monitor deploy at: https://dashboard.render.com"
- name: Health check — wait for backend
continue-on-error: true
run: |
MAX_ATTEMPTS=40
ATTEMPT=0
WAIT_SECONDS=20
echo "Aguardando backend ficar disponível (pode levar até ~13 min no Render free tier)..."
while [ $ATTEMPT -lt $MAX_ATTEMPTS ]; do
ATTEMPT=$((ATTEMPT + 1))
echo "Tentativa $ATTEMPT/$MAX_ATTEMPTS..."
HTTP_STATUS=$(curl -s -o /dev/null -w "%{http_code}" \
--max-time 15 \
https://dataforgetest-backend.onrender.com/ || echo "000")
if [ "$HTTP_STATUS" = "200" ]; then
echo "✅ Backend disponível! Status: $HTTP_STATUS"
exit 0
fi
echo "Status: $HTTP_STATUS — aguardando ${WAIT_SECONDS}s..."
sleep $WAIT_SECONDS
done
echo "⚠️ Backend não respondeu após ${MAX_ATTEMPTS} tentativas — deploy foi triggerado, verifique o Render dashboard"
exit 0
deploy-frontend:
name: 🌐 Deploy Frontend → Vercel
runs-on: ubuntu-latest
timeout-minutes: 10
if: >
(github.event_name == 'workflow_dispatch') ||
(github.event_name == 'workflow_run' && github.event.workflow_run.conclusion == 'success')
steps:
- uses: actions/checkout@v4
- name: Check required secrets
run: |
MISSING=""
[ -z "${{ secrets.VERCEL_TOKEN }}" ] && MISSING="$MISSING VERCEL_TOKEN"
[ -z "${{ secrets.VERCEL_ORG_ID }}" ] && MISSING="$MISSING VERCEL_ORG_ID"
[ -z "${{ secrets.VERCEL_PROJECT_ID }}" ] && MISSING="$MISSING VERCEL_PROJECT_ID"
if [ -n "$MISSING" ]; then
echo "❌ Missing secrets:$MISSING"
echo " Add them at: Settings → Secrets → Actions → New repository secret"
exit 1
fi
echo "✅ All Vercel secrets are configured"
- name: Deploy to Vercel
env:
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
run: |
# Pull project settings from Vercel (respects rootDirectory configured on the dashboard)
npx vercel pull --yes --environment=production \
--token=${{ secrets.VERCEL_TOKEN }}
# Build using project settings (rootDirectory=frontend is applied automatically)
npx vercel build --prod \
--token=${{ secrets.VERCEL_TOKEN }}
# Deploy the pre-built output
npx vercel deploy --prebuilt --prod \
--token=${{ secrets.VERCEL_TOKEN }}
- name: Verify Vercel deploy
run: |
echo "✅ Frontend deployed to https://data-forge-test.vercel.app"
curl -f https://data-forge-test.vercel.app/ \
--max-time 30 \
-o /dev/null \
-s \
-w "HTTP Status: %{http_code}\n"