11name : cd
22
33on :
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
118concurrency :
129 group : ${{ github.workflow }}-${{ github.ref }}
@@ -17,10 +14,11 @@ permissions:
1714
1815jobs :
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
0 commit comments