DEV Community

Kyle Y. Parsotan
Kyle Y. Parsotan

Posted on

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.
Enter fullscreen mode Exit fullscreen mode

🧠 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
Enter fullscreen mode Exit fullscreen mode



---

## 🧠 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 }}
Enter fullscreen mode Exit fullscreen mode

🔐 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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Top comments (0)