diff --git a/.github/workflows/preview-env.yml b/.github/workflows/preview-env.yml index 7cad03c..7addfad 100644 --- a/.github/workflows/preview-env.yml +++ b/.github/workflows/preview-env.yml @@ -195,6 +195,42 @@ jobs: --services ${{ steps.tf-output.outputs.ecs_service }} \ --region ${{ env.AWS_REGION }} + - name: Smoke test preview URL + if: github.event.action != 'closed' + id: smoke-test + env: + PREVIEW_URL: ${{ steps.tf-output.outputs.preview_url }} + run: | + if [ -z "$PREVIEW_URL" ] || [ "$PREVIEW_URL" = "null" ]; then + echo "Preview URL missing" + echo "http_status=missing" >> "$GITHUB_OUTPUT" + echo "http_result=missing-url" >> "$GITHUB_OUTPUT" + exit 0 + fi + + # Reachability check: allow 404 (app routes might not exist yet) but fail otherwise + STATUS=$(curl --silent --output /tmp/preview.headers --write-out '%{http_code}' --head --max-time 30 "$PREVIEW_URL" || true) + + if [ "$STATUS" = "404" ]; then + echo "Preview responded with expected 404" + echo "http_status=404" >> "$GITHUB_OUTPUT" + echo "http_result=allowed-404" >> "$GITHUB_OUTPUT" + exit 0 + fi + + if [[ "$STATUS" =~ ^[0-9]{3}$ ]] && [ "$STATUS" -ge 200 ] && [ "$STATUS" -lt 400 ]; then + echo "Preview responded with status $STATUS" + echo "http_status=$STATUS" >> "$GITHUB_OUTPUT" + echo "http_result=success" >> "$GITHUB_OUTPUT" + exit 0 + fi + + echo "Preview responded with unexpected status $STATUS" + cat /tmp/preview.headers + echo "http_status=$STATUS" >> "$GITHUB_OUTPUT" + echo "http_result=unexpected-status" >> "$GITHUB_OUTPUT" + exit 0 + - name: Comment function name on PR if: github.event_name == 'pull_request' && github.event.action != 'closed' uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd @@ -207,6 +243,17 @@ jobs: const owner = context.repo.owner; const repo = context.repo.repo; const issueNumber = context.issue.number; + const smokeStatus = '${{ steps.smoke-test.outputs.http_status }}' || 'n/a'; + const smokeResult = '${{ steps.smoke-test.outputs.http_result }}' || 'not-run'; + + const smokeLabels = { + success: '✅ Passed', + 'allowed-404': '✅ Allowed 404', + 'unexpected-status': '❌ Unexpected status', + 'missing-url': '❌ Missing URL', + }; + + const smokeReadable = smokeLabels[smokeResult] ?? smokeResult; const { data: comments } = await github.rest.issues.listComments({ owner, @@ -231,6 +278,7 @@ jobs: const lines = [ '**Deployment Complete**', `- Preview URL: [${url}](${url})`, + `- Smoke Test: ${smokeReadable} (HTTP ${smokeStatus})`, `- ECS Cluster: \`${cluster}\``, `- ECS Service: \`${service}\``, `- ALB Target: \`${alb}\``,