Cloud & DevOps
9 min
2025-10-23
GitHub Actions is one of the most powerful automation tools built directly into GitHub. It allows developers to create workflows that automatically build, test, and deploy projects, all triggered by repository events like pushes, pull requests, or releases.
A GitHub Actions workflow is defined in a YAML file inside your repository under the .github/workflows directory. Each workflow consists of:
Create a file named .github/workflows/ci.yml in your repository and add the following:
name: CI Pipeline
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: "20"
- name: Install dependencies
run: npm install
- name: Run tests
run: npm test
This workflow automatically runs tests every time you push to or open a pull request on the main branch.
Once your tests pass, you can extend the same workflow to build or deploy your app. For example, to build and deploy a Next.js app to Vercel:
deploy:
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/checkout@v4
- name: Deploy to Vercel
uses: amondnet/vercel-action@v20
with:
vercel-token: ${{ secrets.VERCEL_TOKEN }}
vercel-org-id: ${{ secrets.VERCEL_ORG_ID }}
vercel-project-id: ${{ secrets.VERCEL_PROJECT_ID }}
This allows for automated deployment right after successful builds, no manual steps required.
Never hardcode sensitive data. Instead, store API keys or tokens in GitHub Secrets:
VERCEL_TOKEN)${{ secrets.YOUR_SECRET }} inside your workflowYou can trigger workflows automatically on schedules or manually through the GitHub UI:
on:
workflow_dispatch:
schedule:
- cron: "0 0 * * *" # Runs daily at midnight
This allows you to automate tasks like database backups, reports, or dependency updates on a recurring schedule.
Speed up workflow execution by caching dependencies:
- name: Cache dependencies
uses: actions/cache@v4
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
This avoids reinstalling all dependencies for every run, significantly reducing build times.
Each workflow run can be viewed in the Actions tab of your repository. You can inspect logs, debug failed runs, and even re run jobs selectively.
Here's an example that builds, tests, and deploys a Node.js app automatically:
name: Node.js CI/CD
on:
push:
branches: [ "main" ]
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: "20"
- run: npm ci
- run: npm test
- run: npm run build
- name: Deploy
run: npm run deploy
env:
DEPLOY_TOKEN: ${{ secrets.DEPLOY_TOKEN }}
GitHub Actions makes continuous integration and delivery easier than ever, directly inside your GitHub repository. Whether you're automating simple linting or deploying complex cloud systems, workflows can handle it all. Start small, then scale your automation as your project grows.
Tags :
GitHub
CI/CD
DevOps
Automation
GitHubActions
Workflow
Pipeline