How to use GitHub Actions with Git
GitHub Actions automates software workflows directly in GitHub repositories, running tests, builds, and deployments triggered by Git events like pushes and pull requests. As the creator of CoreUI, a widely used open-source UI library, I’ve implemented GitHub Actions in CI/CD pipelines throughout my 25 years of development experience. The most straightforward approach is creating workflow files in the .github/workflows directory that define automated jobs triggered by Git events. This method integrates seamlessly with Git operations, providing immediate feedback on code quality and deployment status.
Create workflow YAML files in .github/workflows to automate tasks on Git events.
name: CI/CD Pipeline
on:
push:
branches: [main, develop]
pull_request:
branches: [main]
jobs:
build-and-test:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
- 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
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: build-files
path: dist/
Here the on section defines Git events triggering the workflow: pushes to main and develop branches, and pull requests targeting main. The actions/checkout action clones the repository at the specific commit that triggered the workflow. The actions/setup-node installs Node.js with npm caching for faster subsequent runs. The workflow executes npm commands for linting, testing, and building. The actions/upload-artifact saves build outputs for later jobs or deployment stages. Each failed step stops the workflow and marks the commit or PR as failing.
Best Practice Note:
This is the GitHub Actions configuration we use in CoreUI repositories for automated quality checks and continuous integration. Use workflow artifacts to share data between jobs, implement matrix builds to test across multiple Node.js versions and operating systems, and add status badges to README files showing workflow success status for better project transparency.



