reboottime / frontend-testing

A repository gathered some best practices of doing testing in frontend development. Topics covered in this repository include unit testing, integration testing and e2e testing.
1 stars 0 forks source link

CI/CD pipeline setup #7

Open reboottime opened 3 weeks ago

reboottime commented 3 weeks ago

The Process

CI Process

For any pull request (maybe more strict on push request) on any branches, run following steps

CD Process

reboottime commented 3 weeks ago

Configuration Example

name: CI/CD

on:
  push:
    branches:
      - dev
      - sandbox
      - main
  pull_request:
    branches:
      - '**'

jobs:
  lint:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Install dependencies
        run: npm install
      - name: Run linter
        run: npm run lint

  build:
    runs-on: ubuntu-latest
    needs: lint
    steps:
      - uses: actions/checkout@v4
      - name: Install dependencies
        run: npm install
      - name: Build the code
        run: npm run build

  unit-test:
    runs-on: ubuntu-latest
    needs: build
    steps:
      - uses: actions/checkout@v4
      - name: Install dependencies
        run: npm install
      - name: Run unit tests
        run: npm run test:unit

  integration-test:
    runs-on: ubuntu-latest
    needs: build
    steps:
      - uses: actions/checkout@v4
      - name: Install dependencies
        run: npm install
      - name: Run integration tests
        run: npm run test:integration

  e2e-test:
    runs-on: ubuntu-latest
    needs: build
    steps:
      - uses: actions/checkout@v4
      - name: Install dependencies
        run: npm install
      - name: Run end-to-end tests
        run: npm run test:e2e

  deploy:
    runs-on: ubuntu-latest
    needs: [unit-test, integration-test, e2e-test]
    if: github.event_name == 'push' && (github.ref == 'refs/heads/dev' || github.ref == 'refs/heads/sandbox' || github.ref == 'refs/heads/main')
    steps:
      - uses: actions/checkout@v4
      - name: Deploy to environment
        run: |
          # Add your deployment steps here based on the branch
          if [ "${{ github.ref }}" == "refs/heads/dev" ]; then
            # Deploy to dev environment
            echo "Deploying to dev environment..."
          elif [ "${{ github.ref }}" == "refs/heads/sandbox" ]; then
            # Deploy to sandbox environment
            echo "Deploying to sandbox environment..."
          elif [ "${{ github.ref }}" == "refs/heads/main" ]; then
            # Deploy to production environment
            echo "Deploying to production environment..."
          fi