CI/CD with GitHub Actions Tutorial – Complete Beginner to Advanced Guide

CI/CD with GitHub Actions Tutorial – Complete Beginner to Advanced Guide

CI (Continuous Integration):
Automatically builds and tests your code whenever you make changes.

CD (Continuous Deployment / Delivery):
Automatically deploys your code to a server or hosting platform after it passes tests.

Create a Workflow File

.github/workflows/ci.yml

 Basic CI Workflow

name: Simple CI

on:
  push:
    branches:
      - main
  pull_request:

jobs:
  build:
    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'

      - name: Install dependencies
        run: npm install

      - name: Build project
        run: npm run build

Run Tests Automatically

      - name: Run Tests
        run: npm test

Add CD (Deployment) – Simple Example

      - name: Deploy to Server
        uses: appleboy/ssh-action@v1
        with:
          host: ${{ secrets.SSH_HOST }}
          username: ${{ secrets.SSH_USER }}
          key: ${{ secrets.SSH_KEY }}
          script: |
            cd /var/www/project
            git pull origin main
            npm install
            npm run build

Using GitHub Secrets

SSH_HOST
SSH_USER
SSH_KEY

${{ secrets.SSH_HOST }}