@@ -2,45 +2,60 @@ name: Node.js CI/CD
22
33on :
44 push :
5- branches : [ master, main ]
5+ branches : [master, main]
66 pull_request :
7- branches : [ master, main ]
7+ branches : [master, main]
88
99jobs :
1010 build :
1111 runs-on : ubuntu-latest
1212
1313 steps :
14- - name : Checkout code
15- uses : actions/checkout@v3
14+ - name : Checkout code
15+ uses : actions/checkout@v3
1616
17- - name : Setup Node.js
18- uses : actions/setup-node@v3
19- with :
20- node-version : ' 18 '
17+ - name : Setup Node.js
18+ uses : actions/setup-node@v3
19+ with :
20+ node-version : " 18 "
2121
22- - name : Install dependencies
23- run : npm install
22+ - name : Install dependencies
23+ run : npm install
2424
25- - name : Run Tests
26- run : npm test
25+ - name : Run Tests
26+ run : npm test
2727
2828 deploy :
2929 needs : build
3030 runs-on : ubuntu-latest
3131 steps :
32- - name : Deploy to Server 🌐
33- 34- with :
35- host : ${{ secrets.SERVER_IP }}
36- username : ${{ secrets.SERVER_USER }}
37- key : ${{ secrets.SSH_PRIVATE_KEY }}
38- port : 22
39- script : |
40- cd ~/CI-CD-Integration-IN-NodeJS
41- git pull origin master
42- npm install
43- pm2 restart test_server
44-
45- - name : Deploy to Server (Simulation)
46- run : echo "Pretend we're deploying the app now!"
32+ - name : Deploy to Server 🌐
33+ 34+ with :
35+ host : ${{ secrets.SERVER_IP }}
36+ username : ${{ secrets.SERVER_USER }}
37+ key : ${{ secrets.SSH_PRIVATE_KEY }}
38+ port : 22
39+ script : |
40+ # Step 1: Install Node.js via nvm (if not installed)
41+ curl -sL https://deb.nodesource.com/setup_18.x | sudo -E bash -
42+ sudo apt-get install -y nodejs
43+
44+ # Step 2: Navigate to project directory and pull the latest changes
45+ cd ~/CI-CD-Integration-IN-NodeJS
46+ git pull origin master
47+
48+ # Step 3: Install dependencies with updated Node.js
49+ npm install
50+
51+ # Step 4: Restart the PM2 process
52+ pm2 restart test_server
53+
54+ # Step 5: Check PM2 logs
55+ pm2 logs
56+
57+ # Step 6: Check PM2 status
58+ pm2 status
59+
60+ # Step 7: Check if the server is running
61+ curl -I http://localhost:3000
0 commit comments