Skip to content
Merged
117 changes: 117 additions & 0 deletions .github/workflows/copilot-setup-steps.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
name: "Copilot Setup Steps"

on:
workflow_dispatch:
push:
paths:
- .github/workflows/copilot-setup-steps.yml
pull_request:
paths:
- .github/workflows/copilot-setup-steps.yml

jobs:
copilot-setup-steps:
runs-on: ubuntu-latest
timeout-minutes: 30
permissions:
contents: read

steps:
- name: Checkout code
uses: actions/checkout@v5

# Engines: Node >=20, npm >=10
- name: Set up Node 20
uses: actions/setup-node@v4
with:
node-version: "20"
Comment on lines +23 to +27
Copy link

Copilot AI Nov 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the coding guidelines, Node.js version should be 18.x or higher, but the project specifically targets 18.x. The workflow uses Node 20, which may introduce compatibility issues. Consider using Node 18 to match the documented tech stack requirement.

Suggested change
# Engines: Node >=20, npm >=10
- name: Set up Node 20
uses: actions/setup-node@v4
with:
node-version: "20"
# Engines: Node >=18, npm >=10
- name: Set up Node 18
uses: actions/setup-node@v4
with:
node-version: "18"

Copilot uses AI. Check for mistakes.
cache: "npm"

- name: Use npm 10 (per package.json engines)
run: npm i -g npm@10

- name: Copy env file
run: |
if [ -f ".env.example" ]; then
cp .env.example .env
fi

- name: Install dependencies
run: npm ci

# ---------- Playwright MCP (system deps + browsers) ----------
- name: Install Playwright deps & browsers
if: ${{ hashFiles('playwright.config.*') != '' || hashFiles('.playwright-mcp/**') != '' }}
run: |
npx playwright install-deps
npx playwright install

- name: Cache Playwright browsers
if: ${{ hashFiles('playwright.config.*') != '' || hashFiles('.playwright-mcp/**') != '' }}
uses: actions/cache@v4
with:
path: ~/.cache/ms-playwright
key: ${{ runner.os }}-playwright-${{ hashFiles('playwright.config.*', '.playwright-mcp/**') }}

# ---------- Prisma + SQLite (prisma/dev.db) ----------
- name: Generate Prisma client (SQLite)
env:
DATABASE_URL: "file:./prisma/dev.db"
run: |
mkdir -p prisma
npx prisma generate

- name: Init SQLite schema (db push)
env:
DATABASE_URL: "file:./prisma/dev.db"
run: npx prisma db push --accept-data-loss

- name: Apply migrations (optional if present)
env:
DATABASE_URL: "file:./prisma/dev.db"
run: |
if [ -f "prisma/schema.prisma" ] && [ -d "prisma/migrations" ]; then
npx prisma migrate deploy || true
fi

- name: Seed database (uses your npm script)
env:
DATABASE_URL: "file:./prisma/dev.db"
run: |
if [ -f "prisma/seed.ts" ]; then
npm run db:seed
else
echo "No prisma/seed.ts found; skipping."
fi

# ---------- Type checking ----------
- name: Type check
run: npm run type-check

- name: Save type-check errors to JSON (PowerShell script with Linux fallback)
Copy link

Copilot AI Nov 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment indicates PowerShell with Linux fallback, but the implementation shows the opposite: it attempts npm script first, then falls back to PowerShell. On ubuntu-latest, PowerShell may not be available by default. The logic should either be corrected or the comment updated to accurately reflect 'npm script with PowerShell fallback'.

Suggested change
- name: Save type-check errors to JSON (PowerShell script with Linux fallback)
- name: Save type-check errors to JSON (npm script with PowerShell fallback)

Copilot uses AI. Check for mistakes.
run: |
npm run type-check:save || pwsh -File ./scripts/collect-type-errors.ps1
shell: bash

# ---------- Next.js MCP warm start (guarded) ----------
- name: Warm-start Next.js dev server (time-boxed)
if: ${{ hashFiles('app/**','pages/**','src/app/**','src/pages/**') != '' }}
env:
NODE_ENV: development
run: |
(npm run dev & echo $! > /tmp/next_pid) || true
sleep 15 || true
if [ -f /tmp/next_pid ]; then
kill $(cat /tmp/next_pid) || true
Copy link

Copilot AI Nov 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PID capture logic is flawed. If 'npm run dev' fails immediately, the shell will still execute 'echo $! > /tmp/next_pid' with the PID of the failed subshell. The kill command on line 105 should verify the process exists before attempting to kill it, or use 'kill -0' to check process existence first.

Suggested change
kill $(cat /tmp/next_pid) || true
NEXT_PID=$(cat /tmp/next_pid)
if kill -0 "$NEXT_PID" 2>/dev/null; then
kill "$NEXT_PID" || true
fi

Copilot uses AI. Check for mistakes.
fi
Comment on lines +102 to +106
Copy link

Copilot AI Nov 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The backgrounded process PID may not be captured correctly. If npm run dev & fails, the echo $! > /tmp/next_pid still executes due to the || operator binding, writing the wrong PID. The entire command should be wrapped: (npm run dev > /dev/null 2>&1 & echo $! > /tmp/next_pid) to ensure the PID file is only created if the process starts.

Copilot uses AI. Check for mistakes.

# ---------- Optional caches ----------
- name: Cache Next.js build artifacts
uses: actions/cache@v4
with:
path: |
~/.npm
.next/cache
key: ${{ runner.os }}-next-${{ hashFiles('package-lock.json') }}
restore-keys: |
${{ runner.os }}-next-