-
Notifications
You must be signed in to change notification settings - Fork 94
229 lines (202 loc) · 8.28 KB
/
Copy pathdeploy-staging.yml
File metadata and controls
229 lines (202 loc) · 8.28 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
# Issue #515: Staging Environment Deployment Pipeline
# Triggers on pushes to the develop branch and deploys to isolated staging
# infrastructure using Stellar Testnet for smart contract interactions.
name: Deploy to Staging
on:
push:
branches: [develop]
pull_request:
branches: [develop]
env:
STELLAR_NETWORK: testnet
STELLAR_HORIZON_URL: https://horizon-testnet.stellar.org
STELLAR_RPC_URL: https://soroban-testnet.stellar.org
BACKEND_STAGING_URL: ${{ secrets.STAGING_BACKEND_SERVICE_URL }}
FRONTEND_STAGING_URL: ${{ secrets.STAGING_FRONTEND_SERVICE_URL }}
jobs:
# ── Pre-deploy validation ──────────────────────────────────────────────
validate:
name: Validate Staging Readiness
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Verify develop branch
run: |
if [ "${{ github.ref_name }}" != "develop" ]; then
echo "::warning::Not on develop branch — skipping staging deployment"
exit 0
fi
- name: Check required secrets
run: |
required_secrets=(
"STAGING_BACKEND_DEPLOY_HOOK"
"STAGING_FRONTEND_DEPLOY_HOOK"
"STAGING_BACKEND_SERVICE_URL"
"STAGING_FRONTEND_SERVICE_URL"
)
for secret in "${required_secrets[@]}"; do
if [ -z "${{ secrets[secret] }}" ]; then
echo "::error::Missing required staging secret: $secret"
exit 1
fi
done
echo "All required staging secrets are configured."
# ── Run tests before deploying to staging ──────────────────────────────
test:
name: Run Test Suite
needs: validate
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
cache: npm
cache-dependency-path: backend/package-lock.json
- name: Install backend dependencies
run: npm ci
working-directory: backend
- name: Run backend tests
run: npm test
working-directory: backend
env:
NODE_ENV: test
ANOMALY_DETECTION_ENABLED: "false"
GEO_LIMITING_ENABLED: "false"
- name: Run backend linting
run: npm run lint:ci || true
working-directory: backend
# ── Deploy backend to staging ──────────────────────────────────────────
deploy-backend:
name: Deploy Backend (Staging)
needs: [validate, test]
if: github.ref_name == 'develop' && github.event_name == 'push'
runs-on: ubuntu-latest
outputs:
deploy_status: ${{ steps.healthcheck.outputs.status }}
backend_url: ${{ env.BACKEND_STAGING_URL }}
steps:
- name: Trigger staging backend deploy
id: deploy
run: |
curl -f -X POST "${{ secrets.STAGING_BACKEND_DEPLOY_HOOK }}"
echo "deploy_id=$(date +%s)" >> "$GITHUB_OUTPUT"
- name: Wait for deployment to stabilize
run: sleep 45
- name: Health check
id: healthcheck
run: |
echo "Checking staging backend health at ${BACKEND_STAGING_URL}/health"
for i in 1 2 3 4 5 6; do
HTTP_STATUS=$(curl -s -o /dev/null -w "%{http_code}" "${BACKEND_STAGING_URL}/health" || true)
if [ "$HTTP_STATUS" = "200" ]; then
echo "status=healthy" >> "$GITHUB_OUTPUT"
echo "Backend staging health check passed (attempt $i)"
exit 0
fi
echo "Attempt $i: status=$HTTP_STATUS, retrying in 15s..."
sleep 15
done
echo "status=unhealthy" >> "$GITHUB_OUTPUT"
echo "::error::Staging backend health check failed after 6 attempts"
exit 1
- name: Verify Stellar Testnet connectivity
run: |
echo "Verifying Stellar Testnet connectivity..."
HTTP_STATUS=$(curl -s -o /dev/null -w "%{http_code}" "${STELLAR_HORIZON_URL}/" || true)
if [ "$HTTP_STATUS" = "200" ]; then
echo "Stellar Testnet is reachable."
else
echo "::warning::Stellar Testnet returned status $HTTP_STATUS"
fi
- name: Notify deployment status
if: always()
run: |
STATUS="${{ steps.healthcheck.outputs.status || 'failed' }}"
if [ "$STATUS" = "healthy" ]; then
echo "Staging backend deployment succeeded and is healthy."
else
echo "::warning::Staging backend deployment failed or health check unsuccessful."
fi
# ── Deploy frontend to staging ─────────────────────────────────────────
deploy-frontend:
name: Deploy Frontend (Staging)
needs: [validate, deploy-backend]
if: needs.deploy-backend.outputs.deploy_status == 'healthy'
runs-on: ubuntu-latest
steps:
- name: Trigger staging frontend deploy
id: deploy
run: |
curl -f -X POST "${{ secrets.STAGING_FRONTEND_DEPLOY_HOOK }}"
echo "deploy_id=$(date +%s)" >> "$GITHUB_OUTPUT"
- name: Wait for deployment to stabilize
run: sleep 45
- name: Health check
id: healthcheck
run: |
echo "Checking staging frontend health at ${FRONTEND_STAGING_URL}"
for i in 1 2 3 4 5 6; do
HTTP_STATUS=$(curl -s -o /dev/null -w "%{http_code}" "${FRONTEND_STAGING_URL}" || true)
if [ "$HTTP_STATUS" = "200" ]; then
echo "status=healthy" >> "$GITHUB_OUTPUT"
echo "Staging frontend health check passed (attempt $i)"
exit 0
fi
echo "Attempt $i: status=$HTTP_STATUS, retrying in 15s..."
sleep 15
done
echo "status=unhealthy" >> "$GITHUB_OUTPUT"
echo "::error::Staging frontend health check failed after 6 attempts"
exit 1
- name: Notify deployment status
if: always()
run: |
STATUS="${{ steps.healthcheck.outputs.status || 'failed' }}"
if [ "$STATUS" = "healthy" ]; then
echo "Staging frontend deployment succeeded and is healthy."
else
echo "::warning::Staging frontend deployment failed or health check unsuccessful."
fi
# ── Smoke tests against staging ────────────────────────────────────────
smoke-test:
name: Staging Smoke Tests
needs: [deploy-backend, deploy-frontend]
if: needs.deploy-backend.outputs.deploy_status == 'healthy'
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
- name: Verify staging API responds
run: |
echo "Running smoke tests against staging..."
BACKEND_URL="${{ needs.deploy-backend.outputs.backend_url }}"
# Test health endpoint
HTTP_STATUS=$(curl -s -o /dev/null -w "%{http_code}" "${BACKEND_URL}/health")
if [ "$HTTP_STATUS" != "200" ]; then
echo "::error::Staging health check failed with status $HTTP_STATUS"
exit 1
fi
echo "✓ Health check passed"
# Test assets endpoint
HTTP_STATUS=$(curl -s -o /dev/null -w "%{http_code}" "${BACKEND_URL}/api/v1/rwa")
if [ "$HTTP_STATUS" != "200" ]; then
echo "::error::Staging assets endpoint failed with status $HTTP_STATUS"
exit 1
fi
echo "✓ Assets endpoint passed"
# Test GraphQL endpoint
HTTP_STATUS=$(curl -s -o /dev/null -w "%{http_code}" "${BACKEND_URL}/api/graphql?query={queryComplexity{score}}")
if [ "$HTTP_STATUS" != "200" ]; then
echo "::error::Staging GraphQL endpoint failed with status $HTTP_STATUS"
exit 1
fi
echo "✓ GraphQL endpoint passed"
echo "All smoke tests passed!"