diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index a931dad..a706525 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -7,6 +7,9 @@ "overrideCommand": true, "runServices": ["db", "web"], "remoteUser": "node", + "mounts": [ + "source=${localEnv:SSH_AUTH_SOCK},target=/ssh-agent,type=bind" + ], "remoteEnv": { "VSCODE_AGENT_FOLDER": "/home/node/.vscode-server" }, "runArgs": ["--memory=6g", "--shm-size=1g"], diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0190653..db2f4b0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,6 +16,9 @@ concurrency: jobs: build: runs-on: ubuntu-latest + env: + NEXT_TELEMETRY_DISABLED: '1' + DATABASE_URL: postgresql://recipe:recipe@localhost:5432/recipebook services: postgres: @@ -34,17 +37,18 @@ jobs: - name: Checkout uses: actions/checkout@v4 + # pnpm first (your approach), then Node (for cache) - name: Install pnpm uses: pnpm/action-setup@v4 with: version: 10.15.0 run_install: false - - name: Use Node 20 + - name: Use Node 20 (with pnpm cache) uses: actions/setup-node@v4 with: node-version: '20' - cache: 'pnpm' # cache only; does NOT install pnpm + cache: 'pnpm' # cache only; pnpm is already installed above - name: Install Postgres client run: sudo apt-get update && sudo apt-get install -y postgresql-client @@ -52,8 +56,10 @@ jobs: - name: Install deps run: pnpm install --frozen-lockfile=false - - name: Prisma generate - run: pnpm exec prisma generate + - name: Prisma validate & generate + run: | + pnpm exec prisma validate + pnpm exec prisma generate - name: Wait for DB run: | @@ -66,17 +72,29 @@ jobs: echo "DB not ready" && exit 1 - name: Migrate + seed - env: - DATABASE_URL: postgresql://recipe:recipe@localhost:5432/recipebook run: | pnpm exec prisma migrate deploy pnpm run seed || true + # Cache Next.js build cache to speed up subsequent builds + - name: Restore Next.js cache + uses: actions/cache@v4 + with: + path: .next/cache + key: nextcache-${{ runner.os }}-${{ hashFiles('pnpm-lock.yaml') }}-${{ hashFiles('next.config.*','src/**/*.[jt]s','src/**/*.[jt]sx') }} + restore-keys: | + nextcache-${{ runner.os }}-${{ hashFiles('pnpm-lock.yaml') }}- + - name: Typecheck run: pnpm exec tsc --noEmit - name: Build - env: - NEXT_TELEMETRY_DISABLED: '1' - DATABASE_URL: postgresql://recipe:recipe@localhost:5432/recipebook run: pnpm run build + + - name: Save Next.js cache + if: always() + uses: actions/cache@v4 + with: + path: .next/cache + key: nextcache-${{ runner.os }}-${{ hashFiles('pnpm-lock.yaml') }}-${{ github.sha }} + diff --git a/prisma/seed.ts b/prisma/seed.ts index a694504..0cf00ab 100644 --- a/prisma/seed.ts +++ b/prisma/seed.ts @@ -4,12 +4,21 @@ const db = new PrismaClient(); async function main(){ const book = await db.book.upsert({ where: { slug: 'winners' }, + update: {}, create: { slug: 'winners', title: 'Tested Winners' }, update: {} }); - await db.recipe.create({ - data: { + await db.recipe.upsert({ + where: { + bookId_slug_version: { + bookId: book.id, + slug: 'carnitas-confit', + version: 1, + }, + }, + update: {}, // nothing to change if exists + create: { bookId: book.id, slug: 'garlic-mojo', kind: 'COMPONENT', title: 'Garlic Mojo', description: 'Citrusy garlicky oil for drizzling.', status: 'PUBLISHED', version: 1, @@ -27,8 +36,16 @@ async function main(){ } }); - await db.recipe.create({ - data: { + await db.recipe.upsert({ + where: { + bookId_slug_version: { + bookId: book.id, + slug: 'carnitas-confit', + version: 1, + }, + }, + update: {}, // nothing to change if exists + create: { bookId: book.id, slug: 'carnitas-confit', kind: 'TOP_LEVEL', title: 'Confit-Style Carnitas', description: 'Pork shoulder gently confited in lard, then broiled crisp.',