Skip to main content
← Back to Templates

CI/CD Workflow Template

GitHub Actions workflow with security testing

Setup Instructions

1

Create workflows directory

Create .github/workflows if it doesn't exist

2

Create workflow file

Create .github/workflows/ci.yml

3

Customize for your project

Update these sections:

  • • Node.js versions (currently 18.x, 20.x)
  • • Test commands (npm test, npm run lint, etc.)
  • • Branch names (main, develop)
  • • Uncomment Docker section if needed
4

Add required scripts

Ensure your package.json has:

"scripts": {
  "lint": "eslint .",
  "type-check": "tsc --noEmit",
  "test": "jest"
}
5

Commit and test

Commit the file and create a PR to test the workflow

Template Preview

name: CI/CD Pipeline

on:
  push:
    branches: [ main, develop ]
  pull_request:
    branches: [ main, develop ]

jobs:
  # Security and Quality Checks
  security:
    name: Security Scan
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      
      - name: Run Trivy vulnerability scanner
        uses: aquasecurity/trivy-action@master
        with:
          scan-type: 'fs'
          scan-ref: '.'
          format: 'sarif'
          output: 'trivy-results.sarif'
      
      - name: Upload Trivy results to GitHub Security
        uses: github/codeql-action/upload-sarif@v2
        with:
          sarif_file: 'trivy-results.sarif'

  # Build and Test
  build:
    name: Build and Test
    runs-on: ubuntu-latest
    strategy:
      matrix:
        node-version: [18.x, 20.x]
    
    steps:
      - 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 linter
        run: npm run lint
      
      - name: Run type check
        run: npm run type-check
      
      - name: Run tests
        run: npm test -- --coverage
      
      - name: Upload coverage reports
        uses: codecov/codecov-action@v3
        with:
          files: ./coverage/coverage-final.json
          flags: unittests
          name: codecov-umbrella

  # Dependency Review (PRs only)
  dependency-review:
    name: Dependency Review
    runs-on: ubuntu-latest
    if: github.event_name == 'pull_request'
    steps:
      - uses: actions/checkout@v4
      - uses: actions/dependency-review-action@v3
        with:
          fail-on-severity: moderate

  # Build Docker image (optional)
  # docker:
  #   name: Build Docker Image
  #   runs-on: ubuntu-latest
  #   needs: [security, build]
  #   steps:
  #     - uses: actions/checkout@v4
  #     
  #     - name: Build Docker image
  #       run: docker build -t myapp:latest .
  #     
  #     - name: Scan Docker image
  #       uses: aquasecurity/trivy-action@master
  #       with:
  #         image-ref: 'myapp:latest'
  #         format: 'sarif'
  #         output: 'docker-results.sarif'

Compliance Requirements

SOC2 CC8.1

System monitoring and testing

ISO27001 A.14.2.8

System acceptance testing

PCI-DSS 6.4.6

Testing procedures

Quick Info

Time to setup20 minutes
DifficultyMedium
File location.github/workflows/

Note

This workflow requires GitHub Actions to be enabled in your repository settings. Free tier includes 2,000 minutes/month for private repos.

What This Includes

Security vulnerability scanning
Dependency review
Linting and type checking
Unit tests with coverage
Multi-version testing