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:
feature branch push
β
Auto PR created (GitHub Action)
β
CI runs (tests, lint)
β
PR merged to main
β
Auto deploy to production
---
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.
feature/login
feature/login β main
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
---
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 }}
Go to:
π Repo β Settings β Secrets β Actions
Add:
``` plaintext id="sec1"
VERCEL_TOKEN=your_vercel_token
RENDER_DEPLOY_HOOK=https://api.render.com/deploy/xxx
---
## Developer flow:
``` plaintext id="flow2"
git checkout -b feature-login
git push origin feature-login
In GitHub:
Settings β Branches β main
Enable:
``` yaml id="notif1"
``` bash id="tag1"
git tag v1.0.0
git push origin v1.0.0
---
### β Auto-deploy without tests
β leads to broken production
### β No branch protection
β anyone can push to main
### β Missing secrets
β deployment fails silently
---
``` 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