brackt/.forgejo/workflows/deploy.yml

127 lines
4.3 KiB
YAML
Raw Normal View History

name: 🚀 Deploy
on:
push:
branches:
- main
pull_request: {}
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
permissions:
contents: read
jobs:
test:
name: 🧪 Test
runs-on: ubuntu-latest
timeout-minutes: 20
services:
postgres:
image: postgres:15
env:
POSTGRES_USER: test
POSTGRES_PASSWORD: test
POSTGRES_DB: brackt_test
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- name: ⬇️ Checkout repo
uses: https://github.com/actions/checkout@v4
- name: 📥 Install dependencies
run: npm ci
- name: 🧪 Run unit tests
run: npm run test:run
env:
DATABASE_URL: postgresql://test:test@postgres:5432/brackt_test
Add FIFA World Cup 2026 support with group stage display and Monte Carlo simulator (#242) * Add FIFA World Cup 2026 support with group stage display and Monte Carlo simulator, fixes #127 - New `groupStageMatches` table for recording group play results (W/D/L, scores, matchday, schedule) - `computeGroupStandings()` model function: pts → GD → GF → name tiebreaker ordering - `GroupStageStandings` component showing all 12 groups with standings table and manager column - Admin bracket UI: group match score entry, per-group standings, "Recalculate Floors" action - `WorldCupSimulator`: 50k Monte Carlo covering group stage + best-8 3rd-place + knockout + 3rd place game - Fuzzy name matching for national team Elo lookup (exact → substring → word-overlap), warns on miss - Partial group completion: completed matches replayed with real scores, remaining matches simulated - Elo priority: admin-entered sourceElo > futures odds converted to Elo > hardcoded national team ratings - `fifa_48` bracket template: added Third Place Game round with `loserFeedsInto` on Semifinals - Scoring rules: distinct 3rd/4th place for `fifa_48` (not averaged), QF losers share 5th–8th equally - Floor scoring: SF participants guaranteed 4th (provisional), finalized after 3rd place game - `recalculate-floors` admin action deletes and replays all results from scratch (fixes stale guard bug) - Unique index on `(tournamentGroupId, participant1Id, participant2Id)` to prevent duplicate pairings - Batch `findMatchesByGroupIds()` replacing N sequential queries in the sport season loader - League home mini-standings now shows `actualPoints` (includes floor) instead of `totalPoints` only - Elo ratings admin page supports World Cup (same bulk-import flow as snooker) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * Fix TypeScript errors: update GroupStandingData type to use findMatchesByGroupIds Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * Increase Node heap to 4GB for unit tests in CI to prevent OOM Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * Fix OOM in CI: make WorldCupSimulator simulation count configurable for tests Tests now pass numSimulations=500 instead of the production default of 50,000. Six simulator tests × 50k iterations each was exhausting the 4GB heap on GitHub Actions runners. Also reduce simGroupMatch stat tests from 50k to 5k iterations. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-29 10:27:47 -07:00
NODE_OPTIONS: --max-old-space-size=4096
check:
name: ʦ🔍 Typecheck & Lint
runs-on: ubuntu-latest
timeout-minutes: 15
2026-03-22 20:33:43 -07:00
steps:
- name: ⬇️ Checkout repo
uses: https://github.com/actions/checkout@v4
2026-03-22 20:33:43 -07:00
- name: 📥 Install dependencies
run: npm ci
- name: 🔍 Lint (oxlint)
run: npm run lint
- name: 🔎 Type check
run: npm run typecheck
build:
name: 🐳 Build
needs: [test, check]
if: ${{ github.ref == 'refs/heads/main' && github.event_name == 'push' }}
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- name: ⬇️ Checkout repo
uses: https://github.com/actions/checkout@v4
- name: 🐳 Set up Docker Buildx
uses: https://github.com/docker/setup-buildx-action@v3
- name: 🔓 Login to Container Registry
uses: https://github.com/docker/login-action@v3
with:
registry: ${{ vars.CONTAINER_REGISTRY }}
username: ${{ secrets.REGISTRY_USERNAME }}
password: ${{ secrets.REGISTRY_PASSWORD }}
- name: 🗄️ Build and Push to Container Registry
uses: https://github.com/docker/build-push-action@v5
with:
context: .
push: true
Optimize CI build pipeline (~15 min → ~3-5 min) (#59) ## Summary - **Dockerfile layer caching**: `development-dependencies-env` now copies only `package.json`/`package-lock.json` before `npm ci` (was `COPY . /app`), so the npm install layer is cached on every code-only commit instead of rebuilt from scratch - **Skip QEMU**: `platforms: linux/amd64` added to `build-push-action`, cutting `setup-buildx-action` from ~5 min to ~30 sec - **npm cache in CI jobs**: Manual `actions/cache@v3` blocks (copy-pasted 3×) replaced with `actions/setup-node@v4` + `cache: 'npm'`, which handles path/key/restore automatically and pins Node 20 explicitly - **Harden `.npmrc`**: Switched from `COPY .npmrc` to `--mount=type=secret,id=npmrc` in both `npm ci` stages — the file is available during install but never written into a Docker layer, so it cannot leak through the registry build cache regardless of future contents ## Expected timing | Step | Before | After (code change) | |---|---|---| | Setup buildx | ~5 min | ~30 sec | | Build + push | ~5 min | ~1-2 min | | Deploy (docker pull) | ~5 min | ~1-2 min | | **Total** | **~15 min** | **~3-5 min** | ## Test plan - [ ] Push a code-only commit to main — confirm `setup-buildx-action` logs ~30s (no QEMU), Docker build shows `CACHED` for npm install layers, build+push completes in ~1-2 min - [ ] Check deploy job — `docker compose pull` should show most layers as `Already exists` - [ ] Push a commit that changes `package.json` — confirm npm layer correctly re-runs (not cached) - [ ] Confirm deployed app is functional 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Chris Parsons <chrisparsons1127@gmail.com> Reviewed-on: https://forge.brackt.com/chrisp/brackt/pulls/59
2026-05-31 04:35:05 +00:00
platforms: linux/amd64
tags: ${{ vars.CONTAINER_REGISTRY }}/brackt:latest
cache-from: type=registry,ref=${{ vars.CONTAINER_REGISTRY }}/brackt:buildcache
cache-to: type=registry,ref=${{ vars.CONTAINER_REGISTRY }}/brackt:buildcache,mode=max
Optimize CI build pipeline (~15 min → ~3-5 min) (#59) ## Summary - **Dockerfile layer caching**: `development-dependencies-env` now copies only `package.json`/`package-lock.json` before `npm ci` (was `COPY . /app`), so the npm install layer is cached on every code-only commit instead of rebuilt from scratch - **Skip QEMU**: `platforms: linux/amd64` added to `build-push-action`, cutting `setup-buildx-action` from ~5 min to ~30 sec - **npm cache in CI jobs**: Manual `actions/cache@v3` blocks (copy-pasted 3×) replaced with `actions/setup-node@v4` + `cache: 'npm'`, which handles path/key/restore automatically and pins Node 20 explicitly - **Harden `.npmrc`**: Switched from `COPY .npmrc` to `--mount=type=secret,id=npmrc` in both `npm ci` stages — the file is available during install but never written into a Docker layer, so it cannot leak through the registry build cache regardless of future contents ## Expected timing | Step | Before | After (code change) | |---|---|---| | Setup buildx | ~5 min | ~30 sec | | Build + push | ~5 min | ~1-2 min | | Deploy (docker pull) | ~5 min | ~1-2 min | | **Total** | **~15 min** | **~3-5 min** | ## Test plan - [ ] Push a code-only commit to main — confirm `setup-buildx-action` logs ~30s (no QEMU), Docker build shows `CACHED` for npm install layers, build+push completes in ~1-2 min - [ ] Check deploy job — `docker compose pull` should show most layers as `Already exists` - [ ] Push a commit that changes `package.json` — confirm npm layer correctly re-runs (not cached) - [ ] Confirm deployed app is functional 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Chris Parsons <chrisparsons1127@gmail.com> Reviewed-on: https://forge.brackt.com/chrisp/brackt/pulls/59
2026-05-31 04:35:05 +00:00
secret-files: |
npmrc=./.npmrc
deploy:
name: 🚀 Deploy
runs-on: ubuntu-latest
timeout-minutes: 10
needs: [build]
if: ${{ github.ref == 'refs/heads/main' && github.event_name == 'push' }}
steps:
- name: 🚀 Deploy app to server
uses: https://github.com/appleboy/ssh-action@v1.0.3
env:
REGISTRY_USERNAME: ${{ secrets.REGISTRY_USERNAME }}
REGISTRY_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }}
CONTAINER_REGISTRY: ${{ vars.CONTAINER_REGISTRY }}
with:
host: ${{ secrets.DEPLOY_HOST }}
port: ${{ secrets.DEPLOY_PORT }}
username: ${{ secrets.DEPLOY_USER }}
key: ${{ secrets.DEPLOY_KEY }}
Decouple database migrations from server startup (#265) * Use Docker Compose init service pattern for database migrations Replaces the fragile double-migration approach (server.ts startup + drizzle-kit CLI in CI) with a one-shot migrate service in Docker Compose that the app depends on via condition: service_completed_successfully. - Add scripts/migrate.mjs: programmatic drizzle-orm migration (uses production deps, not drizzle-kit which is devOnly and absent from image) - Dockerfile: copy scripts/ into image, remove drizzle.config.ts (only needed by drizzle-kit CLI) - server.ts: remove runMigrations() entirely; migrations are now handled by the migrate container before the app starts - deploy.yml: remove explicit docker run migration step; replace sleep 10 health check with a poll loop and explicit migrate exit-code check Production server's docker-compose.yaml needs a one-time manual update to add the migrate service — see plan for exact config. https://claude.ai/code/session_01ReaqH3o9NVH4QU4qE9WMMQ * Move drizzle-kit to devDependencies; use docker compose wait in deploy drizzle-kit is a dev-only tool (schema generation and local migrations). Now that production migrations run via the programmatic drizzle-orm API in the migrate init container, drizzle-kit has no runtime role. Also replaces the polling health check loop with docker compose wait, which blocks until the migrate service exits and returns its exit code cleanly — no sleep or manual status inspection needed. https://claude.ai/code/session_01ReaqH3o9NVH4QU4qE9WMMQ --------- Co-authored-by: Claude <noreply@anthropic.com>
2026-04-06 00:07:36 -04:00
envs: REGISTRY_USERNAME,REGISTRY_PASSWORD,CONTAINER_REGISTRY
script: |
set -e
docker login $CONTAINER_REGISTRY -u $REGISTRY_USERNAME -p $REGISTRY_PASSWORD
cd brackt
docker compose pull
if ! docker compose up --no-deps migrate; then
Decouple database migrations from server startup (#265) * Use Docker Compose init service pattern for database migrations Replaces the fragile double-migration approach (server.ts startup + drizzle-kit CLI in CI) with a one-shot migrate service in Docker Compose that the app depends on via condition: service_completed_successfully. - Add scripts/migrate.mjs: programmatic drizzle-orm migration (uses production deps, not drizzle-kit which is devOnly and absent from image) - Dockerfile: copy scripts/ into image, remove drizzle.config.ts (only needed by drizzle-kit CLI) - server.ts: remove runMigrations() entirely; migrations are now handled by the migrate container before the app starts - deploy.yml: remove explicit docker run migration step; replace sleep 10 health check with a poll loop and explicit migrate exit-code check Production server's docker-compose.yaml needs a one-time manual update to add the migrate service — see plan for exact config. https://claude.ai/code/session_01ReaqH3o9NVH4QU4qE9WMMQ * Move drizzle-kit to devDependencies; use docker compose wait in deploy drizzle-kit is a dev-only tool (schema generation and local migrations). Now that production migrations run via the programmatic drizzle-orm API in the migrate init container, drizzle-kit has no runtime role. Also replaces the polling health check loop with docker compose wait, which blocks until the migrate service exits and returns its exit code cleanly — no sleep or manual status inspection needed. https://claude.ai/code/session_01ReaqH3o9NVH4QU4qE9WMMQ --------- Co-authored-by: Claude <noreply@anthropic.com>
2026-04-06 00:07:36 -04:00
echo "Migration failed:"
docker compose logs migrate
exit 1
fi
Decouple database migrations from server startup (#265) * Use Docker Compose init service pattern for database migrations Replaces the fragile double-migration approach (server.ts startup + drizzle-kit CLI in CI) with a one-shot migrate service in Docker Compose that the app depends on via condition: service_completed_successfully. - Add scripts/migrate.mjs: programmatic drizzle-orm migration (uses production deps, not drizzle-kit which is devOnly and absent from image) - Dockerfile: copy scripts/ into image, remove drizzle.config.ts (only needed by drizzle-kit CLI) - server.ts: remove runMigrations() entirely; migrations are now handled by the migrate container before the app starts - deploy.yml: remove explicit docker run migration step; replace sleep 10 health check with a poll loop and explicit migrate exit-code check Production server's docker-compose.yaml needs a one-time manual update to add the migrate service — see plan for exact config. https://claude.ai/code/session_01ReaqH3o9NVH4QU4qE9WMMQ * Move drizzle-kit to devDependencies; use docker compose wait in deploy drizzle-kit is a dev-only tool (schema generation and local migrations). Now that production migrations run via the programmatic drizzle-orm API in the migrate init container, drizzle-kit has no runtime role. Also replaces the polling health check loop with docker compose wait, which blocks until the migrate service exits and returns its exit code cleanly — no sleep or manual status inspection needed. https://claude.ai/code/session_01ReaqH3o9NVH4QU4qE9WMMQ --------- Co-authored-by: Claude <noreply@anthropic.com>
2026-04-06 00:07:36 -04:00
docker compose up -d --remove-orphans