Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 104 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
name: CI

on:
push:
branches: [main]
paths:
- "community-reputation/**"
- ".github/workflows/ci.yml"
pull_request:
paths:
- "community-reputation/**"
- ".github/workflows/ci.yml"

defaults:
run:
working-directory: community-reputation

jobs:
typecheck:
name: TypeScript
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: actions/setup-node@v4
with:
node-version: 20
cache: npm
cache-dependency-path: community-reputation/package-lock.json

- run: npm ci

- name: Generate Prisma client
run: npx prisma generate

- run: npx tsc --noEmit

unit-tests:
name: Unit tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: actions/setup-node@v4
with:
node-version: 20
cache: npm
cache-dependency-path: community-reputation/package-lock.json

- run: npm ci

- name: Generate Prisma client
run: npx prisma generate

- run: npm run test:unit

integration-tests:
name: Integration tests
runs-on: ubuntu-latest

services:
postgres:
image: postgres:16-alpine
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: password
POSTGRES_DB: scibase_community_test
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5

steps:
- uses: actions/checkout@v4

- uses: actions/setup-node@v4
with:
node-version: 20
cache: npm
cache-dependency-path: community-reputation/package-lock.json

- run: npm ci

- name: Generate Prisma client
run: npx prisma generate

- name: Push schema to test database
env:
DATABASE_URL: postgresql://postgres:password@localhost:5432/scibase_community_test
# db push is used here because the repo has no migration files yet.
# Once `prisma migrate dev --name init` has been run locally and the
# migrations/ folder is committed, replace this with:
# npx prisma migrate deploy
run: npx prisma db push

- name: Run integration tests
env:
DATABASE_URL: postgresql://postgres:password@localhost:5432/scibase_community_test
# --fileParallelism=false is baked into the npm script; it prevents
# concurrent TRUNCATE calls across test files from deadlocking each other.
run: npm run test:integration
5 changes: 5 additions & 0 deletions community-reputation/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules
.next
.env
*.log
tsconfig.tsbuildinfo
12 changes: 12 additions & 0 deletions community-reputation/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
DATABASE_URL="postgresql://postgres:password@localhost:5432/scibase_community"
DATABASE_URL_TEST="postgresql://postgres:password@localhost:5432/scibase_community_test"

NEXTAUTH_URL="http://localhost:3000"
NEXTAUTH_SECRET="replace-with-a-random-secret-openssl-rand-base64-32"

# GitHub OAuth App — create one at github.com/settings/developers
GITHUB_ID="your-github-oauth-app-client-id"
GITHUB_SECRET="your-github-oauth-app-client-secret"

# Secret header value for the cron endpoint
CRON_SECRET="replace-with-a-random-secret"
1 change: 1 addition & 0 deletions community-reputation/.env.test.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DATABASE_URL="postgresql://postgres:password@localhost:5432/scibase_community_test"
26 changes: 26 additions & 0 deletions community-reputation/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Dependencies
node_modules/

# Next.js build output
.next/
out/

# Environment files — never commit real secrets
.env
.env.local
.env.test

# Prisma generated client (regenerated on install)
# Keep migrations/ committed
prisma/generated/

# TypeScript incremental build cache
tsconfig.tsbuildinfo
*.tsbuildinfo

# OS / editor noise
.DS_Store
*.swp
*.swo
.idea/
.vscode/
33 changes: 33 additions & 0 deletions community-reputation/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# ── Build stage ───────────────────────────────────────────────────────────────
FROM node:20-alpine AS builder
WORKDIR /app

COPY package*.json ./
RUN npm ci

COPY prisma ./prisma
RUN npx prisma generate

COPY . .
RUN npm run build

# ── Runtime stage ─────────────────────────────────────────────────────────────
FROM node:20-alpine AS runner
WORKDIR /app

ENV NODE_ENV=production

# Copy only what's needed to run
COPY --from=builder /app/package*.json ./
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/.next ./.next
COPY --from=builder /app/prisma ./prisma
COPY --from=builder /app/src/lib ./src/lib

EXPOSE 3000

# entrypoint.sh: migrate → seed → (optional demo seed) → start
COPY docker/entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh

ENTRYPOINT ["/entrypoint.sh"]
Loading