better ci

This commit is contained in:
dal 2025-08-19 13:26:06 -06:00
parent 8c4ac06166
commit ddc06f4146
No known key found for this signature in database
GPG Key ID: 16F4B0E1E9F61122
4 changed files with 261 additions and 38 deletions

View File

@ -3,18 +3,20 @@ name: CI
on: on:
pull_request: pull_request:
# Cancel in-progress runs when a new commit is pushed to the same PR
concurrency:
group: ci-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
env: env:
CI: true CI: true
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
TURBO_TEAM: ${{ vars.TURBO_TEAM }}
TURBO_REMOTE_ONLY: true
jobs: jobs:
ci: # First, install dependencies once and cache them
name: Build, Lint & Test install:
runs-on: blacksmith-4vcpu-ubuntu-2404 name: Install Dependencies
timeout-minutes: 30 runs-on: blacksmith-2vcpu-ubuntu-2404
timeout-minutes: 5
steps: steps:
- name: Checkout code - name: Checkout code
uses: actions/checkout@v4 uses: actions/checkout@v4
@ -30,7 +32,6 @@ jobs:
uses: useblacksmith/setup-node@v5 uses: useblacksmith/setup-node@v5
with: with:
node-version: 22 node-version: 22
# Remove cache here since we're using stickydisk for pnpm store
- name: Get pnpm store directory - name: Get pnpm store directory
shell: bash shell: bash
@ -43,11 +44,11 @@ jobs:
key: ${{ github.repository }}-pnpm-store key: ${{ github.repository }}-pnpm-store
path: ${{ env.STORE_PATH }} path: ${{ env.STORE_PATH }}
- name: Mount Turbo cache sticky disk - name: Mount node_modules sticky disk
uses: useblacksmith/stickydisk@v1 uses: useblacksmith/stickydisk@v1
with: with:
key: ${{ github.repository }}-turbo-cache key: ${{ github.repository }}-pr-${{ github.event.pull_request.number }}-node-modules
path: ./.turbo path: ./node_modules
- name: Check if lockfile changed - name: Check if lockfile changed
id: lockfile-check id: lockfile-check
@ -65,14 +66,152 @@ jobs:
- name: Install dependencies - name: Install dependencies
run: pnpm install --frozen-lockfile --prefer-offline run: pnpm install --frozen-lockfile --prefer-offline
# Build job - runs in parallel
build:
name: Build
needs: install
runs-on: blacksmith-4vcpu-ubuntu-2404
timeout-minutes: 10
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install pnpm
uses: pnpm/action-setup@v2
with:
version: 9.15.0
- name: Setup Node.js
uses: useblacksmith/setup-node@v5
with:
node-version: 22
- name: Get pnpm store directory
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
- name: Mount pnpm store sticky disk
uses: useblacksmith/stickydisk@v1
with:
key: ${{ github.repository }}-pnpm-store
path: ${{ env.STORE_PATH }}
- name: Mount node_modules sticky disk
uses: useblacksmith/stickydisk@v1
with:
key: ${{ github.repository }}-pr-${{ github.event.pull_request.number }}-node-modules
path: ./node_modules
- name: Mount Turbo cache sticky disk
uses: useblacksmith/stickydisk@v1
with:
key: ${{ github.repository }}-turbo-cache
path: ./.turbo
- name: Install dependencies (from sticky disk)
run: pnpm install --frozen-lockfile --prefer-offline
- name: Build all packages (excluding web) - name: Build all packages (excluding web)
run: pnpm build --filter='!@buster-app/web' run: pnpm build --filter='!@buster-app/web'
env: env:
NODE_ENV: production NODE_ENV: production
# Lint job - runs in parallel
lint:
name: Lint
needs: install
runs-on: blacksmith-2vcpu-ubuntu-2404
timeout-minutes: 5
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install pnpm
uses: pnpm/action-setup@v2
with:
version: 9.15.0
- name: Setup Node.js
uses: useblacksmith/setup-node@v5
with:
node-version: 22
- name: Get pnpm store directory
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
- name: Mount pnpm store sticky disk
uses: useblacksmith/stickydisk@v1
with:
key: ${{ github.repository }}-pnpm-store
path: ${{ env.STORE_PATH }}
- name: Mount node_modules sticky disk
uses: useblacksmith/stickydisk@v1
with:
key: ${{ github.repository }}-pr-${{ github.event.pull_request.number }}-node-modules
path: ./node_modules
- name: Mount Turbo cache sticky disk
uses: useblacksmith/stickydisk@v1
with:
key: ${{ github.repository }}-turbo-cache
path: ./.turbo
- name: Install dependencies (from sticky disk)
run: pnpm install --frozen-lockfile --prefer-offline
- name: Lint all packages (excluding web) - name: Lint all packages (excluding web)
run: pnpm lint --filter='!@buster-app/web' run: pnpm lint --filter='!@buster-app/web'
# Test job - runs in parallel
test:
name: Test
needs: install
runs-on: blacksmith-4vcpu-ubuntu-2404
timeout-minutes: 15
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install pnpm
uses: pnpm/action-setup@v2
with:
version: 9.15.0
- name: Setup Node.js
uses: useblacksmith/setup-node@v5
with:
node-version: 22
- name: Get pnpm store directory
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
- name: Mount pnpm store sticky disk
uses: useblacksmith/stickydisk@v1
with:
key: ${{ github.repository }}-pnpm-store
path: ${{ env.STORE_PATH }}
- name: Mount node_modules sticky disk
uses: useblacksmith/stickydisk@v1
with:
key: ${{ github.repository }}-pr-${{ github.event.pull_request.number }}-node-modules
path: ./node_modules
- name: Mount Turbo cache sticky disk
uses: useblacksmith/stickydisk@v1
with:
key: ${{ github.repository }}-turbo-cache
path: ./.turbo
- name: Install dependencies (from sticky disk)
run: pnpm install --frozen-lockfile --prefer-offline
- name: Run all unit tests (excluding web) - name: Run all unit tests (excluding web)
run: pnpm test:unit --filter='!@buster-app/web' run: pnpm test:unit --filter='!@buster-app/web'
@ -85,3 +224,24 @@ jobs:
**/coverage/** **/coverage/**
!**/coverage/tmp/** !**/coverage/tmp/**
retention-days: 7 retention-days: 7
# Final status check - ensures all parallel jobs pass
ci-status:
name: CI Status
needs: [build, lint, test]
runs-on: blacksmith-2vcpu-ubuntu-2404
if: always()
timeout-minutes: 1
steps:
- name: Check CI Status
run: |
if [[ "${{ needs.build.result }}" != "success" ||
"${{ needs.lint.result }}" != "success" ||
"${{ needs.test.result }}" != "success" ]]; then
echo "❌ CI failed"
echo "Build: ${{ needs.build.result }}"
echo "Lint: ${{ needs.lint.result }}"
echo "Test: ${{ needs.test.result }}"
exit 1
fi
echo "✅ All CI checks passed!"

View File

@ -8,17 +8,22 @@ on:
- 'packages/database/drizzle.config.ts' - 'packages/database/drizzle.config.ts'
- '.github/workflows/database-migrations.yml' - '.github/workflows/database-migrations.yml'
# Only one migration per environment at a time
concurrency:
group: db-migrate-${{ github.ref }}
cancel-in-progress: false # Never cancel migrations
jobs: jobs:
migrate: migrate:
runs-on: blacksmith-8vcpu-ubuntu-2204 runs-on: blacksmith-2vcpu-ubuntu-2404
environment: ${{ github.ref_name }} environment: ${{ github.ref_name }}
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
- name: Setup Node.js - name: Setup Node.js
uses: actions/setup-node@v4 uses: useblacksmith/setup-node@v5
with: with:
node-version: '22.x' node-version: 22
- name: Install pnpm - name: Install pnpm
uses: pnpm/action-setup@v2 uses: pnpm/action-setup@v2
@ -30,16 +35,26 @@ jobs:
run: | run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
- name: Setup pnpm cache - name: Mount pnpm store sticky disk
uses: actions/cache@v3 uses: useblacksmith/stickydisk@v1
with: with:
key: ${{ github.repository }}-pnpm-store
path: ${{ env.STORE_PATH }} path: ${{ env.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: | - name: Mount node_modules sticky disk
${{ runner.os }}-pnpm-store- uses: useblacksmith/stickydisk@v1
with:
key: ${{ github.repository }}-${{ github.ref_name }}-db-node-modules
path: ./node_modules
- name: Mount Turbo cache sticky disk
uses: useblacksmith/stickydisk@v1
with:
key: ${{ github.repository }}-turbo-cache
path: ./.turbo
- name: Install dependencies - name: Install dependencies
run: pnpm install --frozen-lockfile run: pnpm install --frozen-lockfile --prefer-offline
- name: Run migrations - name: Run migrations
run: pnpm run db:migrate run: pnpm run db:migrate

View File

@ -9,13 +9,18 @@ on:
- 'pnpm-lock.yaml' - 'pnpm-lock.yaml'
- '.github/workflows/docker-build-server.yml' - '.github/workflows/docker-build-server.yml'
# Only one build per branch at a time, queue others
concurrency:
group: docker-build-${{ github.ref }}
cancel-in-progress: false # Don't cancel, queue instead for deployments
env: env:
REGISTRY: ghcr.io REGISTRY: ghcr.io
IMAGE_NAME: buster-so/buster-server IMAGE_NAME: buster-so/buster-server
jobs: jobs:
build-and-push: build-and-push:
runs-on: blacksmith-8vcpu-ubuntu-2204 runs-on: blacksmith-8vcpu-ubuntu-2404
permissions: permissions:
contents: read contents: read
packages: write packages: write
@ -56,6 +61,18 @@ jobs:
key: ${{ github.repository }}-turbo-cache key: ${{ github.repository }}-turbo-cache
path: ./.turbo path: ./.turbo
- name: Mount npm cache sticky disk
uses: useblacksmith/stickydisk@v1
with:
key: ${{ github.repository }}-npm-cache
path: ~/.npm
- name: Mount Docker buildkit sticky disk
uses: useblacksmith/stickydisk@v1
with:
key: ${{ github.repository }}-buildkit-cache
path: /tmp/.buildkit-cache
- name: Install dependencies - name: Install dependencies
run: | run: |
echo "📦 Installing dependencies with pnpm..." echo "📦 Installing dependencies with pnpm..."
@ -79,19 +96,35 @@ jobs:
ls -la dist/ ls -la dist/
cd ../.. cd ../..
- name: Mount production deps sticky disk
uses: useblacksmith/stickydisk@v1
with:
key: ${{ github.repository }}-prod-deps-${{ github.ref_name }}
path: /tmp/prod-deps-cache
- name: Prepare production dependencies - name: Prepare production dependencies
run: | run: |
echo "🧹 Preparing production-only dependencies..." echo "🧹 Preparing production-only dependencies..."
# Create a temporary directory for production deps # Use cached directory if it exists, otherwise create new
if [ -d "/tmp/prod-deps-cache/node_modules" ]; then
echo "Using cached production dependencies"
mkdir -p /tmp/prod-deps
cp -r /tmp/prod-deps-cache/* /tmp/prod-deps/ 2>/dev/null || true
else
echo "Building fresh production dependencies"
mkdir -p /tmp/prod-deps/apps/server mkdir -p /tmp/prod-deps/apps/server
cp package.json pnpm-lock.yaml pnpm-workspace.yaml /tmp/prod-deps/ cp package.json pnpm-lock.yaml pnpm-workspace.yaml /tmp/prod-deps/
cp -r packages /tmp/prod-deps/ cp -r packages /tmp/prod-deps/
cp apps/server/package.json /tmp/prod-deps/apps/server/ cp apps/server/package.json /tmp/prod-deps/apps/server/
fi
# Install production dependencies only # Install/update production dependencies
cd /tmp/prod-deps cd /tmp/prod-deps
pnpm install --frozen-lockfile --prod --ignore-scripts --no-optional pnpm install --frozen-lockfile --prod --ignore-scripts --no-optional
# Update cache
cp -r node_modules /tmp/prod-deps-cache/
# Copy back to workspace # Copy back to workspace
cd - cd -
mkdir -p docker-context mkdir -p docker-context

View File

@ -4,18 +4,23 @@ on:
push: push:
branches: [main, staging] branches: [main, staging]
# Only one deployment per environment at a time
concurrency:
group: trigger-deploy-${{ github.ref }}
cancel-in-progress: false # Never cancel deployments
jobs: jobs:
deploy: deploy:
runs-on: blacksmith-8vcpu-ubuntu-2204 runs-on: blacksmith-4vcpu-ubuntu-2404
environment: ${{ github.ref_name }} environment: ${{ github.ref_name }}
steps: steps:
- name: Checkout code - name: Checkout code
uses: actions/checkout@v4 uses: actions/checkout@v4
- name: Setup Node.js - name: Setup Node.js
uses: actions/setup-node@v4 uses: useblacksmith/setup-node@v5
with: with:
node-version: '22.x' node-version: 22
- name: Install pnpm - name: Install pnpm
uses: pnpm/action-setup@v2 uses: pnpm/action-setup@v2
@ -27,16 +32,26 @@ jobs:
run: | run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
- name: Setup pnpm cache - name: Mount pnpm store sticky disk
uses: actions/cache@v3 uses: useblacksmith/stickydisk@v1
with: with:
key: ${{ github.repository }}-pnpm-store
path: ${{ env.STORE_PATH }} path: ${{ env.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: | - name: Mount node_modules sticky disk
${{ runner.os }}-pnpm-store- uses: useblacksmith/stickydisk@v1
with:
key: ${{ github.repository }}-${{ github.ref_name }}-trigger-node-modules
path: ./node_modules
- name: Mount Turbo cache sticky disk
uses: useblacksmith/stickydisk@v1
with:
key: ${{ github.repository }}-turbo-cache
path: ./.turbo
- name: Install dependencies - name: Install dependencies
run: pnpm install --frozen-lockfile run: pnpm install --frozen-lockfile --prefer-offline
- name: 🚀 Deploy to ${{ github.ref_name == 'main' && 'Production' || 'Staging' }} - name: 🚀 Deploy to ${{ github.ref_name == 'main' && 'Production' || 'Staging' }}
env: env: