Skip to content

Commit 24e5968

Browse files
committed
add feature branch in ec2
1 parent 5fe59da commit 24e5968

File tree

1 file changed

+28
-4
lines changed

1 file changed

+28
-4
lines changed

.github/workflows/cd.yml

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,48 @@ on:
55
workflows: ["Continuous Integration"]
66
types:
77
- completed
8+
branches:
9+
- main
10+
11+
push:
12+
branches:
13+
- main
14+
- feature/** # allow testing
15+
- dev
16+
817
workflow_dispatch:
918

1019
jobs:
1120
deploy:
12-
if: ${{ github.event.workflow_run.conclusion == 'success' || github.event_name == 'workflow_dispatch' }}
21+
if: >
22+
github.event_name == 'workflow_dispatch' ||
23+
github.event_name == 'push' ||
24+
(github.event_name == 'workflow_run' &&
25+
github.event.workflow_run.conclusion == 'success')
26+
1327
runs-on: ubuntu-latest
1428

1529
steps:
1630
- name: Checkout code
1731
uses: actions/checkout@v4
1832

19-
- name: Get branch name
33+
- name: Determine branch name
2034
id: vars
21-
run: echo "branch_name=${GITHUB_REF##*/}" >> $GITHUB_OUTPUT
35+
run: |
36+
echo "branch_name=${GITHUB_REF_NAME}" >> $GITHUB_OUTPUT
2237
23-
- name: Print branch
38+
- name: Log branch being deployed
2439
run: |
2540
echo "🚀 Deploying branch: ${{ steps.vars.outputs.branch_name }}"
2641
42+
- name: Test SSH connection to EC2
43+
uses: appleboy/[email protected]
44+
with:
45+
host: ${{ secrets.EC2_HOST }}
46+
username: ubuntu
47+
key: ${{ secrets.EC2_SSH_KEY }}
48+
script: whoami
49+
2750
- name: Deploy to EC2
2851
uses: appleboy/[email protected]
2952
with:
@@ -32,6 +55,7 @@ jobs:
3255
key: ${{ secrets.EC2_SSH_KEY }}
3356
script: |
3457
cd /home/ubuntu/sentiment-mlops
58+
echo "Fetching latest code..."
3559
git fetch origin
3660
git checkout ${{ steps.vars.outputs.branch_name }} || git checkout -b ${{ steps.vars.outputs.branch_name }}
3761
git pull origin ${{ steps.vars.outputs.branch_name }}

0 commit comments

Comments
 (0)