Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
241 changes: 241 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,241 @@
name: CI Pipeline

# Trigger CI on pull requests and pushes to main/develop
on:
push:
branches:
- main
- develop
pull_request:
branches:
- main
- develop

# Cancel in-progress runs if a new push is made
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
# Job 1: Lint and Code Quality Checks
lint:
name: Lint & 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: '20'
cache: 'npm'

- name: Install dependencies
run: npm ci

- name: Run ESLint
run: npm run lint
continue-on-error: false

- name: Check code formatting (if you add prettier)
run: |
if npm run format:check 2>/dev/null; then
echo "Code formatting check passed"
else
echo "No format:check script found, skipping"
fi
continue-on-error: true

# Job 2: Build Check
build:
name: Build Frontend
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'

- name: Install dependencies
run: npm ci

- name: Build frontend
run: npm run build
env:
NODE_ENV: production

- name: Check build artifacts
run: |
if [ -d "dist" ]; then
echo "✅ Build successful - dist folder created"
ls -la dist/
else
echo "❌ Build failed - no dist folder"
exit 1
fi

# Job 3: Backend Tests
test-backend:
name: Backend Tests
runs-on: ubuntu-latest

# Run MongoDB as a service
services:
mongodb:
image: mongo:7
ports:
- 27017:27017
options: >-
--health-cmd "mongosh --eval 'db.adminCommand({ping: 1})'"
--health-interval 10s
--health-timeout 5s
--health-retries 5

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'

- name: Install dependencies
run: npm ci

- name: Run unit tests
run: npm test -- --testPathPattern="__tests__/unit"
env:
MONGODB_TEST_URI: mongodb://localhost:27017/tlef-test
NODE_ENV: test

- name: Run integration tests
run: npm test -- --testPathPattern="__tests__/integration"
env:
MONGODB_TEST_URI: mongodb://localhost:27017/tlef-test
NODE_ENV: test
JWT_SECRET: test-secret-key-for-ci
JWT_REFRESH_SECRET: test-refresh-secret-for-ci

- name: Generate coverage report
run: npm run test:coverage
env:
MONGODB_TEST_URI: mongodb://localhost:27017/tlef-test
NODE_ENV: test

- name: Upload coverage to Codecov (optional)
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./routes/create/coverage/lcov.info
flags: backend
name: backend-coverage
continue-on-error: true

- name: Comment coverage on PR (optional)
uses: romeovs/lcov-reporter-action@v0.3.1
with:
lcov-file: ./routes/create/coverage/lcov.info
github-token: ${{ secrets.GITHUB_TOKEN }}
continue-on-error: true

# Job 4: Security Audit
security:
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: '20'
cache: 'npm'

- name: Run npm audit
run: npm audit --audit-level=moderate
continue-on-error: true

- name: Check for known vulnerabilities
run: |
npm audit --json > audit-report.json || true
if [ -f audit-report.json ]; then
echo "Audit report generated"
cat audit-report.json
fi

# Job 5: Type Checking (if you add TypeScript)
typecheck:
name: Type 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: '20'
cache: 'npm'

- name: Install dependencies
run: npm ci

- name: Run TypeScript type check
run: |
if npm run typecheck 2>/dev/null; then
echo "✅ Type checking passed"
else
echo "⚠️ No typecheck script found, skipping"
fi
continue-on-error: true

# Job 6: All Checks Summary
all-checks:
name: All CI Checks Passed
runs-on: ubuntu-latest
needs: [lint, build, test-backend, security]
if: always()

steps:
- name: Check if all jobs succeeded
run: |
if [ "${{ needs.lint.result }}" != "success" ]; then
echo "❌ Lint failed"
exit 1
fi
if [ "${{ needs.build.result }}" != "success" ]; then
echo "❌ Build failed"
exit 1
fi
if [ "${{ needs.test-backend.result }}" != "success" ]; then
echo "❌ Backend tests failed"
exit 1
fi
if [ "${{ needs.security.result }}" != "success" ]; then
echo "⚠️ Security audit had warnings (not blocking)"
fi
echo "✅ All required checks passed!"

- name: Post success comment on PR
if: github.event_name == 'pull_request'
uses: actions/github-script@v7
with:
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: '✅ All CI checks passed! Ready for review and merge.'
})
Loading
Loading