@@ -3,7 +3,7 @@ name: Deploy to Staging Environment
33on :
44 push :
55 branches : [ main ]
6- workflow_dispatch :
6+ workflow_dispatch : # Allows manual trigger button
77
88jobs :
99 deploy-staging :
@@ -21,44 +21,36 @@ jobs:
2121 - name : Install Dependencies
2222 run : npm install
2323
24- - name : Run Tests
24+ - name : Run Linting (Code Analysis)
25+ # Placeholder for linting logic
26+ run : echo "Linting code analysis..."
27+
28+ - name : Run Unit Tests
29+ # Ensures code is verified before deploying to Staging
2530 run : npm test
2631
2732 - name : Build React App
2833 run : npm run build-react
2934
30- - name : Copy Files to Staging Server
35+ - name : Deploy Files to Staging Server
3136 uses : appleboy/scp-action@master
3237 with :
33- host : ${{ secrets.HOST_STAGING }}
34- username : ${{ secrets.USERNAME }}
38+ host : ${{ secrets.STAGING_EC2_IP }}
39+ username : ubuntu
3540 key : ${{ secrets.EC2_SSH_KEY }}
3641 source : " ./*"
3742 target : " /home/ubuntu/app"
3843
39- - name : Start Application on Staging
44+ - name : Start Application on Staging Server
4045 uses : appleboy/ssh-action@master
4146 with :
42- host : ${{ secrets.HOST_STAGING }}
43- username : ${{ secrets.USERNAME }}
47+ host : ${{ secrets.STAGING_EC2_IP }}
48+ username : ubuntu
4449 key : ${{ secrets.EC2_SSH_KEY }}
4550 script : |
4651 cd /home/ubuntu/app
52+ # Install production dependencies
4753 npm install --production
54+ # Restart the app using PM2 (or start if not running)
4855 pm2 restart all || pm2 start index.js --name "react-node-app"
49- pm2 save
50-
51- - name : Send Success Email
52- if : success()
53- uses : dawidd6/action-send-mail@v3
54- with :
55- server_address : smtp.gmail.com
56- server_port : 465
57- username : ${{ secrets.MAIL_USERNAME }}
58- password : ${{ secrets.MAIL_PASSWORD }}
59- subject : Deployment to STAGING Successful
60- body : |
61- Changes have been merged to main and deployed to Staging.
62- Access it here: http://${{ secrets.HOST_STAGING }}:3000
63- to : ${{ secrets.QA_EMAIL }}
64- from : DevOps Automation
56+ pm2 save
0 commit comments