-
Notifications
You must be signed in to change notification settings - Fork 504
ci: add preview smoke test for frontend PRs #7192
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
ed309f9
b2abd51
948edc5
d10f1e5
b52e839
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,7 @@ on: | |
|
|
||
| permissions: | ||
| contents: read | ||
| deployments: read | ||
|
|
||
| jobs: | ||
| unit-tests: | ||
|
|
@@ -34,3 +35,72 @@ jobs: | |
|
|
||
| - 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') | ||
|
Comment on lines
+62
to
+64
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could merge these 2 calls into 1 |
||
| 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 | ||
|
Comment on lines
+75
to
+78
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a way to have a warning or maybe a non-blocking error in this case ? |
||
|
|
||
| # Smoke test the deployment | ||
| echo "🔍 Testing $URL/health ..." | ||
| STATUS=$(curl -s -o /dev/null -w '%{http_code}' "$URL/health") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe add timeouts on the curls to not hang indefinitely |
||
| 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" | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe a job timeout-minutes (10 minutes should be enough giiven last one ran in 8seconds 😄 )