Skip to content

Commit f6e6a5a

Browse files
committed
added pr prevention of any branch other than staging and tweaked github actions for staging branch
1 parent a169d6a commit f6e6a5a

File tree

3 files changed

+32
-26
lines changed

3 files changed

+32
-26
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: "Main Branch Protection Check"
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
types: [opened, reopened, synchronize, edited]
8+
9+
jobs:
10+
check-source-branch:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Verify Staging to Main
14+
run: |
15+
echo "Checking PR source branch..."
16+
if [[ "${{ github.head_ref }}" != "staging" ]]; then
17+
echo "ERROR: Pull requests to 'main' must originate from 'staging'."
18+
echo "Current source branch is: ${{ github.head_ref }}"
19+
exit 1
20+
fi
21+
echo "Success: PR is from 'staging'."

.github/workflows/cd.yml

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
name: cd
22

33
on:
4-
# Trigger Staging deployment on push to main
4+
# Trigger deployment on push to staging, main
55
push:
6-
branches: [ main ]
7-
8-
# Trigger Prod deployment manually via GitHub UI
9-
workflow_dispatch:
6+
branches: [ staging, main ]
107

118
concurrency:
129
group: ${{ github.workflow }}-${{ github.ref }}
@@ -17,10 +14,11 @@ permissions:
1714

1815
jobs:
1916
# ------------------------------------------------------------------
20-
# STAGING DEPLOYMENT (Runs on push to main)
17+
# STAGING DEPLOYMENT (Runs on push to 'staging')
2118
# ------------------------------------------------------------------
2219
deploy-staging:
2320
name: Deploy Staging
21+
if: github.ref == 'refs/heads/staging'
2422
runs-on: ubuntu-latest
2523
environment: staging # for GitHub Actions
2624
defaults:
@@ -52,14 +50,13 @@ jobs:
5250
# ------------------------------------------------------------------
5351
deploy-prod:
5452
name: Deploy Production
55-
needs: deploy-staging # Rule 1: needs staging to finish
53+
if: github.ref == 'refs/heads/main'
5654
runs-on: ubuntu-latest
57-
environment: production # Rule 2: waits for manual approval (from repository environment settings)
55+
defaults:
56+
run:
57+
working-directory: backend
5858
steps:
59-
# 1. Deploy Backend to Modal
6059
- uses: actions/checkout@v5
61-
with:
62-
fetch-depth: 0 # Fetch all history for branch syncing
6360

6461
- name: Install uv
6562
uses: astral-sh/setup-uv@v6
@@ -70,23 +67,11 @@ jobs:
7067
run: sudo apt-get update && sudo apt-get install -y ffmpeg
7168

7269
- name: Install dependencies
73-
working-directory: backend
7470
run: uv sync --frozen
7571

7672
- name: Deploy to Modal (Prod)
77-
working-directory: backend
7873
env:
7974
MODAL_TOKEN_ID: ${{ secrets.MODAL_TOKEN_ID }}
8075
MODAL_TOKEN_SECRET: ${{ secrets.MODAL_TOKEN_SECRET }}
8176
ENVIRONMENT: prod
82-
run: uv run modal deploy main.py
83-
84-
# 2. Sync Frontend Code to Production Branch
85-
# This triggers Streamlit Cloud to update the Prod App
86-
- name: Sync Main to Production Branch
87-
run: |
88-
git config --global user.name 'GitHub Actions'
89-
git config --global user.email 'actions@github.com'
90-
git checkout production
91-
git merge origin/main --ff-only
92-
git push origin production
77+
run: uv run modal deploy main.py

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ name: ci
22

33
on:
44
push:
5-
branches: [ main ]
5+
branches: [ staging, main ]
66
pull_request:
7-
branches: [ main ]
7+
branches: [ staging, main ]
88

99
concurrency:
1010
group: ${{ github.workflow }}-${{ github.ref }}

0 commit comments

Comments
 (0)