-
Notifications
You must be signed in to change notification settings - Fork 515
106 lines (89 loc) · 3.41 KB
/
frontend-pull-request.yml
File metadata and controls
106 lines (89 loc) · 3.41 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
name: Frontend Pull Requests
on:
pull_request:
types: [opened, synchronize, reopened, ready_for_review]
paths:
- frontend/**
- .github/workflows/frontend-pull-request.yml
permissions:
contents: read
deployments: read
jobs:
unit-tests:
name: Unit Tests
runs-on: ubuntu-latest
defaults:
run:
working-directory: frontend
steps:
- uses: actions/checkout@v5
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version-file: frontend/.nvmrc
cache: npm
cache-dependency-path: frontend/package-lock.json
- name: Install dependencies
run: npm ci
- name: Run unit tests
run: npm run test:unit -- --passWithNoTests
smoke-test:
name: Vercel Preview Smoke Test
runs-on: ubuntu-latest
steps:
- name: Wait for Vercel deployments and smoke test
env:
GH_TOKEN: ${{ github.token }}
SHA: ${{ github.event.pull_request.head.sha }}
REPO: ${{ github.repository }}
run: |
ENVIRONMENTS=(
"Preview – flagsmith-frontend-preview"
"Preview – flagsmith-frontend-staging"
)
for ENV_NAME in "${ENVIRONMENTS[@]}"; do
echo "⏳ Waiting for '$ENV_NAME' deployment..."
URL=""
for i in $(seq 1 60); do
# Find the deployment for this commit and environment
DEPLOY_ID=$(gh api "repos/$REPO/deployments?sha=$SHA&environment=$(printf '%s' "$ENV_NAME" | jq -sRr @uri)&per_page=1" --jq '.[0].id // empty')
if [ -n "$DEPLOY_ID" ]; then
STATE=$(gh api "repos/$REPO/deployments/$DEPLOY_ID/statuses?per_page=1" --jq '.[0].state // empty')
if [ "$STATE" = "success" ]; then
URL=$(gh api "repos/$REPO/deployments/$DEPLOY_ID/statuses?per_page=1" --jq '.[0].environment_url')
echo "✅ '$ENV_NAME' deployed at: $URL"
break
elif [ "$STATE" = "failure" ] || [ "$STATE" = "error" ]; then
echo "❌ '$ENV_NAME' deployment failed with state: $STATE"
exit 1
fi
fi
sleep 10
done
if [ -z "$URL" ]; then
echo "⚠️ Timed out waiting for '$ENV_NAME' — skipping"
continue
fi
# Smoke test the deployment
echo "🔍 Testing $URL/health ..."
STATUS=$(curl -s -o /dev/null -w '%{http_code}' "$URL/health")
if [ "$STATUS" != "200" ]; then
echo "❌ /health returned $STATUS"
exit 1
fi
echo "🔍 Testing $URL/config/project-overrides ..."
STATUS=$(curl -s -o /dev/null -w '%{http_code}' "$URL/config/project-overrides")
if [ "$STATUS" != "200" ]; then
echo "❌ /config/project-overrides returned $STATUS"
exit 1
fi
echo "🔍 Testing $URL/ ..."
STATUS=$(curl -s -o /dev/null -w '%{http_code}' "$URL/")
if [ "$STATUS" != "200" ]; then
echo "❌ / returned $STATUS (this is the index page served by the Express server)"
exit 1
fi
echo "✅ All smoke tests passed for '$ENV_NAME'"
echo ""
done
echo "🎉 All Vercel preview deployments are healthy"