Skip to content

Token based

Token based #67

Workflow file for this run

name: StarkPulse Backend CI/CD

Check failure on line 1 in .github/workflows/ci-cd.yml

View workflow run for this annotation

GitHub Actions / .github/workflows/ci-cd.yml

Invalid workflow file

(Line: 361, Col: 13): Unrecognized named-value: 'secrets'. Located at position 1 within expression: secrets.DOCKERHUB_USERNAME && secrets.DOCKERHUB_TOKEN, (Line: 376, Col: 13): Unrecognized named-value: 'secrets'. Located at position 1 within expression: secrets.DOCKERHUB_USERNAME && secrets.DOCKERHUB_TOKEN, (Line: 382, Col: 13): Unrecognized named-value: 'secrets'. Located at position 1 within expression: secrets.DOCKERHUB_USERNAME && secrets.DOCKERHUB_TOKEN, (Line: 400, Col: 13): Unrecognized named-value: 'secrets'. Located at position 1 within expression: secrets.DOCKERHUB_USERNAME && secrets.DOCKERHUB_TOKEN
on:
push:
branches: [main, develop]
pull_request:
branches: [main, develop]
env:
NODE_VERSION: '18.x'
POSTGRES_HOST: localhost
POSTGRES_PORT: 5432
POSTGRES_DB: starkpulse_test
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
REDIS_HOST: localhost
REDIS_PORT: 6379
jobs:
lint-and-format:
name: Lint and Format Check
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 Prettier formatting
run: npm run format:check
- name: TypeScript type check
run: npm run build
unit-tests:
name: Unit Tests
runs-on: ubuntu-latest
needs: lint-and-format
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 unit tests
run: npm run test:unit
- name: Upload unit test coverage
uses: codecov/codecov-action@v3
if: always()
with:
files: ./coverage/unit/lcov.info
flags: unit-tests
name: unit-test-coverage
integration-tests:
name: Integration Tests
runs-on: ubuntu-latest
needs: lint-and-format
services:
postgres:
image: postgres:15
env:
POSTGRES_PASSWORD: postgres
POSTGRES_DB: starkpulse_test
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
redis:
image: redis:7
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: Wait for PostgreSQL
run: |
until pg_isready -h localhost -p 5432; do
echo "Waiting for PostgreSQL..."
sleep 2
done
- name: Run integration tests
run: npm run test:integration
- name: Upload integration test coverage
uses: codecov/codecov-action@v3
if: always()
with:
files: ./coverage/integration/lcov.info
flags: integration-tests
name: integration-test-coverage
e2e-tests:
name: E2E Tests
runs-on: ubuntu-latest
needs: [unit-tests, integration-tests]
services:
postgres:
image: postgres:15
env:
POSTGRES_PASSWORD: postgres
POSTGRES_DB: starkpulse_test
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
redis:
image: redis:7
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: Wait for services
run: |
until pg_isready -h localhost -p 5432; do
echo "Waiting for PostgreSQL..."
sleep 2
done
until redis-cli -h localhost -p 6379 ping; do
echo "Waiting for Redis..."
sleep 2
done
- name: Seed test data
run: npm run test:seed
- name: Start application in background
run: |
npm run start:prod &
sleep 30
- name: Run E2E tests
run: npm run test:e2e
- name: Upload E2E test coverage
uses: codecov/codecov-action@v3
if: always()
with:
files: ./coverage/e2e/lcov.info
flags: e2e-tests
name: e2e-test-coverage
performance-tests:
name: Performance Tests
runs-on: ubuntu-latest
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
needs: [unit-tests, integration-tests]
services:
postgres:
image: postgres:15
env:
POSTGRES_PASSWORD: postgres
POSTGRES_DB: starkpulse_test
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
redis:
image: redis:7
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: Install k6
run: |
sudo gpg -k
sudo gpg --no-default-keyring --keyring /usr/share/keyrings/k6-archive-keyring.gpg --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys C5AD17C747E3415A3642D57D77C6C491D6AC1D69
echo "deb [signed-by=/usr/share/keyrings/k6-archive-keyring.gpg] https://dl.k6.io/deb stable main" | sudo tee /etc/apt/sources.list.d/k6.list
sudo apt-get update
sudo apt-get install k6
- name: Start application
run: |
npm run start:prod &
sleep 30
- name: Run performance tests
run: npm run test:performance
- name: Upload performance test results
uses: actions/upload-artifact@v3
if: always()
with:
name: performance-test-results
path: test/load-testing/performance-test-results.json
coverage-report:
name: Coverage Report
runs-on: ubuntu-latest
needs: [unit-tests, integration-tests, e2e-tests]
services:
postgres:
image: postgres:15
env:
POSTGRES_PASSWORD: postgres
POSTGRES_DB: starkpulse_test
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
redis:
image: redis:7
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 all tests with coverage
run: npm run test:coverage
- name: Check coverage thresholds
run: npm run test:coverage:check
- name: Generate coverage report
run: npm run coverage:report
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
files: ./coverage/lcov.info
flags: all-tests
name: complete-test-coverage
build:
runs-on: ubuntu-latest
needs: test
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 18
- run: npm ci
- run: npm run build
- name: Upload dist artifact
uses: actions/upload-artifact@v4
with:
name: dist
path: dist
- name: Cache Docker layers
uses: actions/cache@v4
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to DockerHub
uses: docker/login-action@v3
if: secrets.DOCKERHUB_USERNAME && secrets.DOCKERHUB_TOKEN
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
push: ${{ secrets.DOCKERHUB_USERNAME && secrets.DOCKERHUB_TOKEN }}
tags: ${{ secrets.DOCKERHUB_USERNAME }}/starkpulse-backend:latest
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache
- name: Save Docker image as artifact (for rollback)
run: |
docker save ${{ secrets.DOCKERHUB_USERNAME }}/starkpulse-backend:latest | gzip > starkpulse-backend-latest.tar.gz
if: secrets.DOCKERHUB_USERNAME && secrets.DOCKERHUB_TOKEN
- name: Upload Docker image artifact
uses: actions/upload-artifact@v4
with:
name: docker-image
path: starkpulse-backend-latest.tar.gz
if: secrets.DOCKERHUB_USERNAME && secrets.DOCKERHUB_TOKEN
deploy:
runs-on: ubuntu-latest
needs: build
if: github.ref == 'refs/heads/main'
steps:
- uses: actions/checkout@v4
- name: Download dist artifact
uses: actions/download-artifact@v4
with:
name: dist
path: dist
- name: Download Docker image artifact
uses: actions/download-artifact@v4
with:
name: docker-image
path: .
if: secrets.DOCKERHUB_USERNAME && secrets.DOCKERHUB_TOKEN
# Add your deployment steps here (e.g., Docker run, SSH, cloud CLI)
# - name: Deploy to server
# run: |
# docker load < starkpulse-backend-latest.tar.gz
# docker run -d -p 3000:3000 --env-file .env ${{ secrets.DOCKERHUB_USERNAME }}/starkpulse-backend:latest
# - name: Sentry Release (optional)
# run: |
# # sentry-cli releases new ...
# # sentry-cli releases finalize ...
# env:
# SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
# SENTRY_ORG: ${{ secrets.SENTRY_ORG }}
# SENTRY_PROJECT: ${{ secrets.SENTRY_PROJECT }}
# Optionally, add a job for monitoring hooks or health checks
# monitor:
# runs-on: ubuntu-latest
# needs: deploy
# steps:
# - name: Health check
# run: |
# curl --fail http://your-deployment-url/health || exit 1
# # If health check fails, manual rollback instructions or trigger
# # - name: Rollback
# # run: ...