Skip to content

Commit e58b5fc

Browse files
committed
add feature branch in ec2
1 parent 5c0e220 commit e58b5fc

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

.github/workflows/cd.yml

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,23 @@
11
name: Continuous Deployment
22

33
on:
4-
# 1️⃣ Automatically trigger after CI passes (only for main)
54
workflow_run:
65
workflows: ["Continuous Integration"]
76
types:
87
- completed
98
branches:
109
- main
1110

12-
# 2️⃣ Fallback: trigger on push (for non-main or if CI doesn’t exist)
1311
push:
1412
branches:
1513
- main
16-
- feature/** # optional — allow testing on feature branches
17-
# - dev # optional — allow dev environment deploys
14+
- feature/** # allow testing
15+
- dev
1816

19-
# 3️⃣ Manual trigger anytime
2017
workflow_dispatch:
2118

2219
jobs:
2320
deploy:
24-
# Only run auto-deploy if CI passed OR triggered manually/push
2521
if: >
2622
github.event_name == 'workflow_dispatch' ||
2723
github.event_name == 'push' ||
@@ -34,6 +30,14 @@ jobs:
3430
- name: Checkout code
3531
uses: actions/checkout@v4
3632

33+
- name: Determine branch name
34+
id: vars
35+
run: |
36+
echo "branch_name=${GITHUB_REF_NAME}" >> $GITHUB_OUTPUT
37+
38+
- name: Log branch being deployed
39+
run: echo "🚀 Deploying branch: ${{ steps.vars.outputs.branch_name }}"
40+
3741
- name: Test SSH connection to EC2
3842
uses: appleboy/[email protected]
3943
with:
@@ -50,6 +54,9 @@ jobs:
5054
key: ${{ secrets.EC2_SSH_KEY }}
5155
script: |
5256
cd /home/ubuntu/sentiment-mlops
53-
git pull origin main
57+
echo "Fetching latest code..."
58+
git fetch origin
59+
git checkout ${{ steps.vars.outputs.branch_name }} || git checkout -b ${{ steps.vars.outputs.branch_name }}
60+
git pull origin ${{ steps.vars.outputs.branch_name }}
5461
chmod +x ./deploy.sh
5562
./deploy.sh

0 commit comments

Comments
 (0)