diff --git a/coder/cloudflare-worker/main.tf b/coder/cloudflare-worker/main.tf index e69a6fc..a19bffa 100644 --- a/coder/cloudflare-worker/main.tf +++ b/coder/cloudflare-worker/main.tf @@ -490,27 +490,35 @@ resource "coder_agent" "main" { fi # --- Clone repository --- - if [ -n "$REPO_CLONE_URL" ] && [ ! -d ~/project ]; then + if [ -n "$REPO_CLONE_URL" ]; then + # Always start fresh for automated tasks to avoid stale state + rm -rf ~/project git clone "$REPO_CLONE_URL" ~/project cd ~/project # Switch to develop branch if it exists git fetch origin develop 2>/dev/null && git checkout develop 2>/dev/null || true - # Install backend deps - npm ci --legacy-peer-deps + # Install deps if package.json exists + if [ -f package.json ]; then + npm ci --legacy-peer-deps || npm ci + fi - # Install frontend deps - cd frontend && npm ci && cd .. + # Install frontend deps if present + if [ -f frontend/package.json ]; then + cd frontend && npm ci && cd .. + npm run build:frontend 2>/dev/null || true + fi - # Build frontend (required — vitest fails without frontend/dist) - npm run build:frontend + # Install Playwright if needed + if grep -q "playwright" package.json 2>/dev/null; then + npx playwright install chromium + fi - # Install Playwright Chromium - npx playwright install chromium - - # Apply local migrations - npm run db:migrate:local + # Apply local migrations if script exists + if npm run --silent db:migrate:local 2>/dev/null; then + echo "Local migrations applied" + fi fi # --- Automated task execution ---