How to integrate Git with CI/CD pipelines
Integrating Git with CI/CD pipelines automates testing, building, and deployment workflows triggered by commits, pull requests, and merges, ensuring code quality before production. As the creator of CoreUI, a widely used open-source UI library, I’ve implemented Git-based CI/CD workflows in production systems throughout my 25 years of development experience. The most practical approach is using GitHub Actions with workflow files in the .github/workflows directory triggered by Git events. This method provides automated validation and deployment without external CI services.
Create a workflow file in .github/workflows to automate testing on every push and pull request.
name: CI Pipeline
on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main ]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '18'
- name: Install dependencies
run: npm ci
- name: Run linter
run: npm run lint
- name: Run tests
run: npm test
- name: Build project
run: npm run build
Here the on section defines Git events that trigger the workflow: pushes to main and develop branches, and all pull requests to main. The actions/checkout action clones the repository at the commit that triggered the workflow. The setup-node action installs Node.js version 18. The workflow then runs npm ci to install dependencies, followed by linting, testing, and building. If any step fails, the workflow stops and marks the commit or PR as failing, preventing merges until issues are resolved.
Best Practice Note:
This is the CI/CD integration we use in CoreUI repositories to maintain code quality across all contributions. Cache dependencies with actions/cache to speed up builds, run jobs in parallel when possible, use branch protection rules to require passing CI before merging, and implement separate workflows for deployment to staging and production environments based on branch triggers.



