How Linting fits in the CI/CD Testing?

How Linting fits in the CI_CD Testing

Continuous Integration/Continuous Deployment (CI/CD) testing ensures that:

  1. Code pushed to a repository is automatically tested to catch bugs early (CI).
  2. The code can be deployed safely to production (CD), often after passing all tests and checks.

In a CI/CD pipeline, the workflow typically consists of:

  1. Linting: Checking the code’s syntax and style for consistency.
  2. Unit Testing: Running automated tests to verify functionality.
  3. Integration Testing: Testing how components work together.
  4. Deployment: Automatically deploying to a staging or production environment.

How Super-Linter Fits into CI/CD Testing

Super-Linter is a quality gate in the CI pipeline, ensuring that:

  • Code adheres to best practices before it even reaches testing.
  • Syntax issues (e.g., missing semicolons, unused variables) are caught early.
  • This avoids deploying broken or poorly styled code.

Why Linting Alone is Not Enough

Linting only checks the style and syntax; it doesn’t confirm that:

  • Your app works as intended.
  • The logic of your code passes tests. For that, you need to run unit tests, integration tests, or even end-to-end tests.

Linting and CI/CD Testing Together

Combining Super-Linter with test jobs (as in my earlier example) creates a robust CI/CD pipeline:

  1. Linting Job (Super-Linter): Ensures code style and quality.
  2. Testing Job: Runs test scripts to validate functionality.
  3. (Optional) Build/Deploy Job: Packages and deploys the app if all tests pass.

Here’s how a typical Super-Linter YAML script fits into CI/CD:

name: Super-Linter

on: push

jobs:
  super-lint:
    name: Lint code base
    runs-on: ubuntu-latest
    steps:
      -  name: Checkout code
         uses: actions/checkout@v2

      -  name: Run Super-Linter
         uses: github/super-linter@v4
         env:
           DEFAULT_BRANCH: main
           GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  • Linting as a First Step: The script you shared ensures that all code adheres to standards before proceeding to further steps like testing or deployment.
  • If linting fails, the workflow stops, which saves time by catching issues early.

Example: Full CI/CD Pipeline Workflow

Here’s an enhanced pipeline that includes linting, testing, and deployment:

name: CI/CD Pipeline

on: push

jobs:
  lint:
    name: Lint code base
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v2

      - name: Run Super-Linter
        uses: github/super-linter@v4
        env:
          DEFAULT_BRANCH: main
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

  test:
    name: Run tests
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v2

      - name: Setup Node.js
        uses: actions/setup-node@v3
        with:
          node-version: 16

      - name: Install dependencies
        run: npm install

      - name: Run tests
        run: npm test

  deploy:
    name: Deploy to production
    needs: [lint, test] # Only run if linting and tests pass
    runs-on: ubuntu-latest
    steps:
      - name: Deploy application
        run: ./deploy-script.sh # Replace with your deployment command

Summary

The YAML script you shared focuses on linting, which is part of the CI phase of a CI/CD pipeline. For complete CI/CD testing, you need additional jobs for:

  1. Testing: Validating functionality.
  2. Deployment: Pushing the app to a staging/production environment.
Scroll to Top