Skip to content

feat(sessions): add crash recovery with suspend/resume and grace window expiry #159

feat(sessions): add crash recovery with suspend/resume and grace window expiry

feat(sessions): add crash recovery with suspend/resume and grace window expiry #159

Workflow file for this run

name: CI/CD Pipeline
on:
push:
branches: [main, develop, 'feat/**']
pull_request:
branches: [main, develop]
env:
NODE_VERSION: '18.x'
POSTGRES_VERSION: '14'
jobs:
# Code Quality Checks
lint-and-format:
name: 🧹 Code Quality
runs-on: ubuntu-latest
steps:
- name: πŸ“₯ Checkout code
uses: actions/checkout@v4
- name: πŸ“¦ Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
- name: πŸ“‹ Install dependencies
run: npm ci
- name: πŸ” Run ESLint
run: npm run lint
- name: 🎨 Check code formatting
run: npm run format:check
- name: πŸ“Š Run type checking
run: npm run type-check
# Security Audit
security-audit:
name: πŸ”’ Security Audit
runs-on: ubuntu-latest
steps:
- name: πŸ“₯ Checkout code
uses: actions/checkout@v4
- name: πŸ“¦ Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
- name: πŸ” Run security audit
run: npm audit --audit-level=moderate
- name: πŸ›‘οΈ Run dependency vulnerability scan
run: |
npx audit-ci --moderate
continue-on-error: true
# Unit Tests
unit-tests:
name: πŸ§ͺ Unit Tests
runs-on: ubuntu-latest
strategy:
matrix:
node-version: ['16.x', '18.x', '20.x']
steps:
- name: πŸ“₯ Checkout code
uses: actions/checkout@v4
- name: πŸ“¦ Setup Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- name: πŸ“‹ Install dependencies
run: npm ci
- name: πŸ§ͺ Run unit tests
run: npm run test:unit
env:
NODE_ENV: test
- name: πŸ“Š Generate coverage report
run: npm run test:cov
- name: β˜‚οΈ Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
file: ./coverage/lcov.info
flags: unit-tests
name: unit-tests-${{ matrix.node-version }}
# Integration Tests
integration-tests:
name: πŸ”— Integration Tests
runs-on: ubuntu-latest
services:
postgres:
image: postgres:14
env:
POSTGRES_USER: test_user
POSTGRES_PASSWORD: test_password
POSTGRES_DB: quest_service_test
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
redis:
image: redis:7-alpine
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 6379:6379
steps:
- name: πŸ“₯ Checkout code
uses: actions/checkout@v4
- name: πŸ“¦ Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
- name: πŸ“‹ Install dependencies
run: npm ci
- name: πŸ—„οΈ Run database migrations
run: npm run migration:run
env:
DATABASE_HOST: localhost
DATABASE_PORT: 5432
DATABASE_USER: test_user
DATABASE_PASSWORD: test_password
DATABASE_NAME: quest_service_test
- name: πŸ”— Run integration tests
run: npm run test:integration
env:
NODE_ENV: test
DATABASE_HOST: localhost
DATABASE_PORT: 5432
DATABASE_USER: test_user
DATABASE_PASSWORD: test_password
DATABASE_NAME: quest_service_test
REDIS_HOST: localhost
REDIS_PORT: 6379
JWT_SECRET: test-jwt-secret-key-for-ci
- name: πŸ“Š Upload integration test coverage
uses: codecov/codecov-action@v3
with:
file: ./coverage/lcov.info
flags: integration-tests
name: integration-tests
# End-to-End Tests
e2e-tests:
name: 🎭 E2E Tests
runs-on: ubuntu-latest
services:
postgres:
image: postgres:14
env:
POSTGRES_USER: test_user
POSTGRES_PASSWORD: test_password
POSTGRES_DB: quest_service_e2e
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
redis:
image: redis:7-alpine
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 6379:6379
steps:
- name: πŸ“₯ Checkout code
uses: actions/checkout@v4
- name: πŸ“¦ Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
- name: πŸ“‹ Install dependencies
run: npm ci
- name: πŸ—οΈ Build application
run: npm run build
- name: πŸ—„οΈ Setup test database
run: |
npm run migration:run
npm run seed:run
env:
DATABASE_HOST: localhost
DATABASE_PORT: 5432
DATABASE_USER: test_user
DATABASE_PASSWORD: test_password
DATABASE_NAME: quest_service_e2e
- name: 🎭 Run E2E tests
run: npm run test:e2e
env:
NODE_ENV: test
DATABASE_HOST: localhost
DATABASE_PORT: 5432
DATABASE_USER: test_user
DATABASE_PASSWORD: test_password
DATABASE_NAME: quest_service_e2e
REDIS_HOST: localhost
REDIS_PORT: 6379
JWT_SECRET: test-jwt-secret-key-for-e2e
- name: πŸ“Έ Upload E2E test artifacts
uses: actions/upload-artifact@v3
if: failure()
with:
name: e2e-test-results
path: |
test-results/
screenshots/
videos/
# Performance Tests
performance-tests:
name: ⚑ Performance Tests
runs-on: ubuntu-latest
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/develop')
services:
postgres:
image: postgres:14
env:
POSTGRES_USER: perf_user
POSTGRES_PASSWORD: perf_password
POSTGRES_DB: quest_service_perf
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
steps:
- name: πŸ“₯ Checkout code
uses: actions/checkout@v4
- name: πŸ“¦ Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
- name: πŸ“‹ Install dependencies
run: npm ci
- name: πŸ—οΈ Build application
run: npm run build
- name: πŸ—„οΈ Setup performance database
run: |
npm run migration:run
npm run seed:perf
env:
DATABASE_HOST: localhost
DATABASE_PORT: 5432
DATABASE_USER: perf_user
DATABASE_PASSWORD: perf_password
DATABASE_NAME: quest_service_perf
- name: ⚑ Run performance tests
run: npm run test:performance
env:
DATABASE_HOST: localhost
DATABASE_PORT: 5432
DATABASE_USER: perf_user
DATABASE_PASSWORD: perf_password
DATABASE_NAME: quest_service_perf
- name: πŸ“Š Upload performance results
uses: actions/upload-artifact@v3
with:
name: performance-results
path: performance-results/
# Build and Push Docker Image
build-and-push:
name: 🐳 Build & Push Docker Image
runs-on: ubuntu-latest
needs: [lint-and-format, unit-tests, integration-tests]
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/develop')
steps:
- name: πŸ“₯ Checkout code
uses: actions/checkout@v4
- name: πŸ”‘ Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: 🏷️ Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: quest-service
tags: |
type=ref,event=branch
type=ref,event=pr
type=sha
- name: πŸ—οΈ Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
# Deploy to Staging
deploy-staging:
name: πŸš€ Deploy to Staging
runs-on: ubuntu-latest
needs: [e2e-tests, build-and-push]
if: github.ref == 'refs/heads/develop'
environment: staging
steps:
- name: πŸ“₯ Checkout code
uses: actions/checkout@v4
- name: πŸš€ Deploy to staging
run: |
echo "Deploying to staging environment..."
# Add actual deployment commands here
# e.g., kubectl apply, helm upgrade, etc.
env:
STAGING_KUBECONFIG: ${{ secrets.STAGING_KUBECONFIG }}
- name: πŸ§ͺ Run smoke tests
run: |
echo "Running smoke tests against staging..."
# Add smoke test commands here
npm run test:smoke -- --env=staging
env:
STAGING_API_URL: ${{ secrets.STAGING_API_URL }}
# Deploy to Production
deploy-production:
name: 🌟 Deploy to Production
runs-on: ubuntu-latest
needs: [e2e-tests, build-and-push, performance-tests]
if: github.ref == 'refs/heads/main'
environment: production
steps:
- name: πŸ“₯ Checkout code
uses: actions/checkout@v4
- name: 🌟 Deploy to production
run: |
echo "Deploying to production environment..."
# Add actual deployment commands here
env:
PRODUCTION_KUBECONFIG: ${{ secrets.PRODUCTION_KUBECONFIG }}
- name: πŸ§ͺ Run production smoke tests
run: |
echo "Running smoke tests against production..."
npm run test:smoke -- --env=production
env:
PRODUCTION_API_URL: ${{ secrets.PRODUCTION_API_URL }}
- name: πŸ“’ Notify deployment success
uses: 8398a7/action-slack@v3
with:
status: success
text: 'πŸŽ‰ Quest Service successfully deployed to production!'
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
# Cleanup
cleanup:
name: 🧹 Cleanup
runs-on: ubuntu-latest
needs: [deploy-staging, deploy-production]
if: always()
steps:
- name: 🧹 Clean up old artifacts
run: |
echo "Cleaning up old build artifacts..."
# Add cleanup commands here
- name: πŸ“Š Update deployment metrics
run: |
echo "Updating deployment metrics..."
# Add metrics update commands here