feat/bun-transition #21

Merged
david merged 24 commits from feat/bun-transition into main 2026-04-02 04:51:20 +00:00
6 changed files with 79 additions and 57 deletions
Showing only changes of commit 1cd2cbd0a6 - Show all commits
+10 -10
View File
@@ -9,7 +9,7 @@ jobs:
unit-tests:
runs-on: ubuntu-latest
container:
image: node:20-alpine
image: oven/bun:alpine
options: --user root
steps:
@@ -17,10 +17,10 @@ jobs:
uses: actions/checkout@v4
- name: Install dependencies
run: npm ci
run: bun install
- name: Run unit tests
run: npm run test:run
run: bun test
acceptance-tests:
runs-on: ubuntu-latest
@@ -37,16 +37,16 @@ jobs:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
- name: Setup Bun
uses: oven/setup-bun@v2
with:
node-version: '20'
bun-version: latest
- name: Install dependencies
run: npm ci
run: bun install
- name: Generate Prisma client
run: npx prisma generate
run: bun x prisma generate
env:
DATABASE_URL: postgresql://user:pass@localhost:5432/dummy
@@ -54,10 +54,10 @@ jobs:
run: |
# Create SQLite database file
mkdir -p prisma
npx prisma migrate deploy
bun x prisma migrate deploy
- name: Run acceptance tests
run: npm run test:acceptance
run: bun run test:acceptance
env:
DATABASE_PROVIDER: sqlite
DATABASE_URL: file:./prisma/ci.db
+8 -3
View File
@@ -63,6 +63,11 @@ jobs:
fi
fi
- name: Setup Bun
uses: oven/setup-bun@v2
with:
bun-version: latest
- name: Bump version
id: version
run: |
@@ -70,10 +75,10 @@ jobs:
echo "Bumping version: $BUMP"
# Run the bump script
node scripts/bump-version.js "$BUMP" --yes
bun run scripts/bump-version.js "$BUMP" --yes
# Get new version
NEW_VERSION=$(node -p "require('./package.json').version")
NEW_VERSION=$(bun -e "console.log(require('./package.json').version)")
echo "new_version=$NEW_VERSION" >> $GITHUB_OUTPUT
echo "New version: $NEW_VERSION"
@@ -123,7 +128,7 @@ jobs:
docker run --rm \
-e DATABASE_URL="postgresql://user:pass@localhost:5432/dummy" \
${{ env.IMAGE_NAME }}-test:${{ steps.version.outputs.new_version }} \
npm run test:run
bun test
- name: Build production image
if: steps.commit.outputs.committed == 'true'
-25
View File
@@ -1,25 +0,0 @@
name: Test
on:
push:
branches:
- '**'
jobs:
unit-tests:
runs-on: ubuntu-latest
container:
image: node:20-alpine
options: --user root
# Skip if this is an auto-generated version bump commit (handled by release workflow)
if: "!contains(github.event.head_commit.message, 'chore: bump version')"
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install dependencies
run: npm ci
- name: Run unit tests
run: npm run test:run
+40 -3
View File
@@ -9,11 +9,12 @@ EuchreCamp is a Next.js 14+ application for managing Euchre tournaments and trac
### Key Technologies
- **Next.js 14+** (App Router)
- **TypeScript**
- **Prisma ORM** (SQLite)
- **Prisma ORM** (SQLite/PostgreSQL)
- **Tailwind CSS**
- **Better Auth** (Authentication)
- **Vitest** (Unit Testing)
- **Bun** (Package Manager & Test Runner)
- **Playwright** (Acceptance Testing)
- **Vitest** (Legacy - migrated to Bun test runner)
## Architecture Patterns
@@ -37,13 +38,49 @@ EuchreCamp is a Next.js 14+ application for managing Euchre tournaments and trac
## Common Tasks
### Package Manager: Bun
This project uses **Bun** as the package manager and test runner:
```bash
# Install dependencies
bun install
# Run development server
bun run dev
# Build the application
bun run build
# Run unit/component tests
bun test
# Run acceptance tests (Playwright)
bun run test:acceptance
# Run linting
bun run lint
```
**Note**: E2E tests still use Playwright, as Bun's test runner doesn't support browser automation. Unit and component tests have been migrated to Bun's native test runner for faster execution.
### CI/CD with Bun
All CI/CD workflows have been updated to use Bun:
- **Dockerfile**: Uses `oven/bun:alpine` base image for all stages
- **PR Workflow**: Uses `oven/setup-bun` action and `bun install`, `bun test`
- **Release Workflow**: Uses Bun for version bumping and Docker builds
**Note**: The `test.yml` workflow has been removed as it's redundant with the PR workflow.
### Admin User Creation
To create an admin user, use the provided scripts:
**Option 1: Using Better Auth API (Recommended)**
```bash
node scripts/create-admin-via-api.js
bun run scripts/create-admin-via-api.js
```
This creates the admin user `david@dhg.lol` with password `adminadmin` using Better Auth's internal API.
+13 -13
View File
@@ -1,9 +1,9 @@
# Multi-stage build for EuchreCamp Next.js application
# Stage 1: Builder
FROM node:20-alpine AS builder
FROM oven/bun:alpine AS builder
# Install dependencies
# Install dependencies (needed for native modules)
RUN apk add --no-cache python3 make g++
# Set working directory
@@ -13,21 +13,21 @@ WORKDIR /app
COPY package*.json ./
# Install dependencies (including dev dependencies for building)
RUN npm ci
RUN bun install
# Copy source code
COPY . .
# Generate Prisma client (with dummy PostgreSQL DATABASE_URL for build-time generation)
# Note: A dummy URL is used since the real database is not available during build
RUN DATABASE_URL="postgresql://user:pass@localhost:5432/dummy" npx prisma generate
RUN DATABASE_PROVIDER=postgresql DATABASE_URL="postgresql://user:pass@localhost:5432/dummy" bun x prisma generate
# Build the application (with dummy DATABASE_URL for static page generation and git commit)
ARG GIT_COMMIT=unknown
RUN DATABASE_URL="postgresql://user:pass@localhost:5432/dummy" NEXT_PUBLIC_GIT_COMMIT=$GIT_COMMIT npm run build
RUN DATABASE_PROVIDER=postgresql DATABASE_URL="postgresql://user:pass@localhost:5432/dummy" NEXT_PUBLIC_GIT_COMMIT=$GIT_COMMIT bun run build
# Stage 2: Test runner (includes dev dependencies for testing)
FROM node:20-alpine AS test-runner
FROM oven/bun:alpine AS test-runner
# Install dependencies
RUN apk add --no-cache python3 make g++ git
@@ -39,16 +39,16 @@ WORKDIR /app
COPY package*.json ./
# Install ALL dependencies (including dev dependencies for testing)
RUN npm ci
RUN bun install
# Copy source code
COPY . .
# Generate Prisma client
RUN DATABASE_URL="postgresql://user:pass@localhost:5432/dummy" npx prisma generate
RUN DATABASE_PROVIDER=postgresql DATABASE_URL="postgresql://user:pass@localhost:5432/dummy" bun x prisma generate
# Stage 3: Production runner
FROM node:20-alpine AS runner
FROM oven/bun:alpine AS runner
# Install dumb-init for proper signal handling
RUN apk add --no-cache dumb-init
@@ -64,15 +64,15 @@ WORKDIR /app
COPY --from=builder --chown=euchre:euchre /app/.next ./.next
COPY --from=builder --chown=euchre:euchre /app/public ./public
COPY --from=builder --chown=euchre:euchre /app/package.json ./package.json
COPY --from=builder --chown=euchre:euchre /app/package-lock.json ./package-lock.json
COPY --from=builder --chown=euchre:euchre /app/bun.lockb ./bun.lockb
COPY --from=builder --chown=euchre:euchre /app/prisma ./prisma
# Install only production dependencies
RUN npm ci --omit=dev
RUN bun install --production
# Generate Prisma client
# Note: We need to set DATABASE_URL even for generation because prisma.config.ts requires it
RUN DATABASE_URL="postgresql://user:pass@localhost:5432/dummy" npx prisma generate
RUN DATABASE_PROVIDER=postgresql DATABASE_URL="postgresql://user:pass@localhost:5432/dummy" bun x prisma generate
# Switch to non-root user
USER euchre
@@ -86,4 +86,4 @@ HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
# Start command
ENTRYPOINT ["dumb-init", "--"]
CMD ["npm", "start"]
CMD ["bun", "run", "start"]
+8 -3
View File
@@ -25,14 +25,19 @@
- [x] Auto-create tournament when uploading matches without selecting one
### In Progress 🔄
- [ ] Update CI/CD workflows to use Bun (PR, test, release)
- [ ] Update Dockerfile to use Bun Alpine image
- [ ] Verify release workflow with Bun
- [ ] Update API routes to handle new variant scoring fields
- [ ] Update EditTournamentForm to add variant scoring controls
- [ ] Update MatchEditor to use tournament-specific target score
- [ ] Run tests and verify variant scoring implementation
### Recently Completed ✅
- [x] Update CI/CD workflows to use Bun (PR, release)
- [x] Update Dockerfile to use Bun Alpine image
- [x] Update PR workflow to use Bun
- [x] Update Release workflow to use Bun
- [x] Remove test.yml workflow (redundant)
- [x] Verify Docker build with Bun
### Recently Completed ✅
- [x] Fix Prisma build error in CI pipeline (Docker build failure due to missing DATABASE_URL validation)
- [x] Add defensive checks to src/lib/prisma.ts to prevent build failures