name: CI
on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main, develop ]
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [20.x, 21.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 }}
- name: Install dependencies
run: npm install
- name: Run linter
run: npm run lint
- name: Type check
run: npm run check
- name: Run tests
run: npm test
- name: Run tests with coverage
run: npm run test:coverage
- name: Build project
run: npm run build
- name: Security audit
run: npm audit --audit-level high
quality-gate:
runs-on: ubuntu-latest
needs: test
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20.x
- name: Install dependencies
run: npm install
- name: Check test coverage
run: |
npm run test:coverage
# Check if coverage is above 80%
COVERAGE=$(npm run test:coverage 2>/dev/null | grep -oP 'All files[^|]*\|\s*\K\d+(?:\.\d+)?(?=\s*%)' | tail -1)
if (( $(echo "$COVERAGE < 80" | bc -l) )); then
echo "Coverage $COVERAGE% is below 80% threshold"
exit 1
fi
echo "Coverage $COVERAGE% meets requirement"
- name: Check for lint errors
run: |
if npm run lint 2>&1 | grep -q "Found.*errors"; then
echo "Lint errors found"
exit 1
fi
- name: Check TypeScript compilation
run: |
if ! npm run check; then
echo "TypeScript compilation failed"
exit 1
fi
release:
runs-on: ubuntu-latest
needs: [test, quality-gate]
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20.x
- name: Install dependencies
run: npm install
- name: Build project
run: npm run build
- name: Run tests
run: npm test
- name: Create release
if: github.ref == 'refs/heads/main'
run: |
# This would typically use semantic-release or similar
# For now, just tag the version
echo "Release process would go here"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}