Auto PR + Auto Deploy workflow using CI/CD Pipline

Here’s a real production-style Auto PR + Auto Deploy workflow using GitHub Actions. This is the kind of setup used in teams to keep main stable and deployments automatic.

We’ll build it in 3 parts:

  1. πŸ€– Auto-create Pull Requests (from feature β†’ main)
  2. πŸ§ͺ Run CI checks on PRs
  3. πŸš€ Auto-deploy when merged to main

🧠 0. What we are building

“`plaintext id=”flow1″
feature branch push
↓
Auto PR created (GitHub Action)
↓
CI runs (tests, lint)
↓
PR merged to main
↓
Auto deploy to production




---

# πŸ€– 1. Auto Create Pull Request Workflow

This automatically creates a PR when you push a feature branch.

## πŸ“ `.github/workflows/auto-pr.yml`



```yaml id="pr1"
name: Auto Create Pull Request

on:
  push:
    branches-ignore:
      - main

jobs:
  create-pr:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - name: Create Pull Request
        uses: repo-sync/pull-request@v2
        with:
          destination_branch: main
          github_token: ${{ secrets.GITHUB_TOKEN }}
          pr_title: "Auto PR: ${{ github.ref_name }}"
          pr_body: |
            ## πŸ€– Auto-generated PR

            Branch: `${{ github.ref_name }}`
            Please review changes before merging.

🧠 What this does:

  • Push to feature/login
  • GitHub Actions triggers
  • Automatically opens PR β†’ feature/login β†’ main

πŸ§ͺ 2. CI Pipeline (runs on PRs)

This ensures only clean code gets merged.

πŸ“ .github/workflows/ci.yml

“`yaml id=”ci1″
name: CI Checks

on:
pull_request:
branches: [ main ]

jobs:
test:
runs-on: ubuntu-latest

steps:
  - uses: actions/checkout@v4

  - name: Setup Node
    uses: actions/setup-node@v4
    with:
      node-version: 20

  - name: Install dependencies
    run: npm install

  - name: Run lint
    run: npm run lint

  - name: Run tests
    run: npm test



---

## 🧠 What this does:

Before merge:

* Runs lint checks
* Runs tests
* Blocks bad code from merging

---

# πŸš€ 3. Auto Deploy on Merge to Main

This deploys your app when PR is merged.

## πŸ“ `.github/workflows/deploy.yml`

### Example: Deploy React + Node (Vercel + Render)



```yaml id="deploy1"
name: Auto Deploy

on:
  push:
    branches: [ main ]

jobs:
  deploy-frontend:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v4

      - name: Install frontend
        working-directory: client
        run: npm install

      - name: Build frontend
        working-directory: client
        run: npm run build

      - name: Deploy to Vercel
        run: npx vercel --prod --token=${{ secrets.VERCEL_TOKEN }}

  deploy-backend:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v4

      - name: Install backend
        working-directory: server
        run: npm install

      - name: Deploy backend (Render webhook)
        run: curl -X POST ${{ secrets.RENDER_DEPLOY_HOOK }}

πŸ” 4. GitHub Secrets Setup

Go to:

πŸ‘‰ Repo β†’ Settings β†’ Secrets β†’ Actions

Add:

“`plaintext id=”sec1″
VERCEL_TOKEN=your_vercel_token
RENDER_DEPLOY_HOOK=https://api.render.com/deploy/xxx




---

# 🧭 5. Full Workflow in action

## Developer flow:



```plaintext id="flow2"
git checkout -b feature-login
git push origin feature-login

Then GitHub automatically:

  1. πŸ€– Creates Pull Request
  2. πŸ§ͺ Runs CI checks
  3. πŸ‘€ Waits for review (optional)
  4. πŸ”€ Merge to main
  5. πŸš€ Auto deploys frontend + backend

πŸ”₯ 6. Upgrade (what real companies add)

🟒 Add approval rule (recommended)

In GitHub:

  • Require 1–2 reviewers
  • Require CI to pass before merge

🟑 Add branch protection

Settings β†’ Branches β†’ main

Enable:

  • Require PR before merging
  • Require status checks
  • Block direct pushes

πŸ”΅ Add notifications (Slack/Discord)

“`yaml id=”notif1″

  • name: Notify Slack
    run: |
    curl -X POST -H ‘Content-type: application/json’
    –data ‘{“text”:”New deployment to production πŸš€”}’
    ${{ secrets.SLACK_WEBHOOK }}
    “`

🟣 Add version tagging

“`bash id=”tag1″
git tag v1.0.0
git push origin v1.0.0




---

# ⚠️ Common mistakes

### ❌ Auto-deploy without tests

β†’ leads to broken production

### ❌ No branch protection

β†’ anyone can push to main

### ❌ Missing secrets

β†’ deployment fails silently

---

# 🧠 Final Architecture (Pro level)



```plaintext id="final1"
Feature Branch
   ↓
Auto PR Created
   ↓
CI (tests + lint)
   ↓
Review + Approval
   ↓
Merge to main
   ↓
CD Pipeline
   ↓
Frontend deploy (Vercel)
Backend deploy (Render/AWS)
   ↓
Slack/Discord notification