|
| 1 | +#!/usr/bin/env bash |
| 2 | +set -euo pipefail |
| 3 | + |
| 4 | +# ────────────────────────────────────────────── |
| 5 | +# Ignition Deploy E2E Harness |
| 6 | +# Exercises: link → build → deploy against live |
| 7 | +# Ignition infrastructure. |
| 8 | +# ────────────────────────────────────────────── |
| 9 | + |
| 10 | +REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)" |
| 11 | + |
| 12 | +# ── Logging helpers ────────────────────────── |
| 13 | + |
| 14 | +log() { |
| 15 | + echo "[$(date -u '+%Y-%m-%dT%H:%M:%SZ')] $*" |
| 16 | +} |
| 17 | + |
| 18 | +log_section() { |
| 19 | + echo "" |
| 20 | + echo "════════════════════════════════════════" |
| 21 | + echo " $*" |
| 22 | + echo "════════════════════════════════════════" |
| 23 | + echo "" |
| 24 | +} |
| 25 | + |
| 26 | +run_step() { |
| 27 | + local label="$1" |
| 28 | + shift |
| 29 | + local logfile="/tmp/e2e-${label}.log" |
| 30 | + |
| 31 | + log "▶ step=${label}" |
| 32 | + log " command: $*" |
| 33 | + log " cwd: $(pwd)" |
| 34 | + |
| 35 | + if "$@" > >(tee "$logfile") 2>&1; then |
| 36 | + local rc=0 |
| 37 | + else |
| 38 | + local rc=$? |
| 39 | + fi |
| 40 | + |
| 41 | + log " exit_code=${rc}" |
| 42 | + |
| 43 | + if [ "$rc" -ne 0 ]; then |
| 44 | + log " ✗ Step '${label}' failed — last 50 lines:" |
| 45 | + tail -n 50 "$logfile" || true |
| 46 | + exit "$rc" |
| 47 | + fi |
| 48 | + |
| 49 | + log " ✓ Step '${label}' succeeded" |
| 50 | +} |
| 51 | + |
| 52 | +# ── Preflight checks ──────────────────────── |
| 53 | + |
| 54 | +log_section "Preflight" |
| 55 | + |
| 56 | +REQUIRED_VARS=( |
| 57 | + BIGCOMMERCE_STORE_HASH |
| 58 | + BIGCOMMERCE_ACCESS_TOKEN |
| 59 | + BIGCOMMERCE_STOREFRONT_TOKEN |
| 60 | + BIGCOMMERCE_CHANNEL_ID |
| 61 | + AUTH_SECRET |
| 62 | + BIGCOMMERCE_PROJECT_UUID |
| 63 | +) |
| 64 | + |
| 65 | +for var in "${REQUIRED_VARS[@]}"; do |
| 66 | + val="${!var:-}" |
| 67 | + if [ -z "$val" ]; then |
| 68 | + log "✗ Missing required env var: ${var}" |
| 69 | + exit 1 |
| 70 | + fi |
| 71 | + log " ${var} is set (${#val} chars)" |
| 72 | +done |
| 73 | + |
| 74 | +log " node: $(node --version)" |
| 75 | +log " pnpm: $(pnpm --version)" |
| 76 | +log " HOME: ${HOME}" |
| 77 | + |
| 78 | +mkdir -p "$HOME" |
| 79 | + |
| 80 | +# ── Step 1: Link ───────────────────────────── |
| 81 | + |
| 82 | +log_section "Step 1 — Link" |
| 83 | + |
| 84 | +cd "${REPO_ROOT}/core" |
| 85 | + |
| 86 | +run_step "link" pnpm catalyst link --project-uuid "$BIGCOMMERCE_PROJECT_UUID" |
| 87 | + |
| 88 | +if [ ! -f .bigcommerce/project.json ]; then |
| 89 | + log "✗ .bigcommerce/project.json was not created" |
| 90 | + exit 1 |
| 91 | +fi |
| 92 | + |
| 93 | +log " project.json exists ✓" |
| 94 | + |
| 95 | +# ── Step 2: Build ──────────────────────────── |
| 96 | + |
| 97 | +log_section "Step 2 — Build" |
| 98 | + |
| 99 | +run_step "build" pnpm catalyst build --framework catalyst |
| 100 | + |
| 101 | +if [ ! -d .bigcommerce/dist ] || [ -z "$(ls -A .bigcommerce/dist)" ]; then |
| 102 | + log "✗ .bigcommerce/dist/ is missing or empty" |
| 103 | + exit 1 |
| 104 | +fi |
| 105 | + |
| 106 | +log " dist/ is non-empty ✓" |
| 107 | + |
| 108 | +# ── Step 3: Deploy ─────────────────────────── |
| 109 | + |
| 110 | +log_section "Step 3 — Deploy" |
| 111 | + |
| 112 | +run_step "deploy" pnpm catalyst deploy \ |
| 113 | + --project-uuid "$BIGCOMMERCE_PROJECT_UUID" \ |
| 114 | + --secret "BIGCOMMERCE_STORE_HASH=$BIGCOMMERCE_STORE_HASH" \ |
| 115 | + --secret "BIGCOMMERCE_STOREFRONT_TOKEN=$BIGCOMMERCE_STOREFRONT_TOKEN" \ |
| 116 | + --secret "BIGCOMMERCE_CHANNEL_ID=$BIGCOMMERCE_CHANNEL_ID" \ |
| 117 | + --secret "AUTH_SECRET=$AUTH_SECRET" |
| 118 | + |
| 119 | +# ── Step 4: Extract deployment URL ─────────── |
| 120 | + |
| 121 | +log_section "Step 4 — Extract deployment URL" |
| 122 | + |
| 123 | +DEPLOY_URL="" |
| 124 | +if [ -f /tmp/e2e-deploy.log ]; then |
| 125 | + DEPLOY_URL=$(grep -oP 'Deployment URL: \K\S+' /tmp/e2e-deploy.log || true) |
| 126 | +fi |
| 127 | + |
| 128 | +if [ -z "$DEPLOY_URL" ]; then |
| 129 | + log "⚠ No deployment URL found in deploy output — skipping URL validation" |
| 130 | + log " (deploy succeeded; URL validation is additive)" |
| 131 | + exit 0 |
| 132 | +fi |
| 133 | + |
| 134 | +log " Deployment URL: ${DEPLOY_URL}" |
| 135 | + |
| 136 | +# ── Step 5: Validate deployment URL ────────── |
| 137 | + |
| 138 | +log_section "Step 5 — Validate deployment URL" |
| 139 | + |
| 140 | +DELAY=15 |
| 141 | +MAX_DELAY=120 |
| 142 | +MAX_ATTEMPTS=10 |
| 143 | + |
| 144 | +for attempt in $(seq 1 "$MAX_ATTEMPTS"); do |
| 145 | + log " Attempt ${attempt}/${MAX_ATTEMPTS} (delay=${DELAY}s)" |
| 146 | + sleep "$DELAY" |
| 147 | + |
| 148 | + HTTP_CODE=$(curl -s -o /tmp/e2e-url-response.txt -w '%{http_code}' "$DEPLOY_URL" || echo "000") |
| 149 | + BODY_SIZE=$(wc -c < /tmp/e2e-url-response.txt | tr -d ' ') |
| 150 | + |
| 151 | + log " HTTP ${HTTP_CODE}, body size: ${BODY_SIZE} bytes" |
| 152 | + |
| 153 | + if [ "$HTTP_CODE" = "200" ] && grep -qi '<html' /tmp/e2e-url-response.txt; then |
| 154 | + log " ✓ Deployment is live — HTTP 200 with <html marker" |
| 155 | + log " First 500 chars of response:" |
| 156 | + head -c 500 /tmp/e2e-url-response.txt |
| 157 | + echo "" |
| 158 | + exit 0 |
| 159 | + fi |
| 160 | + |
| 161 | + # Exponential backoff |
| 162 | + DELAY=$((DELAY * 2)) |
| 163 | + if [ "$DELAY" -gt "$MAX_DELAY" ]; then |
| 164 | + DELAY=$MAX_DELAY |
| 165 | + fi |
| 166 | +done |
| 167 | + |
| 168 | +log "✗ Deployment URL validation failed after ${MAX_ATTEMPTS} attempts" |
| 169 | +log " Last response (full body):" |
| 170 | +cat /tmp/e2e-url-response.txt || true |
| 171 | +exit 1 |
0 commit comments