File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ name : Deploy to Staging Environment
2+
3+ on :
4+ push :
5+ branches : [ main ]
6+ workflow_dispatch : # Allows manual trigger button
7+
8+ jobs :
9+ deploy-staging :
10+ runs-on : ubuntu-latest
11+
12+ steps :
13+ - name : Checkout code
14+ uses : actions/checkout@v3
15+
16+ - name : Setup Node.js
17+ uses : actions/setup-node@v3
18+ with :
19+ node-version : ' 18'
20+
21+ - name : Install Dependencies
22+ run : npm install
23+
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
30+ run : npm test
31+
32+ - name : Build React App
33+ run : npm run build-react
34+
35+ - name : Deploy Files to Staging Server
36+ uses : appleboy/scp-action@master
37+ with :
38+ host : ${{ secrets.STAGING_EC2_IP }}
39+ username : ubuntu
40+ key : ${{ secrets.EC2_SSH_KEY }}
41+ source : " ./*"
42+ target : " /home/ubuntu/app"
43+
44+ - name : Start Application on Staging Server
45+ uses : appleboy/ssh-action@master
46+ with :
47+ host : ${{ secrets.STAGING_EC2_IP }}
48+ username : ubuntu
49+ key : ${{ secrets.EC2_SSH_KEY }}
50+ script : |
51+ cd /home/ubuntu/app
52+ # Install production dependencies
53+ npm install --production
54+ # Restart the app using PM2 (or start if not running)
55+ pm2 restart all || pm2 start index.js --name "react-node-app"
56+ pm2 save
You can’t perform that action at this time.
0 commit comments