Automation Workflows.
CI/CD pipelines, n8n automation templates, AI agent patterns, Docker Compose production stacks, and task runners. Copy, adapt, and ship faster.
GitHub Actions Snippets
Quality Gate (3-stage pipeline)
name: CI
on: [push, pull_request]
jobs:
quality:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with: { node-version: '22', cache: 'npm' }
- run: npm ci
- run: npm run typecheck
- run: npm run lint
- run: npm run test
build:
needs: quality
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with: { node-version: '22', cache: 'npm' }
- run: npm ci && npm run build
- uses: actions/upload-artifact@v4
with: { name: dist, path: dist/ }
lighthouse:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with: { name: dist, path: dist/ }
- run: npx lhci autorun
Auto-label PRs by size
name: PR Labels
on: pull_request
jobs:
label:
runs-on: ubuntu-latest
steps:
- uses: codelytv/pr-size-labeler@v1
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
xs_max_size: 10
s_max_size: 50
m_max_size: 200
l_max_size: 500
Deploy on merge to main
name: Deploy
on:
push:
branches: [main]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with: { node-version: '22', cache: 'npm' }
- run: npm ci && npm run build
- uses: cloudflare/pages-action@v1
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
projectName: my-portfolio
directory: dist
CI/CD Pipelines
Three-stage GitHub Actions pipeline: quality gate (tsc, eslint, vitest) runs first; build job depends on quality passing; Lighthouse CI job audits the static export for performance, accessibility, and SEO regressions.
Uses BuildKit multi-stage Dockerfile — deps stage caches node_modules separately from the build stage. GitHub Actions cache action stores Docker layers between runs, cutting cold build time by 60–80%.
Conventional Commits trigger semantic-release on merge to main. Automatically bumps semver, generates CHANGELOG.md, creates GitHub Release, and publishes to npm — zero manual version management.
n8n Workflows
Webhook triggers on issue open. GPT-4o classifies the issue type (bug/feature/docs). n8n applies the correct GitHub label via API and posts a formatted card to the #engineering Slack channel.
Polls 5 tech RSS feeds every 6 hours. For each new item, Claude Haiku writes a 2-sentence summary with emoji. Deduplication via Redis. Posts to Telegram channel with source attribution.
New CRM lead triggers workflow. Clearbit enriches company data. Scoring logic assigns to sales rep based on company size and industry. Resend dispatches personalized welcome email with rep introduction.
Runs every morning at 08:00 UTC. Pulls PostHog, GitHub, and Stripe metrics via HTTP nodes. Formats into a structured HTML report. Sends to founder inbox via Resend with key deltas highlighted.
GitHub webhook fires on repository star. Fetches stargazer profile. Generates a personalized thank-you tweet with Claude Haiku. Posts via X API v2. Deduplication via Redis to prevent double-tweets.
Runs at 02:00 UTC. Crawls the live site with Lighthouse CI. Parses results. For each failed check (score drop > 5%), creates a Linear issue with severity, affected URL, and fix suggestion generated by Claude.
AI Automation Patterns
Documents loaded and split into 512-token chunks with 64-token overlap. OpenAI text-embedding-3-small generates vectors stored in pgvector. At query time, top-k retrieval feeds context to the generation step with a structured system prompt.
Planner breaks task into steps. Executor uses tool calls to carry each out. Critic evaluates output against acceptance criteria — loops back if needed. Summarizer produces the final structured response.
Structured output forces JSON response with category, subcategory, and confidence 0–1. Documents below 0.7 confidence are queued for human review. High-confidence results route automatically to downstream workflows.
Force JSON output using tool_choice: tool + input schema derived from Zod. Validate at runtime with safeParse. Retry up to 3 times on validation failure — pass the Zod error back as user message for self-correction.
Use streaming API to show agent reasoning in real time. Parse stream chunks for tool_use blocks. Execute tools mid-stream and inject results. React to tool output before final response arrives.
Docker Compose Production Stack
docker-compose.yml — App + Postgres + Redis + Nginx + Certbot + Prometheus + Grafana
Full production compose stack with health checks, named volumes, isolated network, TLS via Let's Encrypt, and Prometheus + Grafana monitoring. Copy and customise for your project.
version: '3.9'
services:
app:
build: .
restart: unless-stopped
environment:
DATABASE_URL: postgresql://app:secret@postgres:5432/appdb
REDIS_URL: redis://redis:6379
depends_on:
postgres: { condition: service_healthy }
redis: { condition: service_started }
networks: [backend]
labels:
- "traefik.enable=true"
- "traefik.http.routers.app.rule=Host(`example.com`)"
- "traefik.http.routers.app.tls.certresolver=letsencrypt"
postgres:
image: postgres:16-alpine
restart: unless-stopped
environment:
POSTGRES_USER: app
POSTGRES_PASSWORD: secret
POSTGRES_DB: appdb
volumes:
- postgres_data:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U app -d appdb"]
interval: 10s
timeout: 5s
retries: 5
networks: [backend]
redis:
image: redis:7-alpine
restart: unless-stopped
command: redis-server --appendonly yes --maxmemory 256mb --maxmemory-policy allkeys-lru
volumes:
- redis_data:/data
networks: [backend]
nginx:
image: nginx:alpine
restart: unless-stopped
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf:ro
- certbot_certs:/etc/letsencrypt:ro
ports: ["80:80", "443:443"]
depends_on: [app]
networks: [backend]
certbot:
image: certbot/certbot
volumes:
- certbot_certs:/etc/letsencrypt
entrypoint: >
/bin/sh -c "trap exit TERM;
while :; do certbot renew --webroot -w /var/www/certbot;
sleep 12h & wait $!; done"
prometheus:
image: prom/prometheus:latest
restart: unless-stopped
volumes:
- ./prometheus.yml:/etc/prometheus/prometheus.yml:ro
- prometheus_data:/prometheus
ports: ["9090:9090"]
networks: [backend]
grafana:
image: grafana/grafana:latest
restart: unless-stopped
environment:
GF_SECURITY_ADMIN_PASSWORD: admin
volumes:
- grafana_data:/var/lib/grafana
ports: ["3001:3000"]
depends_on: [prometheus]
networks: [backend]
volumes:
postgres_data:
redis_data:
certbot_certs:
prometheus_data:
grafana_data:
networks:
backend:
Taskfile.yml — Modern Make Alternative
Taskfile.yml — Complete TypeScript project task runner
Task (taskfile.dev) is a modern, cross-platform alternative to Make. YAML syntax, built-in dependency tracking, and works natively on Linux, macOS, and Windows.
version: '3'
vars:
APP_NAME: my-app
DOCKER_IMAGE: "{{.APP_NAME}}:latest"
tasks:
default:
desc: List all tasks
cmds: [task --list]
silent: true
dev:
desc: Start development server with hot reload
cmds: [npm run dev]
build:
desc: Production build
cmds: [npm run build]
test:
desc: Run all tests
cmds: [npm run test -- --run]
test:watch:
desc: Run tests in watch mode
cmds: [npm run test]
lint:
desc: Lint and auto-fix
cmds: [npm run lint -- --fix]
typecheck:
desc: TypeScript type checking (no emit)
cmds: [npm run typecheck]
db:migrate:
desc: Run pending database migrations
cmds: [npx drizzle-kit migrate]
db:seed:
desc: Seed the database with test data
cmds: [npx tsx src/lib/db/seed.ts]
db:studio:
desc: Open Drizzle Studio database GUI
cmds: [npx drizzle-kit studio]
docker:up:
desc: Start all Docker Compose services
cmds: [docker compose up -d]
docker:down:
desc: Stop all Docker Compose services
cmds: [docker compose down]
docker:logs:
desc: Tail logs for all services
cmds: [docker compose logs -f]
deploy:
desc: Deploy to production (Railway)
deps: [typecheck, test]
cmds:
- echo "Deploying {{.APP_NAME}}..."
- railway up --environment production
- echo "Deploy complete"
Makefile — Classic Build Automation
Makefile — Phony targets for TypeScript + Docker + Deploy
Classic Makefile with .PHONY declarations for a TypeScript project. Includes dev, build, test, lint, typecheck, database operations, Docker management, and deployment.
.PHONY: all dev build test lint typecheck clean deploy # Default target all: typecheck lint test build dev: npm run dev build: npm run build test: npm run test -- --run test-watch: npm run test lint: npm run lint typecheck: npm run typecheck clean: rm -rf dist .next node_modules/.cache install: npm ci # DB operations db-migrate: npx drizzle-kit migrate db-seed: npx tsx src/lib/db/seed.ts # Docker docker-up: docker compose up -d docker-down: docker compose down docker-rebuild: docker compose up -d --build # Deploy (requires RAILWAY_TOKEN) deploy: typecheck test railway up --environment production @echo "Deployed successfully"