add feature branch in ec2 #3
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Continuous Deployment | |
| on: | |
| workflow_run: | |
| workflows: ["Continuous Integration"] | |
| types: | |
| - completed | |
| branches: | |
| - main | |
| push: | |
| branches: | |
| - main | |
| - feature/** # allow testing | |
| - dev | |
| workflow_dispatch: | |
| jobs: | |
| deploy: | |
| if: > | |
| github.event_name == 'workflow_dispatch' || | |
| github.event_name == 'push' || | |
| (github.event_name == 'workflow_run' && | |
| github.event.workflow_run.conclusion == 'success') | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Determine branch name | |
| id: vars | |
| run: | | |
| echo "branch_name=${GITHUB_REF_NAME}" >> $GITHUB_OUTPUT | |
| - name: Log branch being deployed | |
| run: | | |
| echo "🚀 Deploying branch: ${{ steps.vars.outputs.branch_name }}" | |
| - name: Test SSH connection to EC2 | |
| uses: appleboy/[email protected] | |
| with: | |
| host: ${{ secrets.EC2_HOST }} | |
| username: ubuntu | |
| key: ${{ secrets.EC2_SSH_KEY }} | |
| script: whoami | |
| - name: Deploy to EC2 | |
| uses: appleboy/[email protected] | |
| with: | |
| host: ${{ secrets.EC2_HOST }} | |
| username: ubuntu | |
| key: ${{ secrets.EC2_SSH_KEY }} | |
| script: | | |
| cd /home/ubuntu/sentiment-mlops | |
| echo "Fetching latest code..." | |
| git fetch origin | |
| git checkout ${{ steps.vars.outputs.branch_name }} || git checkout -b ${{ steps.vars.outputs.branch_name }} | |
| git pull origin ${{ steps.vars.outputs.branch_name }} | |
| chmod +x ./deploy.sh | |
| ./deploy.sh |